1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
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 | **
|
---|
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.
|
---|
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 have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtGui/qmessagebox.h>
|
---|
43 |
|
---|
44 | #ifndef QT_NO_MESSAGEBOX
|
---|
45 |
|
---|
46 | #include <QtGui/qdialogbuttonbox.h>
|
---|
47 | #include "private/qlabel_p.h"
|
---|
48 | #include "private/qapplication_p.h"
|
---|
49 | #include <QtCore/qlist.h>
|
---|
50 | #include <QtCore/qdebug.h>
|
---|
51 | #include <QtGui/qstyle.h>
|
---|
52 | #include <QtGui/qstyleoption.h>
|
---|
53 | #include <QtGui/qgridlayout.h>
|
---|
54 | #include <QtGui/qdesktopwidget.h>
|
---|
55 | #include <QtGui/qpushbutton.h>
|
---|
56 | #include <QtGui/qaccessible.h>
|
---|
57 | #include <QtGui/qicon.h>
|
---|
58 | #include <QtGui/qtextdocument.h>
|
---|
59 | #include <QtGui/qapplication.h>
|
---|
60 | #include <QtGui/qtextedit.h>
|
---|
61 | #include <QtGui/qtextbrowser.h>
|
---|
62 | #include <QtGui/qmenu.h>
|
---|
63 | #include "qdialog_p.h"
|
---|
64 | #include <QtGui/qfont.h>
|
---|
65 | #include <QtGui/qfontmetrics.h>
|
---|
66 | #include <QtGui/qclipboard.h>
|
---|
67 |
|
---|
68 | #ifdef Q_WS_WINCE
|
---|
69 | extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
|
---|
70 | extern bool qt_wince_is_smartphone();//defined in qguifunctions_wince.cpp
|
---|
71 | extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wince.cpp
|
---|
72 |
|
---|
73 | #include "qguifunctions_wince.h"
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | QT_BEGIN_NAMESPACE
|
---|
77 |
|
---|
78 | enum Button { Old_Ok = 1, Old_Cancel = 2, Old_Yes = 3, Old_No = 4, Old_Abort = 5, Old_Retry = 6,
|
---|
79 | Old_Ignore = 7, Old_YesAll = 8, Old_NoAll = 9, Old_ButtonMask = 0xFF,
|
---|
80 | NewButtonMask = 0xFFFFFC00 };
|
---|
81 |
|
---|
82 | enum DetailButtonLabel { ShowLabel = 0, HideLabel = 1 };
|
---|
83 | #ifndef QT_NO_TEXTEDIT
|
---|
84 | class QMessageBoxDetailsText : public QWidget
|
---|
85 | {
|
---|
86 | public:
|
---|
87 | class TextEdit : public QTextEdit
|
---|
88 | {
|
---|
89 | public:
|
---|
90 | TextEdit(QWidget *parent=0) : QTextEdit(parent) { }
|
---|
91 | void contextMenuEvent(QContextMenuEvent * e)
|
---|
92 | {
|
---|
93 | #ifndef QT_NO_CONTEXTMENU
|
---|
94 | QMenu *menu = createStandardContextMenu();
|
---|
95 | menu->exec(e->globalPos());
|
---|
96 | delete menu;
|
---|
97 | #else
|
---|
98 | Q_UNUSED(e);
|
---|
99 | #endif
|
---|
100 | }
|
---|
101 | };
|
---|
102 |
|
---|
103 | QMessageBoxDetailsText(QWidget *parent=0)
|
---|
104 | : QWidget(parent)
|
---|
105 | {
|
---|
106 | QVBoxLayout *layout = new QVBoxLayout;
|
---|
107 | layout->setMargin(0);
|
---|
108 | QFrame *line = new QFrame(this);
|
---|
109 | line->setFrameShape(QFrame::HLine);
|
---|
110 | line->setFrameShadow(QFrame::Sunken);
|
---|
111 | layout->addWidget(line);
|
---|
112 | textEdit = new TextEdit();
|
---|
113 | textEdit->setFixedHeight(100);
|
---|
114 | textEdit->setFocusPolicy(Qt::NoFocus);
|
---|
115 | textEdit->setReadOnly(true);
|
---|
116 | layout->addWidget(textEdit);
|
---|
117 | setLayout(layout);
|
---|
118 | }
|
---|
119 | void setText(const QString &text) { textEdit->setPlainText(text); }
|
---|
120 | QString text() const { return textEdit->toPlainText(); }
|
---|
121 | QString label(DetailButtonLabel label)
|
---|
122 | { return label == ShowLabel ? QMessageBox::tr("Show Details...")
|
---|
123 | : QMessageBox::tr("Hide Details..."); }
|
---|
124 | private:
|
---|
125 | TextEdit *textEdit;
|
---|
126 | };
|
---|
127 | #endif // QT_NO_TEXTEDIT
|
---|
128 |
|
---|
129 | class QMessageBoxPrivate : public QDialogPrivate
|
---|
130 | {
|
---|
131 | Q_DECLARE_PUBLIC(QMessageBox)
|
---|
132 |
|
---|
133 | public:
|
---|
134 | QMessageBoxPrivate() : escapeButton(0), defaultButton(0), clickedButton(0), detailsButton(0),
|
---|
135 | #ifndef QT_NO_TEXTEDIT
|
---|
136 | detailsText(0),
|
---|
137 | #endif
|
---|
138 | compatMode(false), autoAddOkButton(true),
|
---|
139 | detectedEscapeButton(0), informativeLabel(0) { }
|
---|
140 |
|
---|
141 | void init(const QString &title = QString(), const QString &text = QString());
|
---|
142 | void _q_buttonClicked(QAbstractButton *);
|
---|
143 |
|
---|
144 | QAbstractButton *findButton(int button0, int button1, int button2, int flags);
|
---|
145 | void addOldButtons(int button0, int button1, int button2);
|
---|
146 |
|
---|
147 | QAbstractButton *abstractButtonForId(int id) const;
|
---|
148 | int execReturnCode(QAbstractButton *button);
|
---|
149 |
|
---|
150 | void detectEscapeButton();
|
---|
151 | void updateSize();
|
---|
152 | int layoutMinimumWidth();
|
---|
153 | void retranslateStrings();
|
---|
154 |
|
---|
155 | #ifdef Q_WS_WINCE
|
---|
156 | void hideSpecial();
|
---|
157 | #endif
|
---|
158 |
|
---|
159 | static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
---|
160 | const QString &title, const QString &text,
|
---|
161 | int button0, int button1, int button2);
|
---|
162 | static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
---|
163 | const QString &title, const QString &text,
|
---|
164 | const QString &button0Text,
|
---|
165 | const QString &button1Text,
|
---|
166 | const QString &button2Text,
|
---|
167 | int defaultButtonNumber,
|
---|
168 | int escapeButtonNumber);
|
---|
169 |
|
---|
170 | static QMessageBox::StandardButton showNewMessageBox(QWidget *parent,
|
---|
171 | QMessageBox::Icon icon, const QString& title, const QString& text,
|
---|
172 | QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);
|
---|
173 |
|
---|
174 | static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb);
|
---|
175 |
|
---|
176 | QLabel *label;
|
---|
177 | QMessageBox::Icon icon;
|
---|
178 | QLabel *iconLabel;
|
---|
179 | QDialogButtonBox *buttonBox;
|
---|
|
---|