1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.widgets.messagebox;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.coreevent;
19 import qt.core.flags;
20 import qt.core.list;
21 import qt.core.namespace;
22 import qt.core.object;
23 import qt.core.string;
24 import qt.gui.event;
25 import qt.gui.pixmap;
26 import qt.helpers;
27 import qt.widgets.abstractbutton;
28 import qt.widgets.checkbox;
29 import qt.widgets.dialog;
30 import qt.widgets.pushbutton;
31 import qt.widgets.widget;
32 
33 /+ QT_REQUIRE_CONFIG(messagebox);
34 
35 
36 class QLabel; +/
37 extern(C++, class) struct QMessageBoxPrivate;
38 /+ class QAbstractButton;
39 class QCheckBox; +/
40 
41 class /+ Q_WIDGETS_EXPORT +/ QMessageBox : QDialog
42 {
43     mixin(Q_OBJECT);
44     /+ Q_PROPERTY(QString text READ text WRITE setText)
45     Q_PROPERTY(Icon icon READ icon WRITE setIcon)
46     Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
47     Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
48     Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons)
49 #if QT_CONFIG(textedit)
50     Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText)
51 #endif
52     Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText)
53     Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags) +/
54 
55 public:
56     enum Icon {
57         // keep this in sync with QMessageDialogOptions::Icon
58         NoIcon = 0,
59         Information = 1,
60         Warning = 2,
61         Critical = 3,
62         Question = 4
63     }
64     /+ Q_ENUM(Icon) +/
65 
66     enum ButtonRole {
67         // keep this in sync with QDialogButtonBox::ButtonRole and QPlatformDialogHelper::ButtonRole
68         InvalidRole = -1,
69         AcceptRole,
70         RejectRole,
71         DestructiveRole,
72         ActionRole,
73         HelpRole,
74         YesRole,
75         NoRole,
76         ResetRole,
77         ApplyRole,
78 
79         NRoles
80     }
81 
82     enum StandardButton {
83         // keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton
84         NoButton           = 0x00000000,
85         Ok                 = 0x00000400,
86         Save               = 0x00000800,
87         SaveAll            = 0x00001000,
88         Open               = 0x00002000,
89         Yes                = 0x00004000,
90         YesToAll           = 0x00008000,
91         No                 = 0x00010000,
92         NoToAll            = 0x00020000,
93         Abort              = 0x00040000,
94         Retry              = 0x00080000,
95         Ignore             = 0x00100000,
96         Close              = 0x00200000,
97         Cancel             = 0x00400000,
98         Discard            = 0x00800000,
99         Help               = 0x01000000,
100         Apply              = 0x02000000,
101         Reset              = 0x04000000,
102         RestoreDefaults    = 0x08000000,
103 
104         FirstButton        = StandardButton.Ok,                // internal
105         LastButton         = StandardButton.RestoreDefaults,   // internal
106 
107         YesAll             = StandardButton.YesToAll,          // obsolete
108         NoAll              = StandardButton.NoToAll,           // obsolete
109 
110         Default            = 0x00000100,        // obsolete
111         Escape             = 0x00000200,        // obsolete
112         FlagMask           = 0x00000300,        // obsolete
113         ButtonMask         = ~StandardButton.FlagMask          // obsolete
114     }
115     alias Button = StandardButton;  // obsolete
116 
117     /+ Q_DECLARE_FLAGS(StandardButtons, StandardButton) +/
118 alias StandardButtons = QFlags!(StandardButton);    /+ Q_FLAG(StandardButtons) +/
119 
120     /+ explicit +/this(QWidget parent = null);
121     this(Icon icon, ref const(QString) title, ref const(QString) text,
122                     StandardButtons buttons = StandardButton.NoButton, QWidget parent = null,
123                     /+ Qt:: +/qt.core.namespace.WindowFlags flags = /+ Qt:: +/qt.core.namespace.WindowType.Dialog | /+ Qt:: +/qt.core.namespace.WindowType.MSWindowsFixedSizeDialogHint);
124     ~this();
125 
126     final void addButton(QAbstractButton button, ButtonRole role);
127     final QPushButton addButton(ref const(QString) text, ButtonRole role);
128     final QPushButton addButton(StandardButton button);
129     final void removeButton(QAbstractButton button);
130 
131     /+ using QDialog::open; +/
132     final void open(QObject receiver, const(char)* member);
133 
134     final QList!(QAbstractButton) buttons() const;
135     final ButtonRole buttonRole(QAbstractButton button) const;
136 
137     final void setStandardButtons(StandardButtons buttons);
138     final StandardButtons standardButtons() const;
139     final StandardButton standardButton(QAbstractButton button) const;
140     final QAbstractButton button(StandardButton which) const;
141 
142     final QPushButton defaultButton() const;
143     final void setDefaultButton(QPushButton button);
144     final void setDefaultButton(StandardButton button);
145 
146     final QAbstractButton escapeButton() const;
147     final void setEscapeButton(QAbstractButton button);
148     final void setEscapeButton(StandardButton button);
149 
150     final QAbstractButton clickedButton() const;
151 
152     final QString text() const;
153     final void setText(ref const(QString) text);
154     final void setText(const QString s){setText(s);}
155 
156     final Icon icon() const;
157     final void setIcon(Icon);
158 
159     final QPixmap iconPixmap() const;
160     final void setIconPixmap(ref const(QPixmap) pixmap);
161 
162     final /+ Qt:: +/qt.core.namespace.TextFormat textFormat() const;
163     final void setTextFormat(/+ Qt:: +/qt.core.namespace.TextFormat format);
164 
165     final void setTextInteractionFlags(/+ Qt:: +/qt.core.namespace.TextInteractionFlags flags);
166     final /+ Qt:: +/qt.core.namespace.TextInteractionFlags textInteractionFlags() const;
167 
168     final void setCheckBox(QCheckBox cb);
169     final QCheckBox checkBox() const;
170 
171     static StandardButton information(QWidget parent, ref const(QString) title,
172              ref const(QString) text, StandardButtons buttons = StandardButton.Ok,
173              StandardButton defaultButton = StandardButton.NoButton);
174     static StandardButton question(QWidget parent, ref const(QString) title,
175              ref const(QString) text, StandardButtons buttons = StandardButtons(StandardButton.Yes | StandardButton.No),
176              StandardButton defaultButton = StandardButton.NoButton);
177     static StandardButton warning(QWidget parent, ref const(QString) title,
178              ref const(QString) text, StandardButtons buttons = StandardButton.Ok,
179              StandardButton defaultButton = StandardButton.NoButton);
180     static StandardButton critical(QWidget parent, ref const(QString) title,
181              ref const(QString) text, StandardButtons buttons = StandardButton.Ok,
182              StandardButton defaultButton = StandardButton.NoButton);
183     static void about(QWidget parent, ref const(QString) title, ref const(QString) text);
184     static void aboutQt(QWidget parent, ref const(QString) title = globalInitVar!QString);
185 
186     // the following functions are obsolete:
187 
188     this(ref const(QString) title, ref const(QString) text, Icon icon,
189                       int button0, int button1, int button2,
190                       QWidget parent = null,
191                       /+ Qt:: +/qt.core.namespace.WindowFlags f = /+ Qt:: +/qt.core.namespace.WindowType.Dialog | /+ Qt:: +/qt.core.namespace.WindowType.MSWindowsFixedSizeDialogHint);
192 
193     static int information(QWidget parent, ref const(QString) title,
194                                ref const(QString) text,
195                                int button0, int button1 = 0, int button2 = 0);
196     static int information(QWidget parent, ref const(QString) title,
197                                ref const(QString) text,
198                                ref const(QString) button0Text,
199                                ref const(QString) button1Text = globalInitVar!QString,
200                                ref const(QString) button2Text = globalInitVar!QString,
201                                int defaultButtonNumber = 0,
202                                int escapeButtonNumber = -1);
203     pragma(inline, true) static StandardButton information(QWidget parent, ref const(QString) title,
204                                       ref const(QString) text,
205                                       StandardButton button0, StandardButton button1 = StandardButton.NoButton)
206     { return information(parent, title, text, StandardButtons(button0), button1); }
207 
208     static int question(QWidget parent, ref const(QString) title,
209                             ref const(QString) text,
210                             int button0, int button1 = 0, int button2 = 0);
211     static int question(QWidget parent, ref const(QString) title,
212                             ref const(QString) text,
213                             ref const(QString) button0Text,
214                             ref const(QString) button1Text = globalInitVar!QString,
215                             ref const(QString) button2Text = globalInitVar!QString,
216                             int defaultButtonNumber = 0,
217                             int escapeButtonNumber = -1);
218     pragma(inline, true) static int question(QWidget parent, ref const(QString) title,
219                                    ref const(QString) text,
220                                    StandardButton button0, StandardButton button1)
221     { return question(parent, title, text, StandardButtons(button0), button1); }
222 
223     static int warning(QWidget parent, ref const(QString) title,
224                            ref const(QString) text,
225                            int button0, int button1, int button2 = 0);
226     static int warning(QWidget parent, ref const(QString) title,
227                            ref const(QString) text,
228                            ref const(QString) button0Text,
229                            ref const(QString) button1Text = globalInitVar!QString,
230                            ref const(QString) button2Text = globalInitVar!QString,
231                            int defaultButtonNumber = 0,
232                            int escapeButtonNumber = -1);
233     pragma(inline, true) static int warning(QWidget parent, ref const(QString) title,
234                                   ref const(QString) text,
235                                   StandardButton button0, StandardButton button1)
236     { return warning(parent, title, text, StandardButtons(button0), button1); }
237 
238     static int critical(QWidget parent, ref const(QString) title,
239                             ref const(QString) text,
240                             int button0, int button1, int button2 = 0);
241     static int critical(QWidget parent, ref const(QString) title,
242                             ref const(QString) text,
243                             ref const(QString) button0Text,
244                             ref const(QString) button1Text = globalInitVar!QString,
245                             ref const(QString) button2Text = globalInitVar!QString,
246                             int defaultButtonNumber = 0,
247                             int escapeButtonNumber = -1);
248     pragma(inline, true) static int critical(QWidget parent, ref const(QString) title,
249                                    ref const(QString) text,
250                                    StandardButton button0, StandardButton button1)
251     { return critical(parent, title, text, StandardButtons(button0), button1); }
252 
253     final QString buttonText(int button) const;
254     final void setButtonText(int button, ref const(QString) text);
255 
256     final QString informativeText() const;
257     final void setInformativeText(ref const(QString) text);
258 
259 /+ #if QT_CONFIG(textedit) +/
260     final QString detailedText() const;
261     final void setDetailedText(ref const(QString) text);
262 /+ #endif +/
263 
264 //    final void setWindowTitle(ref const(QString) title);
265 //    final void setWindowModality(/+ Qt:: +/qt.core.namespace.WindowModality windowModality);
266 
267 
268     static QPixmap standardIcon(Icon icon);
269 
270 /+ Q_SIGNALS +/public:
271     @QSignal final void buttonClicked(QAbstractButton button);
272 
273 /+ #ifdef Q_CLANG_QDOC
274 public Q_SLOTS:
275     int exec() override;
276 #endif +/
277 
278 protected:
279     override bool event(QEvent e);
280     override void resizeEvent(QResizeEvent event);
281     override void showEvent(QShowEvent event);
282     override void closeEvent(QCloseEvent event);
283     override void keyPressEvent(QKeyEvent event);
284     override void changeEvent(QEvent event);
285 
286 private:
287     /+ Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked(QAbstractButton *))
288     Q_PRIVATE_SLOT(d_func(), void _q_clicked(QPlatformDialogHelper::StandardButton, QPlatformDialogHelper::ButtonRole))
289 
290     Q_DISABLE_COPY(QMessageBox) +/
291     /+ Q_DECLARE_PRIVATE(QMessageBox) +/
292 }
293 /+pragma(inline, true) QFlags!(QMessageBox.StandardButtons.enum_type) operator |(QMessageBox.StandardButtons.enum_type f1, QMessageBox.StandardButtons.enum_type f2)/+noexcept+/{return QFlags!(QMessageBox.StandardButtons.enum_type)(f1)|f2;}+/
294 /+pragma(inline, true) QFlags!(QMessageBox.StandardButtons.enum_type) operator |(QMessageBox.StandardButtons.enum_type f1, QFlags!(QMessageBox.StandardButtons.enum_type) f2)/+noexcept+/{return f2|f1;}+/
295 /+pragma(inline, true) QIncompatibleFlag operator |(QMessageBox.StandardButtons.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
296 
297 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons)
298 #define QT_REQUIRE_VERSION(argc, argv, str) { QString s = QString::fromLatin1(str);\
299 QString sq = QString::fromLatin1(qVersion()); \
300 if ((sq.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
301 (sq.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
302 sq.section(QChar::fromLatin1('.'),2,2).toInt()<(s.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
303 (s.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
304 s.section(QChar::fromLatin1('.'),2,2).toInt()) { \
305 if (!qApp){ \
306     new QApplication(argc,argv); \
307 } \
308 QString s = QApplication::tr("Executable '%1' requires Qt "\
309  "%2, found Qt %3.").arg(qAppName()).arg(QString::fromLatin1(\
310 str)).arg(QString::fromLatin1(qVersion())); QMessageBox::critical(0, QApplication::tr(\
311 "Incompatible Qt Library Error"), s, QMessageBox::Abort, 0); qFatal("%s", s.toLatin1().data()); }} +/
312 
313