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