1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2004 Antonio Larrosa <larrosa@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KPIXMAPREGIONSELECTORDIALOG_H |
9 | #define KPIXMAPREGIONSELECTORDIALOG_H |
10 | |
11 | #include <QDialog> |
12 | #include <memory> |
13 | |
14 | #include <kwidgetsaddons_export.h> |
15 | |
16 | class KPixmapRegionSelectorWidget; |
17 | |
18 | class QImage; |
19 | |
20 | /** |
21 | * @class KPixmapRegionSelectorDialog kpixmapregionselectordialog.h KPixmapRegionSelectorDialog |
22 | * |
23 | * A dialog that uses a KPixmapRegionSelectorWidget to allow the user |
24 | * to select a region of an image. If you want to use special features |
25 | * like forcing the selected area to have a fixed aspect ratio, you can use |
26 | * pixmapRegionSelectorWidget() to get the pointer to the |
27 | * KPixmapRegionSelectorWidget object and set the desired options there. |
28 | * |
29 | * There are some convenience methods that allow to easily show a dialog |
30 | * for the user to select a region of an image, and just care about the selected |
31 | * image. |
32 | * |
33 | * \image html kpixmapregionselectordialog.png "KPixmapRegionSelectorDialog" |
34 | * |
35 | * @author Antonio Larrosa <larrosa@kde.org> |
36 | */ |
37 | class KWIDGETSADDONS_EXPORT KPixmapRegionSelectorDialog : public QDialog |
38 | { |
39 | Q_OBJECT |
40 | |
41 | public: |
42 | /** |
43 | * The constructor of an empty KPixmapRegionSelectorDialog, you have to call |
44 | * later the setPixmap method of the KPixmapRegionSelectorWidget widget of |
45 | * the new object. |
46 | */ |
47 | explicit KPixmapRegionSelectorDialog(QWidget *parent = nullptr); |
48 | |
49 | /** |
50 | * The destructor of the dialog |
51 | */ |
52 | ~KPixmapRegionSelectorDialog() override; |
53 | |
54 | /** |
55 | * @returns the KPixmapRegionSelectorWidget widget so that additional |
56 | * parameters can be set by using it. |
57 | */ |
58 | KPixmapRegionSelectorWidget *pixmapRegionSelectorWidget() const; |
59 | |
60 | /** |
61 | * Creates a modal dialog, lets the user to select a region of the @p pixmap |
62 | * and returns when the dialog is closed. |
63 | * |
64 | * @returns the selected rectangle, or an invalid rectangle if the user |
65 | * pressed the Cancel button. |
66 | */ |
67 | static QRect getSelectedRegion(const QPixmap &pixmap, QWidget *parent = nullptr); |
68 | |
69 | /** |
70 | * Creates a modal dialog, lets the user to select a region of the @p pixmap |
71 | * with the same aspect ratio than @p aspectRatioWidth x @p aspectRatioHeight |
72 | * and returns when the dialog is closed. |
73 | * |
74 | * @returns the selected rectangle, or an invalid rectangle if the user |
75 | * pressed the Cancel button. |
76 | */ |
77 | static QRect getSelectedRegion(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent = nullptr); |
78 | |
79 | /** |
80 | * Creates a modal dialog, lets the user to select a region of the @p pixmap |
81 | * and returns when the dialog is closed. |
82 | * |
83 | * @returns the selected image, or an invalid image if the user |
84 | * pressed the Cancel button. |
85 | */ |
86 | static QImage getSelectedImage(const QPixmap &pixmap, QWidget *parent = nullptr); |
87 | |
88 | /** |
89 | * Creates a modal dialog, lets the user to select a region of the @p pixmap |
90 | * with the same aspect ratio than @p aspectRatioWidth x @p aspectRatioHeight |
91 | * and returns when the dialog is closed. |
92 | * |
93 | * @returns the selected image, or an invalid image if the user |
94 | * pressed the Cancel button. |
95 | */ |
96 | static QImage getSelectedImage(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent = nullptr); |
97 | |
98 | /** |
99 | * @since 4.4.3 |
100 | * Adjusts the size of the KPixmapRegionSelectorWidget to not overflow the screen size |
101 | */ |
102 | void adjustRegionSelectorWidgetSizeToFitScreen(); |
103 | |
104 | private: |
105 | std::unique_ptr<class KPixmapRegionSelectorDialogPrivate> const d; |
106 | |
107 | Q_DISABLE_COPY(KPixmapRegionSelectorDialog) |
108 | }; |
109 | |
110 | #endif |
111 | |