[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #ifndef QMESSAGEBOX_H
|
---|
| 43 | #define QMESSAGEBOX_H
|
---|
| 44 |
|
---|
| 45 | #include <QtGui/qdialog.h>
|
---|
| 46 |
|
---|
| 47 | QT_BEGIN_HEADER
|
---|
| 48 |
|
---|
| 49 | QT_BEGIN_NAMESPACE
|
---|
| 50 |
|
---|
| 51 | QT_MODULE(Gui)
|
---|
| 52 |
|
---|
| 53 | #ifndef QT_NO_MESSAGEBOX
|
---|
| 54 |
|
---|
| 55 | class QLabel;
|
---|
| 56 | class QMessageBoxPrivate;
|
---|
| 57 | class QAbstractButton;
|
---|
| 58 |
|
---|
| 59 | class Q_GUI_EXPORT QMessageBox : public QDialog
|
---|
| 60 | {
|
---|
| 61 | Q_OBJECT
|
---|
| 62 | Q_ENUMS(Icon)
|
---|
| 63 | Q_FLAGS(StandardButtons)
|
---|
| 64 | Q_PROPERTY(QString text READ text WRITE setText)
|
---|
| 65 | // ### Qt 5: Rename 'icon' 'standardIcon' and 'iconPixmap' 'icon' (and use QIcon?)
|
---|
| 66 | Q_PROPERTY(Icon icon READ icon WRITE setIcon)
|
---|
| 67 | Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
|
---|
| 68 | Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
|
---|
| 69 | Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons)
|
---|
| 70 | #ifndef QT_NO_TEXTEDIT
|
---|
| 71 | Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText)
|
---|
| 72 | #endif
|
---|
| 73 | Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText)
|
---|
| 74 |
|
---|
| 75 | public:
|
---|
| 76 | enum Icon {
|
---|
| 77 | NoIcon = 0,
|
---|
| 78 | Information = 1,
|
---|
| 79 | Warning = 2,
|
---|
| 80 | Critical = 3,
|
---|
| 81 | Question = 4
|
---|
| 82 | };
|
---|
| 83 |
|
---|
| 84 | enum ButtonRole {
|
---|
| 85 | // keep this in sync with QDialogButtonBox::ButtonRole
|
---|
| 86 | InvalidRole = -1,
|
---|
| 87 | AcceptRole,
|
---|
| 88 | RejectRole,
|
---|
| 89 | DestructiveRole,
|
---|
| 90 | ActionRole,
|
---|
| 91 | HelpRole,
|
---|
| 92 | YesRole,
|
---|
| 93 | NoRole,
|
---|
| 94 | ResetRole,
|
---|
| 95 | ApplyRole,
|
---|
| 96 |
|
---|
| 97 | NRoles
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 | enum StandardButton {
|
---|
| 101 | // keep this in sync with QDialogButtonBox::StandardButton
|
---|
| 102 | NoButton = 0x00000000,
|
---|
| 103 | Ok = 0x00000400,
|
---|
| 104 | Save = 0x00000800,
|
---|
| 105 | SaveAll = 0x00001000,
|
---|
| 106 | Open = 0x00002000,
|
---|
| 107 | Yes = 0x00004000,
|
---|
| 108 | YesToAll = 0x00008000,
|
---|
| 109 | No = 0x00010000,
|
---|
| 110 | NoToAll = 0x00020000,
|
---|
| 111 | Abort = 0x00040000,
|
---|
| 112 | Retry = 0x00080000,
|
---|
| 113 | Ignore = 0x00100000,
|
---|
| 114 | Close = 0x00200000,
|
---|
| 115 | Cancel = 0x00400000,
|
---|
| 116 | Discard = 0x00800000,
|
---|
| 117 | Help = 0x01000000,
|
---|
| 118 | Apply = 0x02000000,
|
---|
| 119 | Reset = 0x04000000,
|
---|
| 120 | RestoreDefaults = 0x08000000,
|
---|
| 121 |
|
---|
| 122 | FirstButton = Ok, // internal
|
---|
| 123 | LastButton = RestoreDefaults, // internal
|
---|
| 124 |
|
---|
| 125 | YesAll = YesToAll, // obsolete
|
---|
| 126 | NoAll = NoToAll, // obsolete
|
---|
| 127 |
|
---|
| 128 | Default = 0x00000100, // obsolete
|
---|
| 129 | Escape = 0x00000200, // obsolete
|
---|
| 130 | FlagMask = 0x00000300, // obsolete
|
---|
| 131 | ButtonMask = ~FlagMask // obsolete
|
---|
| 132 | };
|
---|
| 133 | typedef StandardButton Button; // obsolete
|
---|
| 134 |
|
---|
| 135 | Q_DECLARE_FLAGS(StandardButtons, StandardButton)
|
---|
| 136 |
|
---|
| 137 | explicit QMessageBox(QWidget *parent = 0);
|
---|
| 138 | QMessageBox(Icon icon, const QString &title, const QString &text,
|
---|
| 139 | StandardButtons buttons = NoButton, QWidget *parent = 0,
|
---|
| 140 | Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
---|
| 141 | ~QMessageBox();
|
---|
| 142 |
|
---|
| 143 | void addButton(QAbstractButton *button, ButtonRole role);
|
---|
| 144 | QPushButton *addButton(const QString &text, ButtonRole role);
|
---|
| 145 | QPushButton *addButton(StandardButton button);
|
---|
| 146 | void removeButton(QAbstractButton *button);
|
---|
| 147 |
|
---|
[561] | 148 | #ifdef Q_WS_WINCE
|
---|
[2] | 149 | void setVisible(bool visible);
|
---|
| 150 | #endif
|
---|
| 151 |
|
---|
| 152 | #ifdef Q_NO_USING_KEYWORD
|
---|
| 153 | #ifndef Q_QDOC
|
---|
| 154 | void open() { QDialog::open(); }
|
---|
| 155 | #endif
|
---|
| 156 | #else
|
---|
| 157 | using QDialog::open;
|
---|
| 158 | #endif
|
---|
| 159 | void open(QObject *receiver, const char *member);
|
---|
| 160 |
|
---|
| 161 | QList<QAbstractButton *> buttons() const;
|
---|
| 162 | ButtonRole buttonRole(QAbstractButton *button) const;
|
---|
| 163 |
|
---|
| 164 | void setStandardButtons(StandardButtons buttons);
|
---|
| 165 | StandardButtons standardButtons() const;
|
---|
| 166 | StandardButton standardButton(QAbstractButton *button) const;
|
---|
| 167 | QAbstractButton *button(StandardButton which) const;
|
---|
| 168 |
|
---|
| 169 | QPushButton *defaultButton() const;
|
---|
| 170 | void setDefaultButton(QPushButton *button);
|
---|
| 171 | void setDefaultButton(StandardButton button);
|
---|
| 172 |
|
---|
| 173 | QAbstractButton *escapeButton() const;
|
---|
| 174 | void setEscapeButton(QAbstractButton *button);
|
---|
| 175 | void setEscapeButton(StandardButton button);
|
---|
| 176 |
|
---|
| 177 | QAbstractButton *clickedButton() const;
|
---|
| 178 |
|
---|
| 179 | QString text() const;
|
---|
| 180 | void setText(const QString &text);
|
---|
| 181 |
|
---|
| 182 | Icon icon() const;
|
---|
| 183 | void setIcon(Icon);
|
---|
| 184 |
|
---|
| 185 | QPixmap iconPixmap() const;
|
---|
| 186 | void setIconPixmap(const QPixmap &pixmap);
|
---|
| 187 |
|
---|
| 188 | Qt::TextFormat textFormat() const;
|
---|
| 189 | void setTextFormat(Qt::TextFormat format);
|
---|
| 190 |
|
---|
| 191 | static StandardButton information(QWidget *parent, const QString &title,
|
---|
| 192 | const QString &text, StandardButtons buttons = Ok,
|
---|
| 193 | StandardButton defaultButton = NoButton);
|
---|
[561] | 194 | // ### Qt 5: Replace Ok with Yes|No in question() function.
|
---|
| 195 | // Also consider if Ok == Yes and Cancel == No.
|
---|
[2] | 196 | static StandardButton question(QWidget *parent, const QString &title,
|
---|
| 197 | const QString &text, StandardButtons buttons = Ok,
|
---|
| 198 | StandardButton defaultButton = NoButton);
|
---|
| 199 | static StandardButton warning(QWidget *parent, const QString &title,
|
---|
| 200 | const QString &text, StandardButtons buttons = Ok,
|
---|
| 201 | StandardButton defaultButton = NoButton);
|
---|
| 202 | static StandardButton critical(QWidget *parent, const QString &title,
|
---|
| 203 | const QString &text, StandardButtons buttons = Ok,
|
---|
| 204 | StandardButton defaultButton = NoButton);
|
---|
| 205 | static void about(QWidget *parent, const QString &title, const QString &text);
|
---|
| 206 | static void aboutQt(QWidget *parent, const QString &title = QString());
|
---|
| 207 |
|
---|
| 208 | QSize sizeHint() const;
|
---|
| 209 |
|
---|
| 210 | // the following functions are obsolete:
|
---|
| 211 |
|
---|
| 212 | QMessageBox(const QString &title, const QString &text, Icon icon,
|
---|
| 213 | int button0, int button1, int button2,
|
---|
| 214 | QWidget *parent = 0,
|
---|
| 215 | Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
---|
| 216 |
|
---|
| 217 | static int information(QWidget *parent, const QString &title,
|
---|
| 218 | const QString& text,
|
---|
| 219 | int button0, int button1 = 0, int button2 = 0);
|
---|
| 220 | static int information(QWidget *parent, const QString &title,
|
---|
| 221 | const QString& text,
|
---|
| 222 | const QString& button0Text,
|
---|
| 223 | const QString& button1Text = QString(),
|
---|
| 224 | const QString& button2Text = QString(),
|
---|
| 225 | int defaultButtonNumber = 0,
|
---|
| 226 | int escapeButtonNumber = -1);
|
---|
| 227 | inline static StandardButton information(QWidget *parent, const QString &title,
|
---|
| 228 | const QString& text,
|
---|
| 229 | StandardButton button0, StandardButton button1 = NoButton)
|
---|
| 230 | { return information(parent, title, text, StandardButtons(button0), button1); }
|
---|
| 231 |
|
---|
| 232 | static int question(QWidget *parent, const QString &title,
|
---|
| 233 | const QString& text,
|
---|
| 234 | int button0, int button1 = 0, int button2 = 0);
|
---|
| 235 | static int question(QWidget *parent, const QString &title,
|
---|
| 236 | const QString& text,
|
---|
| 237 | const QString& button0Text,
|
---|
| 238 | const QString& button1Text = QString(),
|
---|
| 239 | const QString& button2Text = QString(),
|
---|
| 240 | int defaultButtonNumber = 0,
|
---|
| 241 | int escapeButtonNumber = -1);
|
---|
| 242 | inline static int question(QWidget *parent, const QString &title,
|
---|
| 243 | const QString& text,
|
---|
| 244 | StandardButton button0, StandardButton button1)
|
---|
| 245 | { return question(parent, title, text, StandardButtons(button0), button1); }
|
---|
| 246 |
|
---|
| 247 | static int warning(QWidget *parent, const QString &title,
|
---|
| 248 | const QString& text,
|
---|
| 249 | int button0, int button1, int button2 = 0);
|
---|
| 250 | static int warning(QWidget *parent, const QString &title,
|
---|
| 251 | const QString& text,
|
---|
| 252 | const QString& button0Text,
|
---|
| 253 | const QString& button1Text = QString(),
|
---|
| 254 | const QString& button2Text = QString(),
|
---|
| 255 | int defaultButtonNumber = 0,
|
---|
| 256 | int escapeButtonNumber = -1);
|
---|
| 257 | inline static int warning(QWidget *parent, const QString &title,
|
---|
| 258 | const QString& text,
|
---|
| 259 | StandardButton button0, StandardButton button1)
|
---|
| 260 | { return warning(parent, title, text, StandardButtons(button0), button1); }
|
---|
| 261 |
|
---|
| 262 | static int critical(QWidget *parent, const QString &title,
|
---|
| 263 | const QString& text,
|
---|
| 264 | int button0, int button1, int button2 = 0);
|
---|
| 265 | static int critical(QWidget *parent, const QString &title,
|
---|
| 266 | const QString& text,
|
---|
| 267 | const QString& button0Text,
|
---|
| 268 | const QString& button1Text = QString(),
|
---|
| 269 | const QString& button2Text = QString(),
|
---|
| 270 | int defaultButtonNumber = 0,
|
---|
| 271 | int escapeButtonNumber = -1);
|
---|
| 272 | inline static int critical(QWidget *parent, const QString &title,
|
---|
| 273 | const QString& text,
|
---|
| 274 | StandardButton button0, StandardButton button1)
|
---|
| 275 | { return critical(parent, title, text, StandardButtons(button0), button1); }
|
---|
| 276 |
|
---|
| 277 | QString buttonText(int button) const;
|
---|
| 278 | void setButtonText(int button, const QString &text);
|
---|
| 279 |
|
---|
| 280 | QString informativeText() const;
|
---|
| 281 | void setInformativeText(const QString &text);
|
---|
| 282 |
|
---|
| 283 | #ifndef QT_NO_TEXTEDIT
|
---|
| 284 | QString detailedText() const;
|
---|
| 285 | void setDetailedText(const QString &text);
|
---|
| 286 | #endif
|
---|
| 287 |
|
---|
| 288 | void setWindowTitle(const QString &title);
|
---|
| 289 | void setWindowModality(Qt::WindowModality windowModality);
|
---|
| 290 |
|
---|
| 291 | #ifdef QT3_SUPPORT
|
---|
| 292 | QT3_SUPPORT_CONSTRUCTOR QMessageBox(const QString &title, const QString &text, Icon icon,
|
---|
| 293 | int button0, int button1, int button2,
|
---|
| 294 | QWidget *parent, const char *name, bool modal,
|
---|
| 295 | Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
---|
| 296 | QT3_SUPPORT_CONSTRUCTOR QMessageBox(QWidget *parent, const char *name);
|
---|
| 297 |
|
---|
| 298 | static QT3_SUPPORT QPixmap standardIcon(Icon icon, Qt::GUIStyle);
|
---|
| 299 | static QT3_SUPPORT int message(const QString &title,
|
---|
| 300 | const QString& text,
|
---|
| 301 | const QString& buttonText=QString(),
|
---|
| 302 | QWidget *parent = 0, const char * = 0) {
|
---|
| 303 | return QMessageBox::information(parent, title, text,
|
---|
| 304 | buttonText.isEmpty() ? tr("OK") : buttonText) == 0;
|
---|
| 305 | }
|
---|
| 306 | static QT3_SUPPORT bool query(const QString &title,
|
---|
| 307 | const QString& text,
|
---|
| 308 | const QString& yesButtonText = QString(),
|
---|
| 309 | const QString& noButtonText = QString(),
|
---|
| 310 | QWidget *parent = 0, const char * = 0) {
|
---|
| 311 | return QMessageBox::information(parent, title, text,
|
---|
| 312 | yesButtonText.isEmpty() ? tr("OK") : yesButtonText,
|
---|
| 313 | noButtonText) == 0;
|
---|
| 314 | }
|
---|
| 315 | #endif
|
---|
| 316 |
|
---|
| 317 | static QPixmap standardIcon(Icon icon);
|
---|
| 318 |
|
---|
| 319 | Q_SIGNALS:
|
---|
| 320 | void buttonClicked(QAbstractButton *button);
|
---|
| 321 |
|
---|
| 322 | #ifdef qdoc
|
---|
| 323 | public Q_SLOTS:
|
---|
| 324 | int exec();
|
---|
| 325 | #endif
|
---|
| 326 |
|
---|
| 327 | protected:
|
---|
| 328 | bool event(QEvent *e);
|
---|
| 329 | void resizeEvent(QResizeEvent *event);
|
---|
| 330 | void showEvent(QShowEvent *event);
|
---|
| 331 | void closeEvent(QCloseEvent *event);
|
---|
| 332 | void keyPressEvent(QKeyEvent *event);
|
---|
| 333 | void changeEvent(QEvent *event);
|
---|
| 334 |
|
---|
| 335 | private:
|
---|
| 336 | Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked(QAbstractButton *))
|
---|
| 337 |
|
---|
| 338 | Q_DISABLE_COPY(QMessageBox)
|
---|
| 339 | Q_DECLARE_PRIVATE(QMessageBox)
|
---|
| 340 | };
|
---|
| 341 |
|
---|
| 342 | Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons)
|
---|
| 343 |
|
---|
| 344 | #define QT_REQUIRE_VERSION(argc, argv, str) { QString s = QString::fromLatin1(str);\
|
---|
| 345 | QString sq = QString::fromLatin1(qVersion()); \
|
---|
| 346 | if ((sq.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
|
---|
| 347 | (sq.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
|
---|
| 348 | sq.section(QChar::fromLatin1('.'),2,2).toInt()<(s.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
|
---|
| 349 | (s.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
|
---|
| 350 | s.section(QChar::fromLatin1('.'),2,2).toInt()) { \
|
---|
| 351 | if (!qApp){ \
|
---|
| 352 | new QApplication(argc,argv); \
|
---|
| 353 | } \
|
---|
| 354 | QString s = QApplication::tr("Executable '%1' requires Qt "\
|
---|
| 355 | "%2, found Qt %3.").arg(qAppName()).arg(QString::fromLatin1(\
|
---|
| 356 | str)).arg(QString::fromLatin1(qVersion())); QMessageBox::critical(0, QApplication::tr(\
|
---|
[846] | 357 | "Incompatible Qt Library Error"), s, QMessageBox::Abort, 0); qFatal("%s", s.toLatin1().data()); }}
|
---|
[2] | 358 |
|
---|
| 359 | #endif // QT_NO_MESSAGEBOX
|
---|
| 360 |
|
---|
| 361 | QT_END_NAMESPACE
|
---|
| 362 |
|
---|
| 363 | QT_END_HEADER
|
---|
| 364 |
|
---|
| 365 | #endif // QMESSAGEBOX_H
|
---|