~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/widgets/dialogs/qmessagebox.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

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