source: trunk/src/gui/dialogs/qmessagebox.h@ 135

Last change on this file since 135 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 14.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
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**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QMESSAGEBOX_H
43#define QMESSAGEBOX_H
44
45#include <QtGui/qdialog.h>
46
47QT_BEGIN_HEADER
48
49QT_BEGIN_NAMESPACE
50
51QT_MODULE(Gui)
52
53#ifndef QT_NO_MESSAGEBOX
54
55class QLabel;
56class QMessageBoxPrivate;
57class QAbstractButton;
58
59class 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
75public:
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
148#ifdef Q_OS_WINCE
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);
194 static StandardButton question(QWidget *parent, const QString &title,
195 const QString &text, StandardButtons buttons = Ok,
196 StandardButton defaultButton = NoButton);
197 static StandardButton warning(QWidget *parent, const QString &title,
198 const QString &text, StandardButtons buttons = Ok,
199 StandardButton defaultButton = NoButton);
200 static StandardButton critical(QWidget *parent, const QString &title,
201 const QString &text, StandardButtons buttons = Ok,
202 StandardButton defaultButton = NoButton);
203 static void about(QWidget *parent, const QString &title, const QString &text);
204 static void aboutQt(QWidget *parent, const QString &title = QString());
205
206 QSize sizeHint() const;
207
208 // the following functions are obsolete:
209
210 QMessageBox(const QString &title, const QString &text, Icon icon,
211 int button0, int button1, int button2,
212 QWidget *parent = 0,
213 Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
214
215 static int information(QWidget *parent, const QString &title,
216 const QString& text,
217 int button0, int button1 = 0, int button2 = 0);
218 static int information(QWidget *parent, const QString &title,
219 const QString& text,
220 const QString& button0Text,
221 const QString& button1Text = QString(),
222 const QString& button2Text = QString(),
223 int defaultButtonNumber = 0,
224 int escapeButtonNumber = -1);
225 inline static StandardButton information(QWidget *parent, const QString &title,
226 const QString& text,
227 StandardButton button0, StandardButton button1 = NoButton)
228 { return information(parent, title, text, StandardButtons(button0), button1); }
229
230 static int question(QWidget *parent, const QString &title,
231 const QString& text,
232 int button0, int button1 = 0, int button2 = 0);
233 static int question(QWidget *parent, const QString &title,
234 const QString& text,
235 const QString& button0Text,
236 const QString& button1Text = QString(),
237 const QString& button2Text = QString(),
238 int defaultButtonNumber = 0,
239 int escapeButtonNumber = -1);
240 inline static int question(QWidget *parent, const QString &title,
241 const QString& text,
242 StandardButton button0, StandardButton button1)
243 { return question(parent, title, text, StandardButtons(button0), button1); }
244
245 static int warning(QWidget *parent, const QString &title,
246 const QString& text,
247 int button0, int button1, int button2 = 0);
248 static int warning(QWidget *parent, const QString &title,
249 const QString& text,
250 const QString& button0Text,
251 const QString& button1Text = QString(),
252 const QString& button2Text = QString(),
253 int defaultButtonNumber = 0,
254 int escapeButtonNumber = -1);
255 inline static int warning(QWidget *parent, const QString &title,
256 const QString& text,
257 StandardButton button0, StandardButton button1)
258 { return warning(parent, title, text, StandardButtons(button0), button1); }
259
260 static int critical(QWidget *parent, const QString &title,
261 const QString& text,
262 int button0, int button1, int button2 = 0);
263 static int critical(QWidget *parent, const QString &title,
264 const QString& text,
265 const QString& button0Text,
266 const QString& button1Text = QString(),
267 const QString& button2Text = QString(),
268 int defaultButtonNumber = 0,
269 int escapeButtonNumber = -1);
270 inline static int critical(QWidget *parent, const QString &title,
271 const QString& text,
272 StandardButton button0, StandardButton button1)
273 { return critical(parent, title, text, StandardButtons(button0), button1); }
274
275 QString buttonText(int button) const;
276 void setButtonText(int button, const QString &text);
277
278 QString informativeText() const;
279 void setInformativeText(const QString &text);
280
281#ifndef QT_NO_TEXTEDIT
282 QString detailedText() const;
283 void setDetailedText(const QString &text);
284#endif
285
286 void setWindowTitle(const QString &title);
287 void setWindowModality(Qt::WindowModality windowModality);
288
289#ifdef QT3_SUPPORT
290 QT3_SUPPORT_CONSTRUCTOR QMessageBox(const QString &title, const QString &text, Icon icon,
291 int button0, int button1, int button2,
292 QWidget *parent, const char *name, bool modal,
293 Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
294 QT3_SUPPORT_CONSTRUCTOR QMessageBox(QWidget *parent, const char *name);
295
296 static QT3_SUPPORT QPixmap standardIcon(Icon icon, Qt::GUIStyle);
297 static QT3_SUPPORT int message(const QString &title,
298 const QString& text,
299 const QString& buttonText=QString(),
300 QWidget *parent = 0, const char * = 0) {
301 return QMessageBox::information(parent, title, text,
302 buttonText.isEmpty() ? tr("OK") : buttonText) == 0;
303 }
304 static QT3_SUPPORT bool query(const QString &title,
305 const QString& text,
306 const QString& yesButtonText = QString(),
307 const QString& noButtonText = QString(),
308 QWidget *parent = 0, const char * = 0) {
309 return QMessageBox::information(parent, title, text,
310 yesButtonText.isEmpty() ? tr("OK") : yesButtonText,
311 noButtonText) == 0;
312 }
313#endif
314
315 static QPixmap standardIcon(Icon icon);
316
317Q_SIGNALS:
318 void buttonClicked(QAbstractButton *button);
319
320#ifdef qdoc
321public Q_SLOTS:
322 int exec();
323#endif
324
325protected:
326 bool event(QEvent *e);
327 void resizeEvent(QResizeEvent *event);
328 void showEvent(QShowEvent *event);
329 void closeEvent(QCloseEvent *event);
330 void keyPressEvent(QKeyEvent *event);
331 void changeEvent(QEvent *event);
332
333private:
334 Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked(QAbstractButton *))
335
336 Q_DISABLE_COPY(QMessageBox)
337 Q_DECLARE_PRIVATE(QMessageBox)
338};
339
340Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons)
341
342#define QT_REQUIRE_VERSION(argc, argv, str) { QString s = QString::fromLatin1(str);\
343QString sq = QString::fromLatin1(qVersion()); \
344if ((sq.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
345(sq.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
346sq.section(QChar::fromLatin1('.'),2,2).toInt()<(s.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
347(s.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
348s.section(QChar::fromLatin1('.'),2,2).toInt()) { \
349if (!qApp){ \
350 new QApplication(argc,argv); \
351} \
352QString s = QApplication::tr("Executable '%1' requires Qt "\
353 "%2, found Qt %3.").arg(qAppName()).arg(QString::fromLatin1(\
354str)).arg(QString::fromLatin1(qVersion())); QMessageBox::critical(0, QApplication::tr(\
355"Incompatible Qt Library Error"), s, QMessageBox::Abort, 0); qFatal(s.toLatin1().data()); }}
356
357#endif // QT_NO_MESSAGEBOX
358
359QT_END_NAMESPACE
360
361QT_END_HEADER
362
363#endif // QMESSAGEBOX_H
Note: See TracBrowser for help on using the repository browser.