1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
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 qt-info@nokia.com.
|
---|
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 | #ifndef QT_NO_STYLE_S60
|
---|
69 | #include <qs60style.h>
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | #ifdef Q_WS_WINCE
|
---|
73 | extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
|
---|
74 | extern bool qt_wince_is_smartphone();//defined in qguifunctions_wince.cpp
|
---|
75 | extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wince.cpp
|
---|
76 |
|
---|
77 | #include "qguifunctions_wince.h"
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | QT_BEGIN_NAMESPACE
|
---|
81 |
|
---|
82 | enum Button { Old_Ok = 1, Old_Cancel = 2, Old_Yes = 3, Old_No = 4, Old_Abort = 5, Old_Retry = 6,
|
---|
83 | Old_Ignore = 7, Old_YesAll = 8, Old_NoAll = 9, Old_ButtonMask = 0xFF,
|
---|
84 | NewButtonMask = 0xFFFFFC00 };
|
---|
85 |
|
---|
86 | enum DetailButtonLabel { ShowLabel = 0, HideLabel = 1 };
|
---|
87 | #ifndef QT_NO_TEXTEDIT
|
---|
88 | class QMessageBoxDetailsText : public QWidget
|
---|
89 | {
|
---|
90 | public:
|
---|
91 | class TextEdit : public QTextEdit
|
---|
92 | {
|
---|
93 | public:
|
---|
94 | TextEdit(QWidget *parent=0) : QTextEdit(parent) { }
|
---|
95 | void contextMenuEvent(QContextMenuEvent * e)
|
---|
96 | {
|
---|
97 | #ifndef QT_NO_CONTEXTMENU
|
---|
98 | QMenu *menu = createStandardContextMenu();
|
---|
99 | menu->exec(e->globalPos());
|
---|
100 | delete menu;
|
---|
101 | #else
|
---|
102 | Q_UNUSED(e);
|
---|
103 | #endif
|
---|
104 | }
|
---|
105 | };
|
---|
106 |
|
---|
107 | QMessageBoxDetailsText(QWidget *parent=0)
|
---|
108 | : QWidget(parent)
|
---|
109 | {
|
---|
110 | QVBoxLayout *layout = new QVBoxLayout;
|
---|
111 | layout->setMargin(0);
|
---|
112 | QFrame *line = new QFrame(this);
|
---|
113 | line->setFrameShape(QFrame::HLine);
|
---|
114 | line->setFrameShadow(QFrame::Sunken);
|
---|
115 | layout->addWidget(line);
|
---|
116 | textEdit = new TextEdit();
|
---|
117 | textEdit->setFixedHeight(100);
|
---|
118 | textEdit->setFocusPolicy(Qt::NoFocus);
|
---|
119 | textEdit->setReadOnly(true);
|
---|
120 | layout->addWidget(textEdit);
|
---|
121 | setLayout(layout);
|
---|
122 | }
|
---|
123 | void setText(const QString &text) { textEdit->setPlainText(text); }
|
---|
124 | QString text() const { return textEdit->toPlainText(); }
|
---|
125 | QString label(DetailButtonLabel label)
|
---|
126 | { return label == ShowLabel ? QMessageBox::tr("Show Details...")
|
---|
127 | : QMessageBox::tr("Hide Details..."); }
|
---|
128 | private:
|
---|
129 | TextEdit *textEdit;
|
---|
130 | };
|
---|
131 | #endif // QT_NO_TEXTEDIT
|
---|
132 |
|
---|
133 | class QMessageBoxPrivate : public QDialogPrivate
|
---|
134 | {
|
---|
135 | Q_DECLARE_PUBLIC(QMessageBox)
|
---|
136 |
|
---|
137 | public:
|
---|
138 | QMessageBoxPrivate() : escapeButton(0), defaultButton(0), clickedButton(0), detailsButton(0),
|
---|
139 | #ifndef QT_NO_TEXTEDIT
|
---|
140 | detailsText(0),
|
---|
141 | #endif
|
---|
142 | compatMode(false), autoAddOkButton(true),
|
---|
143 | detectedEscapeButton(0), informativeLabel(0) { }
|
---|
144 |
|
---|
145 | void init(const QString &title = QString(), const QString &text = QString());
|
---|
146 | void _q_buttonClicked(QAbstractButton *);
|
---|
147 |
|
---|
148 | QAbstractButton *findButton(int button0, int button1, int button2, int flags);
|
---|
149 | void addOldButtons(int button0, int button1, int button2);
|
---|
150 |
|
---|
151 | QAbstractButton *abstractButtonForId(int id) const;
|
---|
152 | int execReturnCode(QAbstractButton *button);
|
---|
153 |
|
---|
154 | void detectEscapeButton();
|
---|
155 | void updateSize();
|
---|
156 | int layoutMinimumWidth();
|
---|
157 | void retranslateStrings();
|
---|
158 |
|
---|
159 | #ifdef Q_WS_WINCE
|
---|
160 | void hideSpecial();
|
---|
161 | #endif
|
---|
162 |
|
---|
163 | static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
---|
164 | const QString &title, const QString &text,
|
---|
165 | int button0, int button1, int button2);
|
---|
166 | static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
---|
167 | const QString &title, const QString &text,
|
---|
168 | const QString &button0Text,
|
---|
169 | const QString &button1Text,
|
---|
170 | const QString &button2Text,
|
---|
171 | int defaultButtonNumber,
|
---|
172 | int escapeButtonNumber);
|
---|
173 |
|
---|
174 | static QMessageBox::StandardButton showNewMessageBox(QWidget *parent,
|
---|
175 | QMessageBox::Icon icon, const QString& title, const QString& text,
|
---|
176 | QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);
|
---|
177 |
|
---|
178 | static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb);
|
---|
179 |
|
---|
180 | QLabel *label;
|
---|
181 | QMessageBox::Icon icon;
|
---|
182 | QLabel *iconLabel;
|
---|
183 | QDialogButtonBox *buttonBox;
|
---|
184 | QList<QAbstractButton *> customButtonList;
|
---|
185 | QAbstractButton *escapeButton;
|
---|
186 | QPushButton *defaultButton;
|
---|
187 | QAbstractButton *clickedButton;
|
---|
188 | QPushButton *detailsButton;
|
---|
189 | #ifndef QT_NO_TEXTEDIT
|
---|
190 | QMessageBoxDetailsText *detailsText;
|
---|
191 | #endif
|
---|
192 | bool compatMode;
|
---|
193 | bool autoAddOkButton;
|
---|
194 | QAbstractButton *detectedEscapeButton;
|
---|
195 | QLabel *informativeLabel;
|
---|
196 | #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
|
---|
197 | QTextBrowser *textBrowser;
|
---|
198 | #endif
|
---|
199 | QPointer<QObject> receiverToDisconnectOnClose;
|
---|
200 | QByteArray memberToDisconnectOnClose;
|
---|
201 | QByteArray signalToDisconnectOnClose;
|
---|
202 | };
|
---|
203 |
|
---|
204 | void QMessageBoxPrivate::init(const QString &title, const QString &text)
|
---|
205 | {
|
---|
206 | Q_Q(QMessageBox);
|
---|
207 |
|
---|
208 | label = new QLabel;
|
---|
209 | label->setObjectName(QLatin1String("qt_msgbox_label"));
|
---|
210 | label->setTextInteractionFlags(Qt::TextInteractionFlags(q->style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, q)));
|
---|
211 | label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
---|
212 | label->setOpenExternalLinks(true);
|
---|
213 | #if defined(Q_WS_MAC)
|
---|
214 | label->setContentsMargins(16, 0, 0, 0);
|
---|
215 | #elif !defined(Q_WS_QWS)
|
---|
216 | label->setContentsMargins(2, 0, 0, 0);
|
---|
217 | label->setIndent(9);
|
---|
218 | #endif
|
---|
219 | icon = QMessageBox::NoIcon;
|
---|
220 | iconLabel = new QLabel;
|
---|
221 | iconLabel->setObjectName(QLatin1String("qt_msgboxex_icon_label"));
|
---|
222 | iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
223 |
|
---|
224 | buttonBox = new QDialogButtonBox;
|
---|
225 | buttonBox->setObjectName(QLatin1String("qt_msgbox_buttonbox"));
|
---|
226 | buttonBox->setCenterButtons(q->style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, q));
|
---|
227 | QObject::connect(buttonBox, SIGNAL(clicked(QAbstractButton*)),
|
---|
228 | q, SLOT(_q_buttonClicked(QAbstractButton*)));
|
---|
229 |
|
---|
230 | QGridLayout *grid = new QGridLayout;
|
---|
231 | #ifndef Q_WS_MAC
|
---|
232 | grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop);
|
---|
233 | grid->addWidget(label, 0, 1, 1, 1);
|
---|
234 | // -- leave space for information label --
|
---|
235 | grid->addWidget(buttonBox, 2, 0, 1, 2);
|
---|
236 | #else
|
---|
237 | grid->setMargin(0);
|
---|
238 | grid->setVerticalSpacing(8);
|
---|
239 | grid->setHorizontalSpacing(0);
|
---|
240 | q->setContentsMargins(24, 15, 24, 20);
|
---|
241 | grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop | Qt::AlignLeft);
|
---|
242 | grid->addWidget(label, 0, 1, 1, 1);
|
---|
243 | // -- leave space for information label --
|
---|
244 | grid->setRowStretch(1, 100);
|
---|
245 | grid->setRowMinimumHeight(2, 6);
|
---|
246 | grid->addWidget(buttonBox, 3, 1, 1, 1);
|
---|
247 | #endif
|
---|
248 |
|
---|
249 | grid->setSizeConstraint(QLayout::SetNoConstraint);
|
---|
250 | q->setLayout(grid);
|
---|
251 |
|
---|
252 | if (!title.isEmpty() || !text.isEmpty()) {
|
---|
253 | q->setWindowTitle(title);
|
---|
254 | q->setText(text);
|
---|
255 | }
|
---|
256 | q->setModal(true);
|
---|
257 |
|
---|
258 | #ifdef Q_WS_MAC
|
---|
259 | QFont f = q->font();
|
---|
260 | f.setBold(true);
|
---|
261 | label->setFont(f);
|
---|
262 | #endif
|
---|
263 | retranslateStrings();
|
---|
264 | }
|
---|
265 |
|
---|
266 | int QMessageBoxPrivate::layoutMinimumWidth()
|
---|
267 | {
|
---|
268 | layout->activate();
|
---|
269 | return layout->totalMinimumSize().width();
|
---|
270 | }
|
---|
271 |
|
---|
272 | void QMessageBoxPrivate::updateSize()
|
---|
273 | {
|
---|
274 | Q_Q(QMessageBox);
|
---|
275 |
|
---|
276 | if (!q->isVisible())
|
---|
277 | return;
|
---|
278 |
|
---|
279 | QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
|
---|
280 | #if defined(Q_WS_QWS) || defined(Q_WS_WINCE) || defined(Q_OS_SYMBIAN)
|
---|
281 | // the width of the screen, less the window border.
|
---|
282 | int hardLimit = screenSize.width() - (q->frameGeometry().width() - q->geometry().width());
|
---|
283 | #else
|
---|
284 | int hardLimit = qMin(screenSize.width() - 480, 1000); // can never get bigger than this
|
---|
285 | // on small screens allows the messagebox be the same size as the screen
|
---|
286 | if (screenSize.width() <= 1024)
|
---|
287 | hardLimit = screenSize.width();
|
---|
288 | #endif
|
---|
289 | #ifdef Q_WS_MAC
|
---|
290 | int softLimit = qMin(screenSize.width()/2, 420);
|
---|
291 | #elif defined(Q_WS_QWS)
|
---|
292 | int softLimit = qMin(hardLimit, 500);
|
---|
293 | #else
|
---|
294 | // note: ideally on windows, hard and soft limits but it breaks compat
|
---|
295 | #ifndef Q_WS_WINCE
|
---|
296 | int softLimit = qMin(screenSize.width()/2, 500);
|
---|
297 | #else
|
---|
298 | int softLimit = qMin(screenSize.width() * 3 / 4, 500);
|
---|
299 | #endif //Q_WS_WINCE
|
---|
300 | #endif
|
---|
301 |
|
---|
302 | if (informativeLabel)
|
---|
303 | informativeLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
---|
304 |
|
---|
305 | label->setWordWrap(false); // makes the label return min size
|
---|
306 | int width = layoutMinimumWidth();
|
---|
307 |
|
---|
308 | if (width > softLimit) {
|
---|
309 | label->setWordWrap(true);
|
---|
310 | width = qMax(softLimit, layoutMinimumWidth());
|
---|
311 |
|
---|
312 | if (width > hardLimit) {
|
---|
313 | label->d_func()->ensureTextControl();
|
---|
314 | if (QTextControl *control = label->d_func()->control) {
|
---|
315 | QTextOption opt = control->document()->defaultTextOption();
|
---|
316 | opt.setWrapMode(QTextOption::WrapAnywhere);
|
---|
317 | control->document()->setDefaultTextOption(opt);
|
---|
318 | }
|
---|
319 | width = hardLimit;
|
---|
320 | }
|
---|
321 | }
|
---|
322 | #ifdef Q_WS_S60
|
---|
323 | // in S60 portait messageBoxes should always occupy maximum width
|
---|
324 | if (QApplication::desktop()->size().height() > QApplication::desktop()->size().width()){
|
---|
325 | width = hardLimit;
|
---|
326 | } else {
|
---|
327 | // in landscape the messageBoxes should be of same width as in portrait
|
---|
328 | width = qMin(QApplication::desktop()->size().height(), hardLimit);
|
---|
329 | }
|
---|
330 | #endif
|
---|
331 |
|
---|
332 | if (informativeLabel) {
|
---|
333 | label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
---|
334 | QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
---|
335 | policy.setHeightForWidth(true);
|
---|
336 | informativeLabel->setSizePolicy(policy);
|
---|
337 | width = qMax(width, layoutMinimumWidth());
|
---|
338 | if (width > hardLimit) { // longest word is really big, so wrap anywhere
|
---|
339 | informativeLabel->d_func()->ensureTextControl();
|
---|
340 | if (QTextControl *control = informativeLabel->d_func()->control) {
|
---|
341 | QTextOption opt = control->document()->defaultTextOption();
|
---|
342 | opt.setWrapMode(QTextOption::WrapAnywhere);
|
---|
343 | control->document()->setDefaultTextOption(opt);
|
---|
344 | }
|
---|
345 | width = hardLimit;
|
---|
346 | }
|
---|
347 | policy.setHeightForWidth(label->wordWrap());
|
---|
348 | label->setSizePolicy(policy);
|
---|
349 | }
|
---|
350 |
|
---|
351 | QFontMetrics fm(QApplication::font("QWorkspaceTitleBar"));
|
---|
352 | int windowTitleWidth = qMin(fm.width(q->windowTitle()) + 50, hardLimit);
|
---|
353 | if (windowTitleWidth > width)
|
---|
354 | width = windowTitleWidth;
|
---|
355 |
|
---|
356 | layout->activate();
|
---|
357 | int height = (layout->hasHeightForWidth())
|
---|
358 | ? layout->totalHeightForWidth(width)
|
---|
359 | : layout->totalMinimumSize().height();
|
---|
360 |
|
---|
361 | #ifndef QT_NO_STYLE_S60
|
---|
362 | QS60Style *s60Style = 0;
|
---|
363 | s60Style = qobject_cast<QS60Style *>(QApplication::style());
|
---|
364 |
|
---|
365 | //use custom pixel metric to deduce the minimum height of the messagebox
|
---|
366 | if (s60Style)
|
---|
367 | height = qMax(height, s60Style->pixelMetric((QStyle::PixelMetric)PM_MessageBoxHeight));
|
---|
368 | #endif
|
---|
369 |
|
---|
370 | q->setFixedSize(width, height);
|
---|
371 | QCoreApplication::removePostedEvents(q, QEvent::LayoutRequest);
|
---|
372 | }
|
---|
373 |
|
---|
374 |
|
---|
375 | #ifdef Q_WS_WINCE
|
---|
376 | /*!
|
---|
377 | \internal
|
---|
378 | Hides special buttons which are rather shown in the title bar
|
---|
379 | on WinCE, to conserve screen space.
|
---|
380 | */
|
---|
381 |
|
---|
382 | void QMessageBoxPrivate::hideSpecial()
|
---|
383 | {
|
---|
384 | Q_Q(QMessageBox);
|
---|
385 | QList<QPushButton*> list = qFindChildren<QPushButton*>(q);
|
---|
386 | for (int i=0; i<list.size(); ++i) {
|
---|
387 | QPushButton *pb = list.at(i);
|
---|
388 | QString text = pb->text();
|
---|
389 | text.remove(QChar::fromLatin1('&'));
|
---|
390 | if (text == QApplication::translate("QMessageBox", "OK" ))
|
---|
391 | pb->setFixedSize(0,0);
|
---|
392 | }
|
---|
393 | }
|
---|
394 | #endif
|
---|
395 |
|
---|
396 | static int oldButton(int button)
|
---|
397 | {
|
---|
398 | switch (button & QMessageBox::ButtonMask) {
|
---|
399 | case QMessageBox::Ok:
|
---|
400 | return Old_Ok;
|
---|
401 | case QMessageBox::Cancel:
|
---|
402 | return Old_Cancel;
|
---|
403 | case QMessageBox::Yes:
|
---|
404 | return Old_Yes;
|
---|
405 | case QMessageBox::No:
|
---|
406 | return Old_No;
|
---|
407 | case QMessageBox::Abort:
|
---|
408 | return Old_Abort;
|
---|
409 | case QMessageBox::Retry:
|
---|
410 | return Old_Retry;
|
---|
411 | case QMessageBox::Ignore:
|
---|
412 | return Old_Ignore;
|
---|
413 | case QMessageBox::YesToAll:
|
---|
414 | return Old_YesAll;
|
---|
415 | case QMessageBox::NoToAll:
|
---|
416 | return Old_NoAll;
|
---|
417 | default:
|
---|
418 | return 0;
|
---|
419 | }
|
---|
420 | }
|
---|
421 |
|
---|
422 | int QMessageBoxPrivate::execReturnCode(QAbstractButton *button)
|
---|
423 | {
|
---|
424 | int ret = buttonBox->standardButton(button);
|
---|
425 | if (ret == QMessageBox::NoButton) {
|
---|
426 | ret = customButtonList.indexOf(button); // if button == 0, correctly sets ret = -1
|
---|
427 | } else if (compatMode) {
|
---|
428 | ret = oldButton(ret);
|
---|
429 | }
|
---|
430 | return ret;
|
---|
431 | }
|
---|
432 |
|
---|
433 | void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button)
|
---|
434 | {
|
---|
435 | Q_Q(QMessageBox);
|
---|
436 | #ifndef QT_NO_TEXTEDIT
|
---|
437 | if (detailsButton && detailsText && button == detailsButton) {
|
---|
438 | detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel));
|
---|
439 | detailsText->setHidden(!detailsText->isHidden());
|
---|
440 | updateSize();
|
---|
441 | } else
|
---|
442 | #endif
|
---|
443 | {
|
---|
444 | clickedButton = button;
|
---|
445 | q->done(execReturnCode(button)); // does not trigger closeEvent
|
---|
446 | emit q->buttonClicked(button);
|
---|
447 |
|
---|
448 | if (receiverToDisconnectOnClose) {
|
---|
449 | QObject::disconnect(q, signalToDisconnectOnClose, receiverToDisconnectOnClose,
|
---|
450 | memberToDisconnectOnClose);
|
---|
451 | receiverToDisconnectOnClose = 0;
|
---|
452 | }
|
---|
453 | signalToDisconnectOnClose.clear();
|
---|
454 | memberToDisconnectOnClose.clear();
|
---|
455 | }
|
---|
456 | }
|
---|
457 |
|
---|
458 | /*!
|
---|
459 | \class QMessageBox
|
---|
460 |
|
---|
461 | \brief The QMessageBox class provides a modal dialog for informing
|
---|
462 | the user or for asking the user a question and receiving an answer.
|
---|
463 |
|
---|
464 | \ingroup standard-dialogs
|
---|
465 |
|
---|
466 |
|
---|
467 | A message box displays a primary \l{QMessageBox::text}{text} to
|
---|
468 | alert the user to a situation, an \l{QMessageBox::informativeText}
|
---|
469 | {informative text} to further explain the alert or to ask the user
|
---|
470 | a question, and an optional \l{QMessageBox::detailedText}
|
---|
471 | {detailed text} to provide even more data if the user requests
|
---|
472 | it. A message box can also display an \l{QMessageBox::icon} {icon}
|
---|
473 | and \l{QMessageBox::standardButtons} {standard buttons} for
|
---|
474 | accepting a user response.
|
---|
475 |
|
---|
476 | Two APIs for using QMessageBox are provided, the property-based
|
---|
477 | API, and the static functions. Calling one of the static functions
|
---|
478 | is the simpler approach, but it is less flexible than using the
|
---|
479 | property-based API, and the result is less informative. Using the
|
---|
480 | property-based API is recommended.
|
---|
481 |
|
---|
482 | \section1 The Property-based API
|
---|
483 |
|
---|
484 | To use the property-based API, construct an instance of
|
---|
485 | QMessageBox, set the desired properties, and call exec() to show
|
---|
486 | the message. The simplest configuration is to set only the
|
---|
487 | \l{QMessageBox::text} {message text} property.
|
---|
488 |
|
---|
489 | \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 5
|
---|
490 |
|
---|
491 | The user must click the \gui{OK} button to dismiss the message
|
---|
492 | box. The rest of the GUI is blocked until the message box is
|
---|
493 | dismissed.
|
---|
494 |
|
---|
495 | \image msgbox1.png
|
---|
496 |
|
---|
497 | A better approach than just alerting the user to an event is to
|
---|
498 | also ask the user what to do about it. Store the question in the
|
---|
499 | \l{QMessageBox::informativeText} {informative text} property, and
|
---|
500 | set the \l{QMessageBox::standardButtons} {standard buttons}
|
---|
501 | property to the set of buttons you want as the set of user
|
---|
502 | responses. The buttons are specified by combining values from
|
---|
503 | StandardButtons using the bitwise OR operator. The display order
|
---|
504 | for the buttons is platform-dependent. For example, on Windows,
|
---|
505 | \gui{Save} is displayed to the left of \gui{Cancel}, whereas on
|
---|
506 | Mac OS, the order is reversed.
|
---|
507 |
|
---|
508 | Mark one of your standard buttons to be your
|
---|
509 | \l{QMessageBox::defaultButton()} {default button}.
|
---|
510 |
|
---|
511 | \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 6
|
---|
512 |
|
---|
513 | This is the approach recommended in the
|
---|
514 | \l{http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGWindows/chapter_18_section_7.html}
|
---|
515 | {Mac OS X Guidlines}. Similar guidlines apply for the other
|
---|
516 | platforms, but note the different ways the
|
---|
517 | \l{QMessageBox::informativeText} {informative text} is handled for
|
---|
518 | different platforms.
|
---|
519 |
|
---|
520 | \image msgbox2.png
|
---|
521 |
|
---|
522 | The exec() slot returns the StandardButtons value of the button
|
---|
523 | that was clicked.
|
---|
524 |
|
---|
525 | \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 7
|
---|
526 |
|
---|
527 | To give the user more information to help him answer the question,
|
---|
528 | set the \l{QMessageBox::detailedText} {detailed text} property. If
|
---|
529 | the \l{QMessageBox::detailedText} {detailed text} property is set,
|
---|
530 | the \gui{Show Details...} button will be shown.
|
---|
531 |
|
---|
532 | \image msgbox3.png
|
---|
533 |
|
---|
534 | Clicking the \gui{Show Details...} button displays the detailed text.
|
---|
535 |
|
---|
536 | \image msgbox4.png
|
---|
537 |
|
---|
538 | \section2 Rich Text and the Text Format Property
|
---|
539 |
|
---|
540 | The \l{QMessageBox::detailedText} {detailed text} property is
|
---|
541 | always interpreted as plain text. The \l{QMessageBox::text} {main
|
---|
542 | text} and \l{QMessageBox::informativeText} {informative text}
|
---|
543 | properties can be either plain text or rich text. These strings
|
---|
544 | are interpreted according to the setting of the
|
---|
545 | \l{QMessageBox::textFormat} {text format} property. The default
|
---|
546 | setting is \l{Qt::AutoText} {auto-text}.
|
---|
547 |
|
---|
548 | Note that for some plain text strings containing XML
|
---|
549 | meta-characters, the auto-text \l{Qt::mightBeRichText()} {rich
|
---|
550 | text detection test} may fail causing your plain text string to be
|
---|
551 | interpreted incorrectly as rich text. In these rare cases, use
|
---|
552 | Qt::convertFromPlainText() to convert your plain text string to a
|
---|
553 | visually equivalent rich text string, or set the
|
---|
554 | \l{QMessageBox::textFormat} {text format} property explicitly with
|
---|
555 | setTextFormat().
|
---|
556 |
|
---|
557 | \section2 Severity Levels and the Icon and Pixmap Properties
|
---|
558 |
|
---|
559 | QMessageBox supports four predefined message severity levels, or message
|
---|
560 | types, which really only differ in the predefined icon they each show.
|
---|
561 | Specify one of the four predefined message types by setting the
|
---|
562 | \l{QMessageBox::icon}{icon} property to one of the
|
---|
563 | \l{QMessageBox::Icon}{predefined icons}. The following rules are
|
---|
564 | guidelines:
|
---|
565 |
|
---|
566 | \table
|
---|
567 | \row
|
---|
568 | \o \img qmessagebox-quest.png
|
---|
569 | \o \l Question
|
---|
570 | \o For asking a question during normal operations.
|
---|
571 | \row
|
---|
572 | \o \img qmessagebox-info.png
|
---|
573 | \o \l Information
|
---|
574 | \o For reporting information about normal operations.
|
---|
575 | \row
|
---|
576 | \o \img qmessagebox-warn.png
|
---|
577 | \o \l Warning
|
---|
578 | \o For reporting non-critical errors.
|
---|
579 | \row
|
---|
580 | \o \img qmessagebox-crit.png
|
---|
581 | \o \l Critical
|
---|
582 | \o For reporting critical errors.
|
---|
583 | \endtable
|
---|
584 |
|
---|
585 | \l{QMessageBox::Icon}{Predefined icons} are not defined by QMessageBox, but
|
---|
586 | provided by the style. The default value is \l{QMessageBox::NoIcon}
|
---|
587 | {No Icon}. The message boxes are otherwise the same for all cases. When
|
---|
588 | using a standard icon, use the one recommended in the table, or use the
|
---|
589 | one recommended by the style guidelines for your platform. If none of the
|
---|
590 | standard icons is right for your message box, you can use a custom icon by
|
---|
591 | setting the \l{QMessageBox::iconPixmap}{icon pixmap} property instead of
|
---|
592 | setting the \l{QMessageBox::icon}{icon} property.
|
---|
593 |
|
---|
594 | In summary, to set an icon, use \e{either} setIcon() for one of the
|
---|
595 | standard icons, \e{or} setIconPixmap() for a custom icon.
|
---|
596 |
|
---|
597 | \section1 The Static Functions API
|
---|
598 |
|
---|
599 | Building message boxes with the static functions API, although
|
---|
600 | convenient, is less flexible than using the property-based API,
|
---|
601 | because the static function signatures lack parameters for setting
|
---|
602 | the \l{QMessageBox::informativeText} {informative text} and
|
---|
603 | \l{QMessageBox::detailedText} {detailed text} properties. One
|
---|
604 | work-around for this has been to use the \c{title} parameter as
|
---|
605 | the message box main text and the \c{text} parameter as the
|
---|
606 | message box informative text. Because this has the obvious
|
---|
607 | drawback of making a less readable message box, platform
|
---|
608 | guidelines do not recommend it. The \e{Microsoft Windows User
|
---|
609 | Interface Guidelines} recommend using the
|
---|
610 | \l{QCoreApplication::applicationName} {application name} as the
|
---|
611 | \l{QMessageBox::setWindowTitle()} {window's title}, which means
|
---|
612 | that if you have an informative text in addition to your main
|
---|
613 | text, you must concatenate it to the \c{text} parameter.
|
---|
614 |
|
---|
615 | Note that the static function signatures have changed with respect
|
---|
616 | to their button parameters, which are now used to set the
|
---|
617 | \l{QMessageBox::standardButtons} {standard buttons} and the
|
---|
618 | \l{QMessageBox::defaultButton()} {default button}.
|
---|
619 |
|
---|
620 | Static functions are available for creating information(),
|
---|
621 | question(), warning(), and critical() message boxes.
|
---|
622 |
|
---|
623 | \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 0
|
---|
624 |
|
---|
625 | The \l{dialogs/standarddialogs}{Standard Dialogs} example shows
|
---|
626 | how to use QMessageBox and the other built-in Qt dialogs.
|
---|
627 |
|
---|
628 | \section1 Advanced Usage
|
---|
629 |
|
---|
630 | If the \l{QMessageBox::StandardButtons} {standard buttons} are not
|
---|
631 | flexible enough for your message box, you can use the addButton()
|
---|
632 | overload that takes a text and a ButtonRoleto to add custom
|
---|
633 | buttons. The ButtonRole is used by QMessageBox to determine the
|
---|
634 | ordering of the buttons on screen (which varies according to the
|
---|
635 | platform). You can test the value of clickedButton() after calling
|
---|
636 | exec(). For example,
|
---|
637 |
|
---|
638 | \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 2
|
---|
639 |
|
---|
640 | \section1 Default and Escape Keys
|
---|
641 |
|
---|
642 | The default button (i.e., the button activated when \key Enter is
|
---|
643 | pressed) can be specified using setDefaultButton(). If a default
|
---|
644 | button is not specified, QMessageBox tries to find one based on
|
---|
645 | the \l{ButtonRole} {button roles} of the buttons used in the
|
---|
646 | message box.
|
---|
647 |
|
---|
648 | The escape button (the button activated when \key Esc is pressed)
|
---|
649 | can be specified using setEscapeButton(). If an escape button is
|
---|
650 | not specified, QMessageBox tries to find one using these rules:
|
---|
651 |
|
---|
652 | \list 1
|
---|
653 |
|
---|
654 | \o If there is only one button, it is the button activated when
|
---|
655 | \key Esc is pressed.
|
---|
656 |
|
---|
657 | \o If there is a \l Cancel button, it is the button activated when
|
---|
658 | \key Esc is pressed.
|
---|
659 |
|
---|
660 | \o If there is exactly one button having either
|
---|
661 | \l{QMessageBox::RejectRole} {the Reject role} or the
|
---|
662 | \l{QMessageBox::NoRole} {the No role}, it is the button
|
---|
663 | activated when \key Esc is pressed.
|
---|
664 |
|
---|
665 | \endlist
|
---|
666 |
|
---|
667 | When an escape button can't be determined using these rules,
|
---|
668 | pressing \key Esc has no effect.
|
---|
669 |
|
---|
670 | \sa QDialogButtonBox, {fowler}{GUI Design Handbook: Message Box}, {Standard Dialogs Example}, {Application Example}
|
---|
671 | */
|
---|
672 |
|
---|
673 | /*!
|
---|
674 | \enum QMessageBox::StandardButton
|
---|
675 | \since 4.2
|
---|
676 |
|
---|
677 | These enums describe flags for standard buttons. Each button has a
|
---|
678 | defined \l ButtonRole.
|
---|
679 |
|
---|
680 | \value Ok An "OK" button defined with the \l AcceptRole.
|
---|
681 | \value Open A "Open" button defined with the \l AcceptRole.
|
---|
682 | \value Save A "Save" button defined with the \l AcceptRole.
|
---|
683 | \value Cancel A "Cancel" button defined with the \l RejectRole.
|
---|
684 | \value Close A "Close" button defined with the \l RejectRole.
|
---|
685 | \value Discard A "Discard" or "Don't Save" button, depending on the platform,
|
---|
686 | defined with the \l DestructiveRole.
|
---|
687 | \value Apply An "Apply" button defined with the \l ApplyRole.
|
---|
688 | \value Reset A "Reset" button defined with the \l ResetRole.
|
---|
689 | \value RestoreDefaults A "Restore Defaults" button defined with the \l ResetRole.
|
---|
690 | \value Help A "Help" button defined with the \l HelpRole.
|
---|
691 | \value SaveAll A "Save All" button defined with the \l AcceptRole.
|
---|
692 | \value Yes A "Yes" button defined with the \l YesRole.
|
---|
693 | \value YesToAll A "Yes to All" button defined with the \l YesRole.
|
---|
694 | \value No A "No" button defined with the \l NoRole.
|
---|
695 | \value NoToAll A "No to All" button defined with the \l NoRole.
|
---|
696 | \value Abort An "Abort" button defined with the \l RejectRole.
|
---|
697 | \value Retry A "Retry" button defined with the \l AcceptRole.
|
---|
698 | \value Ignore An "Ignore" button defined with the \l AcceptRole.
|
---|
699 |
|
---|
700 | \value NoButton An invalid button.
|
---|
701 |
|
---|
702 | \omitvalue FirstButton
|
---|
703 | \omitvalue LastButton
|
---|
704 |
|
---|
705 | The following values are obsolete:
|
---|
706 |
|
---|
707 | \value YesAll Use YesToAll instead.
|
---|
708 | \value NoAll Use NoToAll instead.
|
---|
709 | \value Default Use the \c defaultButton argument of
|
---|
710 | information(), warning(), etc. instead, or call
|
---|
711 | setDefaultButton().
|
---|
712 | \value Escape Call setEscapeButton() instead.
|
---|
713 | \value FlagMask
|
---|
714 | \value ButtonMask
|
---|
715 |
|
---|
716 | \sa ButtonRole, standardButtons
|
---|
717 | */
|
---|
718 |
|
---|
719 | /*!
|
---|
720 | \fn void QMessageBox::buttonClicked(QAbstractButton *button)
|
---|
721 |
|
---|
722 | This signal is emitted whenever a button is clicked inside the QMessageBox.
|
---|
723 | The button that was clicked in returned in \a button.
|
---|
724 | */
|
---|
725 |
|
---|
726 | /*!
|
---|
727 | Constructs a message box with no text and no buttons. \a parent is
|
---|
728 | passed to the QDialog constructor.
|
---|
729 |
|
---|
730 | On Mac OS X, if you want your message box to appear
|
---|
731 | as a Qt::Sheet of its \a parent, set the message box's
|
---|
732 | \l{setWindowModality()} {window modality} to Qt::WindowModal or use open().
|
---|
733 | Otherwise, the message box will be a standard dialog.
|
---|
734 |
|
---|
735 | */
|
---|
736 | QMessageBox::QMessageBox(QWidget *parent)
|
---|
737 | : QDialog(*new QMessageBoxPrivate, parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
|
---|
738 | {
|
---|
739 | Q_D(QMessageBox);
|
---|
740 | d->init();
|
---|
741 | }
|
---|
742 |
|
---|
743 | /*!
|
---|
744 | Constructs a message box with the given \a icon, \a title, \a
|
---|
745 | text, and standard \a buttons. Standard or custom buttons can be
|
---|
746 | added at any time using addButton(). The \a parent and \a f
|
---|
747 | arguments are passed to the QDialog constructor.
|
---|
748 |
|
---|
749 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
750 | {application modal} dialog box. If \a parent is a widget, the
|
---|
751 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
752 | parent.
|
---|
753 |
|
---|
754 | On Mac OS X, if \a parent is not 0 and you want your message box
|
---|
755 | to appear as a Qt::Sheet of that parent, set the message box's
|
---|
756 | \l{setWindowModality()} {window modality} to Qt::WindowModal
|
---|
757 | (default). Otherwise, the message box will be a standard dialog.
|
---|
758 |
|
---|
759 | \sa setWindowTitle(), setText(), setIcon(), setStandardButtons()
|
---|
760 | */
|
---|
761 | QMessageBox::QMessageBox(Icon icon, const QString &title, const QString &text,
|
---|
762 | StandardButtons buttons, QWidget *parent,
|
---|
763 | Qt::WindowFlags f)
|
---|
764 | : QDialog(*new QMessageBoxPrivate, parent, f | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
|
---|
765 | {
|
---|
766 | Q_D(QMessageBox);
|
---|
767 | d->init(title, text);
|
---|
768 | setIcon(icon);
|
---|
769 | if (buttons != NoButton)
|
---|
770 | setStandardButtons(buttons);
|
---|
771 | }
|
---|
772 |
|
---|
773 | /*!
|
---|
774 | Destroys the message box.
|
---|
775 | */
|
---|
776 | QMessageBox::~QMessageBox()
|
---|
777 | {
|
---|
778 | }
|
---|
779 |
|
---|
780 | /*!
|
---|
781 | \since 4.2
|
---|
782 |
|
---|
783 | Adds the given \a button to the message box with the specified \a
|
---|
784 | role.
|
---|
785 |
|
---|
786 | \sa removeButton(), button(), setStandardButtons()
|
---|
787 | */
|
---|
788 | void QMessageBox::addButton(QAbstractButton *button, ButtonRole role)
|
---|
789 | {
|
---|
790 | Q_D(QMessageBox);
|
---|
791 | if (!button)
|
---|
792 | return;
|
---|
793 | removeButton(button);
|
---|
794 | d->buttonBox->addButton(button, (QDialogButtonBox::ButtonRole)role);
|
---|
795 | d->customButtonList.append(button);
|
---|
796 | d->autoAddOkButton = false;
|
---|
797 | }
|
---|
798 |
|
---|
799 | /*!
|
---|
800 | \since 4.2
|
---|
801 | \overload
|
---|
802 |
|
---|
803 | Creates a button with the given \a text, adds it to the message box for the
|
---|
804 | specified \a role, and returns it.
|
---|
805 | */
|
---|
806 | QPushButton *QMessageBox::addButton(const QString& text, ButtonRole role)
|
---|
807 | {
|
---|
808 | Q_D(QMessageBox);
|
---|
809 | QPushButton *pushButton = new QPushButton(text);
|
---|
810 | addButton(pushButton, role);
|
---|
811 | d->updateSize();
|
---|
812 | return pushButton;
|
---|
813 | }
|
---|
814 |
|
---|
815 | /*!
|
---|
816 | \since 4.2
|
---|
817 | \overload
|
---|
818 |
|
---|
819 | Adds a standard \a button to the message box if it is valid to do so, and
|
---|
820 | returns the push button.
|
---|
821 |
|
---|
822 | \sa setStandardButtons()
|
---|
823 | */
|
---|
824 | QPushButton *QMessageBox::addButton(StandardButton button)
|
---|
825 | {
|
---|
826 | Q_D(QMessageBox);
|
---|
827 | QPushButton *pushButton = d->buttonBox->addButton((QDialogButtonBox::StandardButton)button);
|
---|
828 | if (pushButton)
|
---|
829 | d->autoAddOkButton = false;
|
---|
830 | return pushButton;
|
---|
831 | }
|
---|
832 |
|
---|
833 | /*!
|
---|
834 | \since 4.2
|
---|
835 |
|
---|
836 | Removes \a button from the button box without deleting it.
|
---|
837 |
|
---|
838 | \sa addButton(), setStandardButtons()
|
---|
839 | */
|
---|
840 | void QMessageBox::removeButton(QAbstractButton *button)
|
---|
841 | {
|
---|
842 | Q_D(QMessageBox);
|
---|
843 | d->customButtonList.removeAll(button);
|
---|
844 | if (d->escapeButton == button)
|
---|
845 | d->escapeButton = 0;
|
---|
846 | if (d->defaultButton == button)
|
---|
847 | d->defaultButton = 0;
|
---|
848 | d->buttonBox->removeButton(button);
|
---|
849 | d->updateSize();
|
---|
850 | }
|
---|
851 |
|
---|
852 | /*!
|
---|
853 | \property QMessageBox::standardButtons
|
---|
854 | \brief collection of standard buttons in the message box
|
---|
855 | \since 4.2
|
---|
856 |
|
---|
857 | This property controls which standard buttons are used by the message box.
|
---|
858 |
|
---|
859 | By default, this property contains no standard buttons.
|
---|
860 |
|
---|
861 | \sa addButton()
|
---|
862 | */
|
---|
863 | void QMessageBox::setStandardButtons(StandardButtons buttons)
|
---|
864 | {
|
---|
865 | Q_D(QMessageBox);
|
---|
866 | d->buttonBox->setStandardButtons(QDialogButtonBox::StandardButtons(int(buttons)));
|
---|
867 |
|
---|
868 | QList<QAbstractButton *> buttonList = d->buttonBox->buttons();
|
---|
869 | if (!buttonList.contains(d->escapeButton))
|
---|
870 | d->escapeButton = 0;
|
---|
871 | if (!buttonList.contains(d->defaultButton))
|
---|
872 | d->defaultButton = 0;
|
---|
873 | d->autoAddOkButton = false;
|
---|
874 | d->updateSize();
|
---|
875 | }
|
---|
876 |
|
---|
877 | QMessageBox::StandardButtons QMessageBox::standardButtons() const
|
---|
878 | {
|
---|
879 | Q_D(const QMessageBox);
|
---|
880 | return QMessageBox::StandardButtons(int(d->buttonBox->standardButtons()));
|
---|
881 | }
|
---|
882 |
|
---|
883 | /*!
|
---|
884 | \since 4.2
|
---|
885 |
|
---|
886 | Returns the standard button enum value corresponding to the given \a button,
|
---|
887 | or NoButton if the given \a button isn't a standard button.
|
---|
888 |
|
---|
889 | \sa button(), standardButtons()
|
---|
890 | */
|
---|
891 | QMessageBox::StandardButton QMessageBox::standardButton(QAbstractButton *button) const
|
---|
892 | {
|
---|
893 | Q_D(const QMessageBox);
|
---|
894 | return (QMessageBox::StandardButton)d->buttonBox->standardButton(button);
|
---|
895 | }
|
---|
896 |
|
---|
897 | /*!
|
---|
898 | \since 4.2
|
---|
899 |
|
---|
900 | Returns a pointer corresponding to the standard button \a which,
|
---|
901 | or 0 if the standard button doesn't exist in this message box.
|
---|
902 |
|
---|
903 | \sa standardButtons, standardButton()
|
---|
904 | */
|
---|
905 | QAbstractButton *QMessageBox::button(StandardButton which) const
|
---|
906 | {
|
---|
907 | Q_D(const QMessageBox);
|
---|
908 | return d->buttonBox->button(QDialogButtonBox::StandardButton(which));
|
---|
909 | }
|
---|
910 |
|
---|
911 | /*!
|
---|
912 | \since 4.2
|
---|
913 |
|
---|
914 | Returns the button that is activated when escape is pressed.
|
---|
915 |
|
---|
916 | By default, QMessageBox attempts to automatically detect an
|
---|
917 | escape button as follows:
|
---|
918 |
|
---|
919 | \list 1
|
---|
920 | \o If there is only one button, it is made the escape button.
|
---|
921 | \o If there is a \l Cancel button, it is made the escape button.
|
---|
922 | \o On Mac OS X only, if there is exactly one button with the role
|
---|
923 | QMessageBox::RejectRole, it is made the escape button.
|
---|
924 | \endlist
|
---|
925 |
|
---|
926 | When an escape button could not be automatically detected, pressing
|
---|
927 | \key Esc has no effect.
|
---|
928 |
|
---|
929 | \sa addButton()
|
---|
930 | */
|
---|
931 | QAbstractButton *QMessageBox::escapeButton() const
|
---|
932 | {
|
---|
933 | Q_D(const QMessageBox);
|
---|
934 | return d->escapeButton;
|
---|
935 | }
|
---|
936 |
|
---|
937 | /*!
|
---|
938 | \since 4.2
|
---|
939 |
|
---|
940 | Sets the button that gets activated when the \key Escape key is
|
---|
941 | pressed to \a button.
|
---|
942 |
|
---|
943 | \sa addButton(), clickedButton()
|
---|
944 | */
|
---|
945 | void QMessageBox::setEscapeButton(QAbstractButton *button)
|
---|
946 | {
|
---|
947 | Q_D(QMessageBox);
|
---|
948 | if (d->buttonBox->buttons().contains(button))
|
---|
949 | d->escapeButton = button;
|
---|
950 | }
|
---|
951 |
|
---|
952 | /*!
|
---|
953 | \since 4.3
|
---|
954 |
|
---|
955 | Sets the buttons that gets activated when the \key Escape key is
|
---|
956 | pressed to \a button.
|
---|
957 |
|
---|
958 | \sa addButton(), clickedButton()
|
---|
959 | */
|
---|
960 | void QMessageBox::setEscapeButton(QMessageBox::StandardButton button)
|
---|
961 | {
|
---|
962 | Q_D(QMessageBox);
|
---|
963 | setEscapeButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));
|
---|
964 | }
|
---|
965 |
|
---|
966 | void QMessageBoxPrivate::detectEscapeButton()
|
---|
967 | {
|
---|
968 | if (escapeButton) { // escape button explicitly set
|
---|
969 | detectedEscapeButton = escapeButton;
|
---|
970 | return;
|
---|
971 | }
|
---|
972 |
|
---|
973 | // Cancel button automatically becomes escape button
|
---|
974 | detectedEscapeButton = buttonBox->button(QDialogButtonBox::Cancel);
|
---|
975 | if (detectedEscapeButton)
|
---|
976 | return;
|
---|
977 |
|
---|
978 | // If there is only one button, make it the escape button
|
---|
979 | const QList<QAbstractButton *> buttons = buttonBox->buttons();
|
---|
980 | if (buttons.count() == 1) {
|
---|
981 | detectedEscapeButton = buttons.first();
|
---|
982 | return;
|
---|
983 | }
|
---|
984 |
|
---|
985 | // if the message box has one RejectRole button, make it the escape button
|
---|
986 | for (int i = 0; i < buttons.count(); i++) {
|
---|
987 | if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::RejectRole) {
|
---|
988 | if (detectedEscapeButton) { // already detected!
|
---|
989 | detectedEscapeButton = 0;
|
---|
990 | break;
|
---|
991 | }
|
---|
992 | detectedEscapeButton = buttons.at(i);
|
---|
993 | }
|
---|
994 | }
|
---|
995 | if (detectedEscapeButton)
|
---|
996 | return;
|
---|
997 |
|
---|
998 | // if the message box has one NoRole button, make it the escape button
|
---|
999 | for (int i = 0; i < buttons.count(); i++) {
|
---|
1000 | if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::NoRole) {
|
---|
1001 | if (detectedEscapeButton) { // already detected!
|
---|
1002 | detectedEscapeButton = 0;
|
---|
1003 | break;
|
---|
1004 | }
|
---|
1005 | detectedEscapeButton = buttons.at(i);
|
---|
1006 | }
|
---|
1007 | }
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | /*!
|
---|
1011 | \since 4.2
|
---|
1012 |
|
---|
1013 | Returns the button that was clicked by the user,
|
---|
1014 | or 0 if the user hit the \key Esc key and
|
---|
1015 | no \l{setEscapeButton()}{escape button} was set.
|
---|
1016 |
|
---|
1017 | If exec() hasn't been called yet, returns 0.
|
---|
1018 |
|
---|
1019 | Example:
|
---|
1020 |
|
---|
1021 | \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 3
|
---|
1022 |
|
---|
1023 | \sa standardButton(), button()
|
---|
1024 | */
|
---|
1025 | QAbstractButton *QMessageBox::clickedButton() const
|
---|
1026 | {
|
---|
1027 | Q_D(const QMessageBox);
|
---|
1028 | return d->clickedButton;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | /*!
|
---|
1032 | \since 4.2
|
---|
1033 |
|
---|
1034 | Returns the button that should be the message box's
|
---|
1035 | \l{QPushButton::setDefault()}{default button}. Returns 0
|
---|
1036 | if no default button was set.
|
---|
1037 |
|
---|
1038 | \sa addButton(), QPushButton::setDefault()
|
---|
1039 | */
|
---|
1040 | QPushButton *QMessageBox::defaultButton() const
|
---|
1041 | {
|
---|
1042 | Q_D(const QMessageBox);
|
---|
1043 | return d->defaultButton;
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | /*!
|
---|
1047 | \since 4.2
|
---|
1048 |
|
---|
1049 | Sets the message box's \l{QPushButton::setDefault()}{default button}
|
---|
1050 | to \a button.
|
---|
1051 |
|
---|
1052 | \sa addButton(), QPushButton::setDefault()
|
---|
1053 | */
|
---|
1054 | void QMessageBox::setDefaultButton(QPushButton *button)
|
---|
1055 | {
|
---|
1056 | Q_D(QMessageBox);
|
---|
1057 | if (!d->buttonBox->buttons().contains(button))
|
---|
1058 | return;
|
---|
1059 | d->defaultButton = button;
|
---|
1060 | button->setDefault(true);
|
---|
1061 | button->setFocus();
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | /*!
|
---|
1065 | \since 4.3
|
---|
1066 |
|
---|
1067 | Sets the message box's \l{QPushButton::setDefault()}{default button}
|
---|
1068 | to \a button.
|
---|
1069 |
|
---|
1070 | \sa addButton(), QPushButton::setDefault()
|
---|
1071 | */
|
---|
1072 | void QMessageBox::setDefaultButton(QMessageBox::StandardButton button)
|
---|
1073 | {
|
---|
1074 | Q_D(QMessageBox);
|
---|
1075 | setDefaultButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | /*!
|
---|
1079 | \property QMessageBox::text
|
---|
1080 | \brief the message box text to be displayed.
|
---|
1081 |
|
---|
1082 | The text will be interpreted either as a plain text or as rich text,
|
---|
1083 | depending on the text format setting (\l QMessageBox::textFormat).
|
---|
1084 | The default setting is Qt::AutoText, i.e., the message box will try
|
---|
1085 | to auto-detect the format of the text.
|
---|
1086 |
|
---|
1087 | The default value of this property is an empty string.
|
---|
1088 |
|
---|
1089 | \sa textFormat, QMessageBox::informativeText, QMessageBox::detailedText
|
---|
1090 | */
|
---|
1091 | QString QMessageBox::text() const
|
---|
1092 | {
|
---|
1093 | Q_D(const QMessageBox);
|
---|
1094 | return d->label->text();
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | void QMessageBox::setText(const QString &text)
|
---|
1098 | {
|
---|
1099 | Q_D(QMessageBox);
|
---|
1100 | d->label->setText(text);
|
---|
1101 | d->label->setWordWrap(d->label->textFormat() == Qt::RichText
|
---|
1102 | || (d->label->textFormat() == Qt::AutoText && Qt::mightBeRichText(text)));
|
---|
1103 | d->updateSize();
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | /*!
|
---|
1107 | \enum QMessageBox::Icon
|
---|
1108 |
|
---|
1109 | This enum has the following values:
|
---|
1110 |
|
---|
1111 | \value NoIcon the message box does not have any icon.
|
---|
1112 |
|
---|
1113 | \value Question an icon indicating that
|
---|
1114 | the message is asking a question.
|
---|
1115 |
|
---|
1116 | \value Information an icon indicating that
|
---|
1117 | the message is nothing out of the ordinary.
|
---|
1118 |
|
---|
1119 | \value Warning an icon indicating that the
|
---|
1120 | message is a warning, but can be dealt with.
|
---|
1121 |
|
---|
1122 | \value Critical an icon indicating that
|
---|
1123 | the message represents a critical problem.
|
---|
1124 |
|
---|
1125 | */
|
---|
1126 |
|
---|
1127 | /*!
|
---|
1128 | \property QMessageBox::icon
|
---|
1129 | \brief the message box's icon
|
---|
1130 |
|
---|
1131 | The icon of the message box can be specified with one of the
|
---|
1132 | values:
|
---|
1133 |
|
---|
1134 | \list
|
---|
1135 | \o QMessageBox::NoIcon
|
---|
1136 | \o QMessageBox::Question
|
---|
1137 | \o QMessageBox::Information
|
---|
1138 | \o QMessageBox::Warning
|
---|
1139 | \o QMessageBox::Critical
|
---|
1140 | \endlist
|
---|
1141 |
|
---|
1142 | The default is QMessageBox::NoIcon.
|
---|
1143 |
|
---|
1144 | The pixmap used to display the actual icon depends on the current
|
---|
1145 | \l{QWidget::style()} {GUI style}. You can also set a custom pixmap
|
---|
1146 | for the icon by setting the \l{QMessageBox::iconPixmap} {icon
|
---|
1147 | pixmap} property.
|
---|
1148 |
|
---|
1149 | \sa iconPixmap
|
---|
1150 | */
|
---|
1151 | QMessageBox::Icon QMessageBox::icon() const
|
---|
1152 | {
|
---|
1153 | Q_D(const QMessageBox);
|
---|
1154 | return d->icon;
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | void QMessageBox::setIcon(Icon icon)
|
---|
1158 | {
|
---|
1159 | Q_D(QMessageBox);
|
---|
1160 | setIconPixmap(QMessageBoxPrivate::standardIcon((QMessageBox::Icon)icon,
|
---|
1161 | this));
|
---|
1162 | d->icon = icon;
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | /*!
|
---|
1166 | \property QMessageBox::iconPixmap
|
---|
1167 | \brief the current icon
|
---|
1168 |
|
---|
1169 | The icon currently used by the message box. Note that it's often
|
---|
1170 | hard to draw one pixmap that looks appropriate in all GUI styles;
|
---|
1171 | you may want to supply a different pixmap for each platform.
|
---|
1172 |
|
---|
1173 | By default, this property is undefined.
|
---|
1174 |
|
---|
1175 | \sa icon
|
---|
1176 | */
|
---|
1177 | QPixmap QMessageBox::iconPixmap() const
|
---|
1178 | {
|
---|
1179 | Q_D(const QMessageBox);
|
---|
1180 | if (d->iconLabel && d->iconLabel->pixmap())
|
---|
1181 | return *d->iconLabel->pixmap();
|
---|
1182 | return QPixmap();
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | void QMessageBox::setIconPixmap(const QPixmap &pixmap)
|
---|
1186 | {
|
---|
1187 | Q_D(QMessageBox);
|
---|
1188 | d->iconLabel->setPixmap(pixmap);
|
---|
1189 | d->updateSize();
|
---|
1190 | d->icon = NoIcon;
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | /*!
|
---|
1194 | \property QMessageBox::textFormat
|
---|
1195 | \brief the format of the text displayed by the message box
|
---|
1196 |
|
---|
1197 | The current text format used by the message box. See the \l
|
---|
1198 | Qt::TextFormat enum for an explanation of the possible options.
|
---|
1199 |
|
---|
1200 | The default format is Qt::AutoText.
|
---|
1201 |
|
---|
1202 | \sa setText()
|
---|
1203 | */
|
---|
1204 | Qt::TextFormat QMessageBox::textFormat() const
|
---|
1205 | {
|
---|
1206 | Q_D(const QMessageBox);
|
---|
1207 | return d->label->textFormat();
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | void QMessageBox::setTextFormat(Qt::TextFormat format)
|
---|
1211 | {
|
---|
1212 | Q_D(QMessageBox);
|
---|
1213 | d->label->setTextFormat(format);
|
---|
1214 | d->label->setWordWrap(format == Qt::RichText
|
---|
1215 | || (format == Qt::AutoText && Qt::mightBeRichText(d->label->text())));
|
---|
1216 | d->updateSize();
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | /*!
|
---|
1220 | \reimp
|
---|
1221 | */
|
---|
1222 | bool QMessageBox::event(QEvent *e)
|
---|
1223 | {
|
---|
1224 | bool result =QDialog::event(e);
|
---|
1225 | switch (e->type()) {
|
---|
1226 | case QEvent::LayoutRequest:
|
---|
1227 | d_func()->updateSize();
|
---|
1228 | break;
|
---|
1229 | case QEvent::LanguageChange:
|
---|
1230 | d_func()->retranslateStrings();
|
---|
1231 | break;
|
---|
1232 | #ifdef Q_WS_WINCE
|
---|
1233 | case QEvent::OkRequest:
|
---|
1234 | case QEvent::HelpRequest: {
|
---|
1235 | QString bName =
|
---|
1236 | (e->type() == QEvent::OkRequest)
|
---|
1237 | ? QApplication::translate("QMessageBox", "OK")
|
---|
1238 | : QApplication::translate("QMessageBox", "Help");
|
---|
1239 | QList<QPushButton*> list = qFindChildren<QPushButton*>(this);
|
---|
1240 | for (int i=0; i<list.size(); ++i) {
|
---|
1241 | QPushButton *pb = list.at(i);
|
---|
1242 | if (pb->text() == bName) {
|
---|
1243 | if (pb->isEnabled())
|
---|
1244 | pb->click();
|
---|
1245 | return pb->isEnabled();
|
---|
1246 | }
|
---|
1247 | }
|
---|
1248 | }
|
---|
1249 | #endif
|
---|
1250 | default:
|
---|
1251 | break;
|
---|
1252 | }
|
---|
1253 | return result;
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | /*!
|
---|
1257 | \reimp
|
---|
1258 | */
|
---|
1259 | void QMessageBox::resizeEvent(QResizeEvent *event)
|
---|
1260 | {
|
---|
1261 | QDialog::resizeEvent(event);
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | /*!
|
---|
1265 | \reimp
|
---|
1266 | */
|
---|
1267 | void QMessageBox::closeEvent(QCloseEvent *e)
|
---|
1268 | {
|
---|
1269 | Q_D(QMessageBox);
|
---|
1270 | if (!d->detectedEscapeButton) {
|
---|
1271 | e->ignore();
|
---|
1272 | return;
|
---|
1273 | }
|
---|
1274 | QDialog::closeEvent(e);
|
---|
1275 | d->clickedButton = d->detectedEscapeButton;
|
---|
1276 | setResult(d->execReturnCode(d->detectedEscapeButton));
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | /*!
|
---|
1280 | \reimp
|
---|
1281 | */
|
---|
1282 | void QMessageBox::changeEvent(QEvent *ev)
|
---|
1283 | {
|
---|
1284 | Q_D(QMessageBox);
|
---|
1285 | switch (ev->type()) {
|
---|
1286 | case QEvent::StyleChange:
|
---|
1287 | {
|
---|
1288 | if (d->icon != NoIcon)
|
---|
1289 | setIcon(d->icon);
|
---|
1290 | Qt::TextInteractionFlags flags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this));
|
---|
1291 | d->label->setTextInteractionFlags(flags);
|
---|
1292 | d->buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this));
|
---|
1293 | if (d->informativeLabel)
|
---|
1294 | d->informativeLabel->setTextInteractionFlags(flags);
|
---|
1295 | // intentional fall through
|
---|
1296 | }
|
---|
1297 | case QEvent::FontChange:
|
---|
1298 | case QEvent::ApplicationFontChange:
|
---|
1299 | #ifdef Q_WS_MAC
|
---|
1300 | {
|
---|
1301 | QFont f = font();
|
---|
1302 | f.setBold(true);
|
---|
1303 | d->label->setFont(f);
|
---|
1304 | }
|
---|
1305 | #endif
|
---|
1306 | default:
|
---|
1307 | break;
|
---|
1308 | }
|
---|
1309 | QDialog::changeEvent(ev);
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | /*!
|
---|
1313 | \reimp
|
---|
1314 | */
|
---|
1315 | void QMessageBox::keyPressEvent(QKeyEvent *e)
|
---|
1316 | {
|
---|
1317 | Q_D(QMessageBox);
|
---|
1318 | if (e->key() == Qt::Key_Escape
|
---|
1319 | #ifdef Q_WS_MAC
|
---|
1320 | || (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period)
|
---|
1321 | #endif
|
---|
1322 | ) {
|
---|
1323 | if (d->detectedEscapeButton) {
|
---|
1324 | #ifdef Q_WS_MAC
|
---|
1325 | d->detectedEscapeButton->animateClick();
|
---|
1326 | #else
|
---|
1327 | d->detectedEscapeButton->click();
|
---|
1328 | #endif
|
---|
1329 | }
|
---|
1330 | return;
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | #if defined (Q_OS_WIN) && !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT)
|
---|
1334 | if (e == QKeySequence::Copy) {
|
---|
1335 | QString separator = QString::fromLatin1("---------------------------\n");
|
---|
1336 | QString textToCopy = separator;
|
---|
1337 | separator.prepend(QLatin1Char('\n'));
|
---|
1338 | textToCopy += windowTitle() + separator; // title
|
---|
1339 | textToCopy += d->label->text() + separator; // text
|
---|
1340 |
|
---|
1341 | if (d->informativeLabel)
|
---|
1342 | textToCopy += d->informativeLabel->text() + separator;
|
---|
1343 |
|
---|
1344 | QString buttonTexts;
|
---|
1345 | QList<QAbstractButton *> buttons = d->buttonBox->buttons();
|
---|
1346 | for (int i = 0; i < buttons.count(); i++) {
|
---|
1347 | buttonTexts += buttons[i]->text() + QLatin1String(" ");
|
---|
1348 | }
|
---|
1349 | textToCopy += buttonTexts + separator;
|
---|
1350 |
|
---|
1351 | QApplication::clipboard()->setText(textToCopy);
|
---|
1352 | return;
|
---|
1353 | }
|
---|
1354 | #endif //QT_NO_SHORTCUT QT_NO_CLIPBOARD Q_OS_WIN
|
---|
1355 |
|
---|
1356 | #ifndef QT_NO_SHORTCUT
|
---|
1357 | if (!(e->modifiers() & Qt::AltModifier)) {
|
---|
1358 | int key = e->key() & ~((int)Qt::MODIFIER_MASK|(int)Qt::UNICODE_ACCEL);
|
---|
1359 | if (key) {
|
---|
1360 | const QList<QAbstractButton *> buttons = d->buttonBox->buttons();
|
---|
1361 | for (int i = 0; i < buttons.count(); ++i) {
|
---|
1362 | QAbstractButton *pb = buttons.at(i);
|
---|
1363 | int acc = pb->shortcut() & ~((int)Qt::MODIFIER_MASK|(int)Qt::UNICODE_ACCEL);
|
---|
1364 | if (acc == key) {
|
---|
1365 | pb->animateClick();
|
---|
1366 | return;
|
---|
1367 | }
|
---|
1368 | }
|
---|
1369 | }
|
---|
1370 | }
|
---|
1371 | #endif
|
---|
1372 | QDialog::keyPressEvent(e);
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 | #ifdef Q_WS_WINCE
|
---|
1376 | /*!
|
---|
1377 | \reimp
|
---|
1378 | */
|
---|
1379 | void QMessageBox::setVisible(bool visible)
|
---|
1380 | {
|
---|
1381 | Q_D(QMessageBox);
|
---|
1382 | if (visible)
|
---|
1383 | d->hideSpecial();
|
---|
1384 | QDialog::setVisible(visible);
|
---|
1385 | }
|
---|
1386 | #endif
|
---|
1387 |
|
---|
1388 |
|
---|
1389 | /*!
|
---|
1390 | \overload
|
---|
1391 |
|
---|
1392 | Opens the dialog and connects its finished() or buttonClicked() signal to
|
---|
1393 | the slot specified by \a receiver and \a member. If the slot in \a member
|
---|
1394 | has a pointer for its first parameter the connection is to buttonClicked(),
|
---|
1395 | otherwise the connection is to finished().
|
---|
1396 |
|
---|
1397 | The signal will be disconnected from the slot when the dialog is closed.
|
---|
1398 | */
|
---|
1399 | void QMessageBox::open(QObject *receiver, const char *member)
|
---|
1400 | {
|
---|
1401 | Q_D(QMessageBox);
|
---|
1402 | const char *signal = member && strchr(member, '*') ? SIGNAL(buttonClicked(QAbstractButton*))
|
---|
1403 | : SIGNAL(finished(int));
|
---|
1404 | connect(this, signal, receiver, member);
|
---|
1405 | d->signalToDisconnectOnClose = signal;
|
---|
1406 | d->receiverToDisconnectOnClose = receiver;
|
---|
1407 | d->memberToDisconnectOnClose = member;
|
---|
1408 | QDialog::open();
|
---|
1409 | }
|
---|
1410 |
|
---|
1411 | /*!
|
---|
1412 | \since 4.5
|
---|
1413 |
|
---|
1414 | Returns a list of all the buttons that have been added to the message box.
|
---|
1415 |
|
---|
1416 | \sa buttonRole(), addButton(), removeButton()
|
---|
1417 | */
|
---|
1418 | QList<QAbstractButton *> QMessageBox::buttons() const
|
---|
1419 | {
|
---|
1420 | Q_D(const QMessageBox);
|
---|
1421 | return d->buttonBox->buttons();
|
---|
1422 | }
|
---|
1423 |
|
---|
1424 | /*!
|
---|
1425 | \since 4.5
|
---|
1426 |
|
---|
1427 | Returns the button role for the specified \a button. This function returns
|
---|
1428 | \l InvalidRole if \a button is 0 or has not been added to the message box.
|
---|
1429 |
|
---|
1430 | \sa buttons(), addButton()
|
---|
1431 | */
|
---|
1432 | QMessageBox::ButtonRole QMessageBox::buttonRole(QAbstractButton *button) const
|
---|
1433 | {
|
---|
1434 | Q_D(const QMessageBox);
|
---|
1435 | return QMessageBox::ButtonRole(d->buttonBox->buttonRole(button));
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 | /*!
|
---|
1439 | \reimp
|
---|
1440 | */
|
---|
1441 | void QMessageBox::showEvent(QShowEvent *e)
|
---|
1442 | {
|
---|
1443 | Q_D(QMessageBox);
|
---|
1444 | if (d->autoAddOkButton) {
|
---|
1445 | addButton(Ok);
|
---|
1446 | #if defined(Q_WS_WINCE)
|
---|
1447 | d->hideSpecial();
|
---|
1448 | #endif
|
---|
1449 | }
|
---|
1450 | if (d->detailsButton)
|
---|
1451 | addButton(d->detailsButton, QMessageBox::ActionRole);
|
---|
1452 | d->detectEscapeButton();
|
---|
1453 | d->updateSize();
|
---|
1454 |
|
---|
1455 | #ifndef QT_NO_ACCESSIBILITY
|
---|
1456 | QAccessible::updateAccessibility(this, 0, QAccessible::Alert);
|
---|
1457 | #endif
|
---|
1458 | #ifdef Q_WS_WIN
|
---|
1459 | HMENU systemMenu = GetSystemMenu((HWND)winId(), FALSE);
|
---|
1460 | if (!d->detectedEscapeButton) {
|
---|
1461 | EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
|
---|
1462 | }
|
---|
1463 | else {
|
---|
1464 | EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
|
---|
1465 | }
|
---|
1466 | #endif
|
---|
1467 | QDialog::showEvent(e);
|
---|
1468 | }
|
---|
1469 |
|
---|
1470 |
|
---|
1471 | static QMessageBox::StandardButton showNewMessageBox(QWidget *parent,
|
---|
1472 | QMessageBox::Icon icon,
|
---|
1473 | const QString& title, const QString& text,
|
---|
1474 | QMessageBox::StandardButtons buttons,
|
---|
1475 | QMessageBox::StandardButton defaultButton)
|
---|
1476 | {
|
---|
1477 | // necessary for source compatibility with Qt 4.0 and 4.1
|
---|
1478 | // handles (Yes, No) and (Yes|Default, No)
|
---|
1479 | if (defaultButton && !(buttons & defaultButton))
|
---|
1480 | return (QMessageBox::StandardButton)
|
---|
1481 | QMessageBoxPrivate::showOldMessageBox(parent, icon, title,
|
---|
1482 | text, int(buttons),
|
---|
1483 | int(defaultButton), 0);
|
---|
1484 |
|
---|
1485 | QMessageBox msgBox(icon, title, text, QMessageBox::NoButton, parent);
|
---|
1486 | QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&msgBox);
|
---|
1487 | Q_ASSERT(buttonBox != 0);
|
---|
1488 |
|
---|
1489 | uint mask = QMessageBox::FirstButton;
|
---|
1490 | while (mask <= QMessageBox::LastButton) {
|
---|
1491 | uint sb = buttons & mask;
|
---|
1492 | mask <<= 1;
|
---|
1493 | if (!sb)
|
---|
1494 | continue;
|
---|
1495 | QPushButton *button = msgBox.addButton((QMessageBox::StandardButton)sb);
|
---|
1496 | // Choose the first accept role as the default
|
---|
1497 | if (msgBox.defaultButton())
|
---|
1498 | continue;
|
---|
1499 | if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
---|
1500 | || (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton)))
|
---|
1501 | msgBox.setDefaultButton(button);
|
---|
1502 | }
|
---|
1503 | if (msgBox.exec() == -1)
|
---|
1504 | return QMessageBox::Cancel;
|
---|
1505 | return msgBox.standardButton(msgBox.clickedButton());
|
---|
1506 | }
|
---|
1507 |
|
---|
1508 | /*!
|
---|
1509 | \since 4.2
|
---|
1510 |
|
---|
1511 | Opens an information message box with the specified \a title and
|
---|
1512 | \a text. The standard \a buttons are added to the message box. \a
|
---|
1513 | defaultButton specifies the button used when \key Enter is
|
---|
1514 | pressed. \a defaultButton must refer to a button that was given in \a buttons.
|
---|
1515 | If \a defaultButton is QMessageBox::NoButton, QMessageBox
|
---|
1516 | chooses a suitable default automatically.
|
---|
1517 |
|
---|
1518 | Returns the identity of the standard button that was clicked. If
|
---|
1519 | \key Esc was pressed instead, the \l{Default and Escape Keys}
|
---|
1520 | {escape button} is returned.
|
---|
1521 |
|
---|
1522 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
1523 | {application modal} dialog box. If \a parent is a widget, the
|
---|
1524 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
1525 | parent.
|
---|
1526 |
|
---|
1527 | \sa question(), warning(), critical()
|
---|
1528 | */
|
---|
1529 | QMessageBox::StandardButton QMessageBox::information(QWidget *parent, const QString &title,
|
---|
1530 | const QString& text, StandardButtons buttons,
|
---|
1531 | StandardButton defaultButton)
|
---|
1532 | {
|
---|
1533 | return showNewMessageBox(parent, Information, title, text, buttons,
|
---|
1534 | defaultButton);
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 |
|
---|
1538 | /*!
|
---|
1539 | \since 4.2
|
---|
1540 |
|
---|
1541 | Opens a question message box with the specified \a title and \a
|
---|
1542 | text. The standard \a buttons are added to the message box. \a
|
---|
1543 | defaultButton specifies the button used when \key Enter is
|
---|
1544 | pressed. \a defaultButton must refer to a button that was given in \a buttons.
|
---|
1545 | If \a defaultButton is QMessageBox::NoButton, QMessageBox
|
---|
1546 | chooses a suitable default automatically.
|
---|
1547 |
|
---|
1548 | Returns the identity of the standard button that was clicked. If
|
---|
1549 | \key Esc was pressed instead, the \l{Default and Escape Keys}
|
---|
1550 | {escape button} is returned.
|
---|
1551 |
|
---|
1552 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
1553 | {application modal} dialog box. If \a parent is a widget, the
|
---|
1554 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
1555 | parent.
|
---|
1556 |
|
---|
1557 | \sa information(), warning(), critical()
|
---|
1558 | */
|
---|
1559 | QMessageBox::StandardButton QMessageBox::question(QWidget *parent, const QString &title,
|
---|
1560 | const QString& text, StandardButtons buttons,
|
---|
1561 | StandardButton defaultButton)
|
---|
1562 | {
|
---|
1563 | return showNewMessageBox(parent, Question, title, text, buttons, defaultButton);
|
---|
1564 | }
|
---|
1565 |
|
---|
1566 | /*!
|
---|
1567 | \since 4.2
|
---|
1568 |
|
---|
1569 | Opens a warning message box with the specified \a title and \a
|
---|
1570 | text. The standard \a buttons are added to the message box. \a
|
---|
1571 | defaultButton specifies the button used when \key Enter is
|
---|
1572 | pressed. \a defaultButton must refer to a button that was given in \a buttons.
|
---|
1573 | If \a defaultButton is QMessageBox::NoButton, QMessageBox
|
---|
1574 | chooses a suitable default automatically.
|
---|
1575 |
|
---|
1576 | Returns the identity of the standard button that was clicked. If
|
---|
1577 | \key Esc was pressed instead, the \l{Default and Escape Keys}
|
---|
1578 | {escape button} is returned.
|
---|
1579 |
|
---|
1580 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
1581 | {application modal} dialog box. If \a parent is a widget, the
|
---|
1582 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
1583 | parent.
|
---|
1584 |
|
---|
1585 | \sa question(), information(), critical()
|
---|
1586 | */
|
---|
1587 | QMessageBox::StandardButton QMessageBox::warning(QWidget *parent, const QString &title,
|
---|
1588 | const QString& text, StandardButtons buttons,
|
---|
1589 | StandardButton defaultButton)
|
---|
1590 | {
|
---|
1591 | return showNewMessageBox(parent, Warning, title, text, buttons, defaultButton);
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | /*!
|
---|
1595 | \since 4.2
|
---|
1596 |
|
---|
1597 | Opens a critical message box with the specified \a title and \a
|
---|
1598 | text. The standard \a buttons are added to the message box. \a
|
---|
1599 | defaultButton specifies the button used when \key Enter is
|
---|
1600 | pressed. \a defaultButton must refer to a button that was given in \a buttons.
|
---|
1601 | If \a defaultButton is QMessageBox::NoButton, QMessageBox
|
---|
1602 | chooses a suitable default automatically.
|
---|
1603 |
|
---|
1604 | Returns the identity of the standard button that was clicked. If
|
---|
1605 | \key Esc was pressed instead, the \l{Default and Escape Keys}
|
---|
1606 | {escape button} is returned.
|
---|
1607 |
|
---|
1608 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
1609 | {application modal} dialog box. If \a parent is a widget, the
|
---|
1610 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
1611 | parent.
|
---|
1612 |
|
---|
1613 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
1614 | If you want to do this, you should create the dialog
|
---|
1615 | yourself using one of the QMessageBox constructors.
|
---|
1616 |
|
---|
1617 | \sa question(), warning(), information()
|
---|
1618 | */
|
---|
1619 | QMessageBox::StandardButton QMessageBox::critical(QWidget *parent, const QString &title,
|
---|
1620 | const QString& text, StandardButtons buttons,
|
---|
1621 | StandardButton defaultButton)
|
---|
1622 | {
|
---|
1623 | return showNewMessageBox(parent, Critical, title, text, buttons, defaultButton);
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | /*!
|
---|
1627 | Displays a simple about box with title \a title and text \a
|
---|
1628 | text. The about box's parent is \a parent.
|
---|
1629 |
|
---|
1630 | about() looks for a suitable icon in four locations:
|
---|
1631 |
|
---|
1632 | \list 1
|
---|
1633 | \o It prefers \link QWidget::windowIcon() parent->icon() \endlink
|
---|
1634 | if that exists.
|
---|
1635 | \o If not, it tries the top-level widget containing \a parent.
|
---|
1636 | \o If that fails, it tries the \link
|
---|
1637 | QApplication::activeWindow() active window. \endlink
|
---|
1638 | \o As a last resort it uses the Information icon.
|
---|
1639 | \endlist
|
---|
1640 |
|
---|
1641 | The about box has a single button labelled "OK". On Mac OS X, the
|
---|
1642 | about box is popped up as a modeless window; on other platforms,
|
---|
1643 | it is currently a window modal.
|
---|
1644 |
|
---|
1645 | \sa QWidget::windowIcon(), QApplication::activeWindow()
|
---|
1646 | */
|
---|
1647 | void QMessageBox::about(QWidget *parent, const QString &title, const QString &text)
|
---|
1648 | {
|
---|
1649 | #ifdef Q_WS_MAC
|
---|
1650 | static QPointer<QMessageBox> oldMsgBox;
|
---|
1651 |
|
---|
1652 | if (oldMsgBox && oldMsgBox->text() == text) {
|
---|
1653 | oldMsgBox->show();
|
---|
1654 | oldMsgBox->raise();
|
---|
1655 | oldMsgBox->activateWindow();
|
---|
1656 | return;
|
---|
1657 | }
|
---|
1658 | #endif
|
---|
1659 |
|
---|
1660 | QMessageBox *msgBox = new QMessageBox(title, text, Information, 0, 0, 0, parent
|
---|
1661 | #ifdef Q_WS_MAC
|
---|
1662 | , Qt::WindowTitleHint | Qt::WindowSystemMenuHint
|
---|
1663 | #endif
|
---|
1664 | );
|
---|
1665 | msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
---|
1666 | QIcon icon = msgBox->windowIcon();
|
---|
1667 | QSize size = icon.actualSize(QSize(64, 64));
|
---|
1668 | msgBox->setIconPixmap(icon.pixmap(size));
|
---|
1669 |
|
---|
1670 | // should perhaps be a style hint
|
---|
1671 | #ifdef Q_WS_MAC
|
---|
1672 | oldMsgBox = msgBox;
|
---|
1673 | #if 0
|
---|
1674 | // ### doesn't work until close button is enabled in title bar
|
---|
1675 | msgBox->d_func()->autoAddOkButton = false;
|
---|
1676 | #else
|
---|
1677 | msgBox->d_func()->buttonBox->setCenterButtons(true);
|
---|
1678 | #endif
|
---|
1679 | msgBox->show();
|
---|
1680 | #else
|
---|
1681 | msgBox->exec();
|
---|
1682 | #endif
|
---|
1683 | }
|
---|
1684 |
|
---|
1685 | /*!
|
---|
1686 | Displays a simple message box about Qt, with the given \a title
|
---|
1687 | and centered over \a parent (if \a parent is not 0). The message
|
---|
1688 | includes the version number of Qt being used by the application.
|
---|
1689 |
|
---|
1690 | This is useful for inclusion in the \gui Help menu of an application,
|
---|
1691 | as shown in the \l{mainwindows/menus}{Menus} example.
|
---|
1692 |
|
---|
1693 | QApplication provides this functionality as a slot.
|
---|
1694 |
|
---|
1695 | On Mac OS X, the about box is popped up as a modeless window; on
|
---|
1696 | other platforms, it is currently window modal.
|
---|
1697 |
|
---|
1698 | \sa QApplication::aboutQt()
|
---|
1699 | */
|
---|
1700 | void QMessageBox::aboutQt(QWidget *parent, const QString &title)
|
---|
1701 | {
|
---|
1702 | #ifdef Q_WS_MAC
|
---|
1703 | static QPointer<QMessageBox> oldMsgBox;
|
---|
1704 |
|
---|
1705 | if (oldMsgBox) {
|
---|
1706 | oldMsgBox->show();
|
---|
1707 | oldMsgBox->raise();
|
---|
1708 | oldMsgBox->activateWindow();
|
---|
1709 | return;
|
---|
1710 | }
|
---|
1711 | #endif
|
---|
1712 |
|
---|
1713 | QString translatedTextAboutQtCaption;
|
---|
1714 | translatedTextAboutQtCaption = QMessageBox::tr(
|
---|
1715 | "<h3>About Qt</h3>"
|
---|
1716 | "<p>This program uses Qt version %1.</p>"
|
---|
1717 | ).arg(QLatin1String(QT_VERSION_STR));
|
---|
1718 | QString translatedTextAboutQtText;
|
---|
1719 | translatedTextAboutQtText = QMessageBox::tr(
|
---|
1720 | "<p>Qt is a C++ toolkit for cross-platform application "
|
---|
1721 | "development.</p>"
|
---|
1722 | "<p>Qt provides single-source portability across MS Windows, "
|
---|
1723 | "Mac OS X, Linux, and all major commercial Unix variants. "
|
---|
1724 | "Qt is also available for embedded devices as Qt for Embedded Linux "
|
---|
1725 | "and Qt for Windows CE.</p>"
|
---|
1726 | "<p>Qt is available under three different licensing options designed "
|
---|
1727 | "to accommodate the needs of our various users.</p>"
|
---|
1728 | "<p>Qt licensed under our commercial license agreement is appropriate "
|
---|
1729 | "for development of proprietary/commercial software where you do not "
|
---|
1730 | "want to share any source code with third parties or otherwise cannot "
|
---|
1731 | "comply with the terms of the GNU LGPL version 2.1 or GNU GPL version "
|
---|
1732 | "3.0.</p>"
|
---|
1733 | "<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the "
|
---|
1734 | "development of Qt applications (proprietary or open source) provided "
|
---|
1735 | "you can comply with the terms and conditions of the GNU LGPL version "
|
---|
1736 | "2.1.</p>"
|
---|
1737 | "<p>Qt licensed under the GNU General Public License version 3.0 is "
|
---|
1738 | "appropriate for the development of Qt applications where you wish to "
|
---|
1739 | "use such applications in combination with software subject to the "
|
---|
1740 | "terms of the GNU GPL version 3.0 or where you are otherwise willing "
|
---|
1741 | "to comply with the terms of the GNU GPL version 3.0.</p>"
|
---|
1742 | "<p>Please see <a href=\"http://qt.nokia.com/products/licensing\">qt.nokia.com/products/licensing</a> "
|
---|
1743 | "for an overview of Qt licensing.</p>"
|
---|
1744 | "<p>Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).</p>"
|
---|
1745 | "<p>Qt is a Nokia product. See <a href=\"http://qt.nokia.com/\">qt.nokia.com</a> "
|
---|
1746 | "for more information.</p>"
|
---|
1747 | );
|
---|
1748 | QMessageBox *msgBox = new QMessageBox(parent);
|
---|
1749 | msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
---|
1750 | msgBox->setWindowTitle(title.isEmpty() ? tr("About Qt") : title);
|
---|
1751 | msgBox->setText(translatedTextAboutQtCaption);
|
---|
1752 | msgBox->setInformativeText(translatedTextAboutQtText);
|
---|
1753 |
|
---|
1754 | QPixmap pm(QLatin1String(":/trolltech/qmessagebox/images/qtlogo-64.png"));
|
---|
1755 | if (!pm.isNull())
|
---|
1756 | msgBox->setIconPixmap(pm);
|
---|
1757 | #if defined(Q_WS_WINCE)
|
---|
1758 | msgBox->setDefaultButton(msgBox->addButton(QMessageBox::Ok));
|
---|
1759 | #endif
|
---|
1760 |
|
---|
1761 | // should perhaps be a style hint
|
---|
1762 | #ifdef Q_WS_MAC
|
---|
1763 | oldMsgBox = msgBox;
|
---|
1764 | #if 0
|
---|
1765 | // ### doesn't work until close button is enabled in title bar
|
---|
1766 | msgBox->d_func()->autoAddOkButton = false;
|
---|
1767 | #else
|
---|
1768 | msgBox->d_func()->buttonBox->setCenterButtons(true);
|
---|
1769 | #endif
|
---|
1770 | msgBox->show();
|
---|
1771 | #else
|
---|
1772 | msgBox->exec();
|
---|
1773 | #endif
|
---|
1774 | }
|
---|
1775 |
|
---|
1776 | /*!
|
---|
1777 | \internal
|
---|
1778 | */
|
---|
1779 | QSize QMessageBox::sizeHint() const
|
---|
1780 | {
|
---|
1781 | // ### Qt 5: remove
|
---|
1782 | return QDialog::sizeHint();
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 | /////////////////////////////////////////////////////////////////////////////////////////
|
---|
1786 | // Source and binary compatibility routines for 4.0 and 4.1
|
---|
1787 |
|
---|
1788 | static QMessageBox::StandardButton newButton(int button)
|
---|
1789 | {
|
---|
1790 | // this is needed for source compatibility with Qt 4.0 and 4.1
|
---|
1791 | if (button == QMessageBox::NoButton || (button & NewButtonMask))
|
---|
1792 | return QMessageBox::StandardButton(button & QMessageBox::ButtonMask);
|
---|
1793 |
|
---|
1794 | #if QT_VERSION < 0x050000
|
---|
1795 | // this is needed for binary compatibility with Qt 4.0 and 4.1
|
---|
1796 | switch (button & Old_ButtonMask) {
|
---|
1797 | case Old_Ok:
|
---|
1798 | return QMessageBox::Ok;
|
---|
1799 | case Old_Cancel:
|
---|
1800 | return QMessageBox::Cancel;
|
---|
1801 | case Old_Yes:
|
---|
1802 | return QMessageBox::Yes;
|
---|
1803 | case Old_No:
|
---|
1804 | return QMessageBox::No;
|
---|
1805 | case Old_Abort:
|
---|
1806 | return QMessageBox::Abort;
|
---|
1807 | case Old_Retry:
|
---|
1808 | return QMessageBox::Retry;
|
---|
1809 | case Old_Ignore:
|
---|
1810 | return QMessageBox::Ignore;
|
---|
1811 | case Old_YesAll:
|
---|
1812 | return QMessageBox::YesToAll;
|
---|
1813 | case Old_NoAll:
|
---|
1814 | return QMessageBox::NoToAll;
|
---|
1815 | default:
|
---|
1816 | return QMessageBox::NoButton;
|
---|
1817 | }
|
---|
1818 | #endif
|
---|
1819 | }
|
---|
1820 |
|
---|
1821 | static bool detectedCompat(int button0, int button1, int button2)
|
---|
1822 | {
|
---|
1823 | if (button0 != 0 && !(button0 & NewButtonMask))
|
---|
1824 | return true;
|
---|
1825 | if (button1 != 0 && !(button1 & NewButtonMask))
|
---|
1826 | return true;
|
---|
1827 | if (button2 != 0 && !(button2 & NewButtonMask))
|
---|
1828 | return true;
|
---|
1829 | return false;
|
---|
1830 | }
|
---|
1831 |
|
---|
1832 | QAbstractButton *QMessageBoxPrivate::findButton(int button0, int button1, int button2, int flags)
|
---|
1833 | {
|
---|
1834 | Q_Q(QMessageBox);
|
---|
1835 | int button = 0;
|
---|
1836 |
|
---|
1837 | if (button0 & flags) {
|
---|
1838 | button = button0;
|
---|
1839 | } else if (button1 & flags) {
|
---|
1840 | button = button1;
|
---|
1841 | } else if (button2 & flags) {
|
---|
1842 | button = button2;
|
---|
1843 | }
|
---|
1844 | return q->button(newButton(button));
|
---|
1845 | }
|
---|
1846 |
|
---|
1847 | void QMessageBoxPrivate::addOldButtons(int button0, int button1, int button2)
|
---|
1848 | {
|
---|
1849 | Q_Q(QMessageBox);
|
---|
1850 | q->addButton(newButton(button0));
|
---|
1851 | q->addButton(newButton(button1));
|
---|
1852 | q->addButton(newButton(button2));
|
---|
1853 | q->setDefaultButton(
|
---|
1854 | static_cast<QPushButton *>(findButton(button0, button1, button2, QMessageBox::Default)));
|
---|
1855 | q->setEscapeButton(findButton(button0, button1, button2, QMessageBox::Escape));
|
---|
1856 | compatMode = detectedCompat(button0, button1, button2);
|
---|
1857 | }
|
---|
1858 |
|
---|
1859 | QAbstractButton *QMessageBoxPrivate::abstractButtonForId(int id) const
|
---|
1860 | {
|
---|
1861 | Q_Q(const QMessageBox);
|
---|
1862 | QAbstractButton *result = customButtonList.value(id);
|
---|
1863 | if (result)
|
---|
1864 | return result;
|
---|
1865 | if (id & QMessageBox::FlagMask) // for compatibility with Qt 4.0/4.1 (even if it is silly)
|
---|
1866 | return 0;
|
---|
1867 | return q->button(newButton(id));
|
---|
1868 | }
|
---|
1869 |
|
---|
1870 | int QMessageBoxPrivate::showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
---|
1871 | const QString &title, const QString &text,
|
---|
1872 | int button0, int button1, int button2)
|
---|
1873 | {
|
---|
1874 | QMessageBox messageBox(icon, title, text, QMessageBox::NoButton, parent);
|
---|
1875 | messageBox.d_func()->addOldButtons(button0, button1, button2);
|
---|
1876 | return messageBox.exec();
|
---|
1877 | }
|
---|
1878 |
|
---|
1879 | int QMessageBoxPrivate::showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
---|
1880 | const QString &title, const QString &text,
|
---|
1881 | const QString &button0Text,
|
---|
1882 | const QString &button1Text,
|
---|
1883 | const QString &button2Text,
|
---|
1884 | int defaultButtonNumber,
|
---|
1885 | int escapeButtonNumber)
|
---|
1886 | {
|
---|
1887 | QMessageBox messageBox(icon, title, text, QMessageBox::NoButton, parent);
|
---|
1888 | QString myButton0Text = button0Text;
|
---|
1889 | if (myButton0Text.isEmpty())
|
---|
1890 | myButton0Text = QDialogButtonBox::tr("OK");
|
---|
1891 | messageBox.addButton(myButton0Text, QMessageBox::ActionRole);
|
---|
1892 | if (!button1Text.isEmpty())
|
---|
1893 | messageBox.addButton(button1Text, QMessageBox::ActionRole);
|
---|
1894 | if (!button2Text.isEmpty())
|
---|
1895 | messageBox.addButton(button2Text, QMessageBox::ActionRole);
|
---|
1896 |
|
---|
1897 | const QList<QAbstractButton *> &buttonList = messageBox.d_func()->customButtonList;
|
---|
1898 | messageBox.setDefaultButton(static_cast<QPushButton *>(buttonList.value(defaultButtonNumber)));
|
---|
1899 | messageBox.setEscapeButton(buttonList.value(escapeButtonNumber));
|
---|
1900 |
|
---|
1901 | return messageBox.exec();
|
---|
1902 | }
|
---|
1903 |
|
---|
1904 | void QMessageBoxPrivate::retranslateStrings()
|
---|
1905 | {
|
---|
1906 | #ifndef QT_NO_TEXTEDIT
|
---|
1907 | if (detailsButton)
|
---|
1908 | detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel));
|
---|
1909 | #endif
|
---|
1910 | }
|
---|
1911 |
|
---|
1912 | /*!
|
---|
1913 | \obsolete
|
---|
1914 |
|
---|
1915 | Constructs a message box with a \a title, a \a text, an \a icon,
|
---|
1916 | and up to three buttons.
|
---|
1917 |
|
---|
1918 | The \a icon must be one of the following:
|
---|
1919 | \list
|
---|
1920 | \o QMessageBox::NoIcon
|
---|
1921 | \o QMessageBox::Question
|
---|
1922 | \o QMessageBox::Information
|
---|
1923 | \o QMessageBox::Warning
|
---|
1924 | \o QMessageBox::Critical
|
---|
1925 | \endlist
|
---|
1926 |
|
---|
1927 | Each button, \a button0, \a button1 and \a button2, can have one
|
---|
1928 | of the following values:
|
---|
1929 | \list
|
---|
1930 | \o QMessageBox::NoButton
|
---|
1931 | \o QMessageBox::Ok
|
---|
1932 | \o QMessageBox::Cancel
|
---|
1933 | \o QMessageBox::Yes
|
---|
1934 | \o QMessageBox::No
|
---|
1935 | \o QMessageBox::Abort
|
---|
1936 | \o QMessageBox::Retry
|
---|
1937 | \o QMessageBox::Ignore
|
---|
1938 | \o QMessageBox::YesAll
|
---|
1939 | \o QMessageBox::NoAll
|
---|
1940 | \endlist
|
---|
1941 |
|
---|
1942 | Use QMessageBox::NoButton for the later parameters to have fewer
|
---|
1943 | than three buttons in your message box. If you don't specify any
|
---|
1944 | buttons at all, QMessageBox will provide an Ok button.
|
---|
1945 |
|
---|
1946 | One of the buttons can be OR-ed with the QMessageBox::Default
|
---|
1947 | flag to make it the default button (clicked when Enter is
|
---|
1948 | pressed).
|
---|
1949 |
|
---|
1950 | One of the buttons can be OR-ed with the QMessageBox::Escape flag
|
---|
1951 | to make it the cancel or close button (clicked when \key Esc is
|
---|
1952 | pressed).
|
---|
1953 |
|
---|
1954 | \snippet doc/src/snippets/dialogs/dialogs.cpp 2
|
---|
1955 |
|
---|
1956 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
1957 | {application modal} dialog box. If \a parent is a widget, the
|
---|
1958 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
1959 | parent.
|
---|
1960 |
|
---|
1961 | The \a parent and \a f arguments are passed to
|
---|
1962 | the QDialog constructor.
|
---|
1963 |
|
---|
1964 | \sa setWindowTitle(), setText(), setIcon()
|
---|
1965 | */
|
---|
1966 | QMessageBox::QMessageBox(const QString &title, const QString &text, Icon icon,
|
---|
1967 | int button0, int button1, int button2, QWidget *parent,
|
---|
1968 | Qt::WindowFlags f)
|
---|
1969 | : QDialog(*new QMessageBoxPrivate, parent,
|
---|
1970 | f /*| Qt::MSWindowsFixedSizeDialogHint #### */| Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
|
---|
1971 | {
|
---|
1972 | Q_D(QMessageBox);
|
---|
1973 | d->init(title, text);
|
---|
1974 | setIcon(icon);
|
---|
1975 | d->addOldButtons(button0, button1, button2);
|
---|
1976 | }
|
---|
1977 |
|
---|
1978 | /*!
|
---|
1979 | \obsolete
|
---|
1980 |
|
---|
1981 | Opens an information message box with the given \a title and the
|
---|
1982 | \a text. The dialog may have up to three buttons. Each of the
|
---|
1983 | buttons, \a button0, \a button1 and \a button2 may be set to one
|
---|
1984 | of the following values:
|
---|
1985 |
|
---|
1986 | \list
|
---|
1987 | \o QMessageBox::NoButton
|
---|
1988 | \o QMessageBox::Ok
|
---|
1989 | \o QMessageBox::Cancel
|
---|
1990 | \o QMessageBox::Yes
|
---|
1991 | \o QMessageBox::No
|
---|
1992 | \o QMessageBox::Abort
|
---|
1993 | \o QMessageBox::Retry
|
---|
1994 | \o QMessageBox::Ignore
|
---|
1995 | \o QMessageBox::YesAll
|
---|
1996 | \o QMessageBox::NoAll
|
---|
1997 | \endlist
|
---|
1998 |
|
---|
1999 | If you don't want all three buttons, set the last button, or last
|
---|
2000 | two buttons to QMessageBox::NoButton.
|
---|
2001 |
|
---|
2002 | One button can be OR-ed with QMessageBox::Default, and one
|
---|
2003 | button can be OR-ed with QMessageBox::Escape.
|
---|
2004 |
|
---|
2005 | Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.)
|
---|
2006 | of the button that was clicked.
|
---|
2007 |
|
---|
2008 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
2009 | {application modal} dialog box. If \a parent is a widget, the
|
---|
2010 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
2011 | parent.
|
---|
2012 |
|
---|
2013 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
2014 | If you want to do this, you should create the dialog
|
---|
2015 | yourself using one of the QMessageBox constructors.
|
---|
2016 |
|
---|
2017 | \sa question(), warning(), critical()
|
---|
2018 | */
|
---|
2019 | int QMessageBox::information(QWidget *parent, const QString &title, const QString& text,
|
---|
2020 | int button0, int button1, int button2)
|
---|
2021 | {
|
---|
2022 | return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text,
|
---|
2023 | button0, button1, button2);
|
---|
2024 | }
|
---|
2025 |
|
---|
2026 | /*!
|
---|
2027 | \obsolete
|
---|
2028 | \overload
|
---|
2029 |
|
---|
2030 | Displays an information message box with the given \a title and
|
---|
2031 | \a text, as well as one, two or three buttons. Returns the index
|
---|
2032 | of the button that was clicked (0, 1 or 2).
|
---|
2033 |
|
---|
2034 | \a button0Text is the text of the first button, and is optional.
|
---|
2035 | If \a button0Text is not supplied, "OK" (translated) will be
|
---|
2036 | used. \a button1Text is the text of the second button, and is
|
---|
2037 | optional. \a button2Text is the text of the third button, and is
|
---|
2038 | optional. \a defaultButtonNumber (0, 1 or 2) is the index of the
|
---|
2039 | default button; pressing Return or Enter is the same as clicking
|
---|
2040 | the default button. It defaults to 0 (the first button). \a
|
---|
2041 | escapeButtonNumber is the index of the escape button; pressing
|
---|
2042 | \key Esc is the same as clicking this button. It defaults to -1;
|
---|
2043 | supply 0, 1 or 2 to make pressing \key Esc equivalent to clicking
|
---|
2044 | the relevant button.
|
---|
2045 |
|
---|
2046 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
2047 | {application modal} dialog box. If \a parent is a widget, the
|
---|
2048 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
2049 | parent.
|
---|
2050 |
|
---|
2051 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
2052 | If you want to do this, you should create the dialog
|
---|
2053 | yourself using one of the QMessageBox constructors.
|
---|
2054 |
|
---|
2055 | \sa question(), warning(), critical()
|
---|
2056 | */
|
---|
2057 |
|
---|
2058 | int QMessageBox::information(QWidget *parent, const QString &title, const QString& text,
|
---|
2059 | const QString& button0Text, const QString& button1Text,
|
---|
2060 | const QString& button2Text, int defaultButtonNumber,
|
---|
2061 | int escapeButtonNumber)
|
---|
2062 | {
|
---|
2063 | return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text,
|
---|
2064 | button0Text, button1Text, button2Text,
|
---|
2065 | defaultButtonNumber, escapeButtonNumber);
|
---|
2066 | }
|
---|
2067 |
|
---|
2068 | /*!
|
---|
2069 | \obsolete
|
---|
2070 |
|
---|
2071 | Opens a question message box with the given \a title and \a text.
|
---|
2072 | The dialog may have up to three buttons. Each of the buttons, \a
|
---|
2073 | button0, \a button1 and \a button2 may be set to one of the
|
---|
2074 | following values:
|
---|
2075 |
|
---|
2076 | \list
|
---|
2077 | \o QMessageBox::NoButton
|
---|
2078 | \o QMessageBox::Ok
|
---|
2079 | \o QMessageBox::Cancel
|
---|
2080 | \o QMessageBox::Yes
|
---|
2081 | \o QMessageBox::No
|
---|
2082 | \o QMessageBox::Abort
|
---|
2083 | \o QMessageBox::Retry
|
---|
2084 | \o QMessageBox::Ignore
|
---|
2085 | \o QMessageBox::YesAll
|
---|
2086 | \o QMessageBox::NoAll
|
---|
2087 | \endlist
|
---|
2088 |
|
---|
2089 | If you don't want all three buttons, set the last button, or last
|
---|
2090 | two buttons to QMessageBox::NoButton.
|
---|
2091 |
|
---|
2092 | One button can be OR-ed with QMessageBox::Default, and one
|
---|
2093 | button can be OR-ed with QMessageBox::Escape.
|
---|
2094 |
|
---|
2095 | Returns the identity (QMessageBox::Yes, or QMessageBox::No, etc.)
|
---|
2096 | of the button that was clicked.
|
---|
2097 |
|
---|
2098 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
2099 | {application modal} dialog box. If \a parent is a widget, the
|
---|
2100 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
2101 | parent.
|
---|
2102 |
|
---|
2103 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
2104 | If you want to do this, you should create the dialog
|
---|
2105 | yourself using one of the QMessageBox constructors.
|
---|
2106 |
|
---|
2107 | \sa information(), warning(), critical()
|
---|
2108 | */
|
---|
2109 | int QMessageBox::question(QWidget *parent, const QString &title, const QString& text,
|
---|
2110 | int button0, int button1, int button2)
|
---|
2111 | {
|
---|
2112 | return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text,
|
---|
2113 | button0, button1, button2);
|
---|
2114 | }
|
---|
2115 |
|
---|
2116 | /*!
|
---|
2117 | \obsolete
|
---|
2118 | \overload
|
---|
2119 |
|
---|
2120 | Displays a question message box with the given \a title and \a
|
---|
2121 | text, as well as one, two or three buttons. Returns the index of
|
---|
2122 | the button that was clicked (0, 1 or 2).
|
---|
2123 |
|
---|
2124 | \a button0Text is the text of the first button, and is optional.
|
---|
2125 | If \a button0Text is not supplied, "OK" (translated) will be used.
|
---|
2126 | \a button1Text is the text of the second button, and is optional.
|
---|
2127 | \a button2Text is the text of the third button, and is optional.
|
---|
2128 | \a defaultButtonNumber (0, 1 or 2) is the index of the default
|
---|
2129 | button; pressing Return or Enter is the same as clicking the
|
---|
2130 | default button. It defaults to 0 (the first button). \a
|
---|
2131 | escapeButtonNumber is the index of the Escape button; pressing
|
---|
2132 | Escape is the same as clicking this button. It defaults to -1;
|
---|
2133 | supply 0, 1 or 2 to make pressing Escape equivalent to clicking
|
---|
2134 | the relevant button.
|
---|
2135 |
|
---|
2136 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
2137 | {application modal} dialog box. If \a parent is a widget, the
|
---|
2138 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
2139 | parent.
|
---|
2140 |
|
---|
2141 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
2142 | If you want to do this, you should create the dialog
|
---|
2143 | yourself using one of the QMessageBox constructors.
|
---|
2144 |
|
---|
2145 | \sa information(), warning(), critical()
|
---|
2146 | */
|
---|
2147 | int QMessageBox::question(QWidget *parent, const QString &title, const QString& text,
|
---|
2148 | const QString& button0Text, const QString& button1Text,
|
---|
2149 | const QString& button2Text, int defaultButtonNumber,
|
---|
2150 | int escapeButtonNumber)
|
---|
2151 | {
|
---|
2152 | return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text,
|
---|
2153 | button0Text, button1Text, button2Text,
|
---|
2154 | defaultButtonNumber, escapeButtonNumber);
|
---|
2155 | }
|
---|
2156 |
|
---|
2157 |
|
---|
2158 | /*!
|
---|
2159 | \obsolete
|
---|
2160 |
|
---|
2161 | Opens a warning message box with the given \a title and \a text.
|
---|
2162 | The dialog may have up to three buttons. Each of the button
|
---|
2163 | parameters, \a button0, \a button1 and \a button2 may be set to
|
---|
2164 | one of the following values:
|
---|
2165 |
|
---|
2166 | \list
|
---|
2167 | \o QMessageBox::NoButton
|
---|
2168 | \o QMessageBox::Ok
|
---|
2169 | \o QMessageBox::Cancel
|
---|
2170 | \o QMessageBox::Yes
|
---|
2171 | \o QMessageBox::No
|
---|
2172 | \o QMessageBox::Abort
|
---|
2173 | \o QMessageBox::Retry
|
---|
2174 | \o QMessageBox::Ignore
|
---|
2175 | \o QMessageBox::YesAll
|
---|
2176 | \o QMessageBox::NoAll
|
---|
2177 | \endlist
|
---|
2178 |
|
---|
2179 | If you don't want all three buttons, set the last button, or last
|
---|
2180 | two buttons to QMessageBox::NoButton.
|
---|
2181 |
|
---|
2182 | One button can be OR-ed with QMessageBox::Default, and one
|
---|
2183 | button can be OR-ed with QMessageBox::Escape.
|
---|
2184 |
|
---|
2185 | Returns the identity (QMessageBox::Ok or QMessageBox::No or ...)
|
---|
2186 | of the button that was clicked.
|
---|
2187 |
|
---|
2188 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
2189 | {application modal} dialog box. If \a parent is a widget, the
|
---|
2190 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
2191 | parent.
|
---|
2192 |
|
---|
2193 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
2194 | If you want to do this, you should create the dialog
|
---|
2195 | yourself using one of the QMessageBox constructors.
|
---|
2196 |
|
---|
2197 | \sa information(), question(), critical()
|
---|
2198 | */
|
---|
2199 | int QMessageBox::warning(QWidget *parent, const QString &title, const QString& text,
|
---|
2200 | int button0, int button1, int button2)
|
---|
2201 | {
|
---|
2202 | return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text,
|
---|
2203 | button0, button1, button2);
|
---|
2204 | }
|
---|
2205 |
|
---|
2206 | /*!
|
---|
2207 | \obsolete
|
---|
2208 | \overload
|
---|
2209 |
|
---|
2210 | Displays a warning message box with the given \a title and \a
|
---|
2211 | text, as well as one, two, or three buttons. Returns the number
|
---|
2212 | of the button that was clicked (0, 1, or 2).
|
---|
2213 |
|
---|
2214 | \a button0Text is the text of the first button, and is optional.
|
---|
2215 | If \a button0Text is not supplied, "OK" (translated) will be used.
|
---|
2216 | \a button1Text is the text of the second button, and is optional,
|
---|
2217 | and \a button2Text is the text of the third button, and is
|
---|
2218 | optional. \a defaultButtonNumber (0, 1 or 2) is the index of the
|
---|
2219 | default button; pressing Return or Enter is the same as clicking
|
---|
2220 | the default button. It defaults to 0 (the first button). \a
|
---|
2221 | escapeButtonNumber is the index of the Escape button; pressing
|
---|
2222 | Escape is the same as clicking this button. It defaults to -1;
|
---|
2223 | supply 0, 1, or 2 to make pressing Escape equivalent to clicking
|
---|
2224 | the relevant button.
|
---|
2225 |
|
---|
2226 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
2227 | {application modal} dialog box. If \a parent is a widget, the
|
---|
2228 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
2229 | parent.
|
---|
2230 |
|
---|
2231 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
2232 | If you want to do this, you should create the dialog
|
---|
2233 | yourself using one of the QMessageBox constructors.
|
---|
2234 |
|
---|
2235 | \sa information(), question(), critical()
|
---|
2236 | */
|
---|
2237 | int QMessageBox::warning(QWidget *parent, const QString &title, const QString& text,
|
---|
2238 | const QString& button0Text, const QString& button1Text,
|
---|
2239 | const QString& button2Text, int defaultButtonNumber,
|
---|
2240 | int escapeButtonNumber)
|
---|
2241 | {
|
---|
2242 | return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text,
|
---|
2243 | button0Text, button1Text, button2Text,
|
---|
2244 | defaultButtonNumber, escapeButtonNumber);
|
---|
2245 | }
|
---|
2246 |
|
---|
2247 | /*!
|
---|
2248 | \obsolete
|
---|
2249 |
|
---|
2250 | Opens a critical message box with the given \a title and \a text.
|
---|
2251 | The dialog may have up to three buttons. Each of the button
|
---|
2252 | parameters, \a button0, \a button1 and \a button2 may be set to
|
---|
2253 | one of the following values:
|
---|
2254 |
|
---|
2255 | \list
|
---|
2256 | \o QMessageBox::NoButton
|
---|
2257 | \o QMessageBox::Ok
|
---|
2258 | \o QMessageBox::Cancel
|
---|
2259 | \o QMessageBox::Yes
|
---|
2260 | \o QMessageBox::No
|
---|
2261 | \o QMessageBox::Abort
|
---|
2262 | \o QMessageBox::Retry
|
---|
2263 | \o QMessageBox::Ignore
|
---|
2264 | \o QMessageBox::YesAll
|
---|
2265 | \o QMessageBox::NoAll
|
---|
2266 | \endlist
|
---|
2267 |
|
---|
2268 | If you don't want all three buttons, set the last button, or last
|
---|
2269 | two buttons to QMessageBox::NoButton.
|
---|
2270 |
|
---|
2271 | One button can be OR-ed with QMessageBox::Default, and one
|
---|
2272 | button can be OR-ed with QMessageBox::Escape.
|
---|
2273 |
|
---|
2274 | Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.)
|
---|
2275 | of the button that was clicked.
|
---|
2276 |
|
---|
2277 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
2278 | {application modal} dialog box. If \a parent is a widget, the
|
---|
2279 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
2280 | parent.
|
---|
2281 |
|
---|
2282 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
2283 | If you want to do this, you should create the dialog
|
---|
2284 | yourself using one of the QMessageBox constructors.
|
---|
2285 |
|
---|
2286 | \sa information(), question(), warning()
|
---|
2287 | */
|
---|
2288 |
|
---|
2289 | int QMessageBox::critical(QWidget *parent, const QString &title, const QString& text,
|
---|
2290 | int button0, int button1, int button2)
|
---|
2291 | {
|
---|
2292 | return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text,
|
---|
2293 | button0, button1, button2);
|
---|
2294 | }
|
---|
2295 |
|
---|
2296 | /*!
|
---|
2297 | \obsolete
|
---|
2298 | \overload
|
---|
2299 |
|
---|
2300 | Displays a critical error message box with the given \a title and
|
---|
2301 | \a text, as well as one, two, or three buttons. Returns the
|
---|
2302 | number of the button that was clicked (0, 1 or 2).
|
---|
2303 |
|
---|
2304 | \a button0Text is the text of the first button, and is optional.
|
---|
2305 | If \a button0Text is not supplied, "OK" (translated) will be used.
|
---|
2306 | \a button1Text is the text of the second button, and is optional,
|
---|
2307 | and \a button2Text is the text of the third button, and is
|
---|
2308 | optional. \a defaultButtonNumber (0, 1 or 2) is the index of the
|
---|
2309 | default button; pressing Return or Enter is the same as clicking
|
---|
2310 | the default button. It defaults to 0 (the first button). \a
|
---|
2311 | escapeButtonNumber is the index of the Escape button; pressing
|
---|
2312 | Escape is the same as clicking this button. It defaults to -1;
|
---|
2313 | supply 0, 1, or 2 to make pressing Escape equivalent to clicking
|
---|
2314 | the relevant button.
|
---|
2315 |
|
---|
2316 | If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
---|
2317 | {application modal} dialog box. If \a parent is a widget, the
|
---|
2318 | message box is \l{Qt::WindowModal} {window modal} relative to \a
|
---|
2319 | parent.
|
---|
2320 |
|
---|
2321 | \warning Do not delete \a parent during the execution of the dialog.
|
---|
2322 | If you want to do this, you should create the dialog
|
---|
2323 | yourself using one of the QMessageBox constructors.
|
---|
2324 |
|
---|
2325 | \sa information(), question(), warning()
|
---|
2326 | */
|
---|
2327 | int QMessageBox::critical(QWidget *parent, const QString &title, const QString& text,
|
---|
2328 | const QString& button0Text, const QString& button1Text,
|
---|
2329 | const QString& button2Text, int defaultButtonNumber,
|
---|
2330 | int escapeButtonNumber)
|
---|
2331 | {
|
---|
2332 | return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text,
|
---|
2333 | button0Text, button1Text, button2Text,
|
---|
2334 | defaultButtonNumber, escapeButtonNumber);
|
---|
2335 | }
|
---|
2336 |
|
---|
2337 |
|
---|
2338 | /*!
|
---|
2339 | \obsolete
|
---|
2340 |
|
---|
2341 | Returns the text of the message box button \a button, or
|
---|
2342 | an empty string if the message box does not contain the button.
|
---|
2343 |
|
---|
2344 | Use button() and QPushButton::text() instead.
|
---|
2345 | */
|
---|
2346 | QString QMessageBox::buttonText(int button) const
|
---|
2347 | {
|
---|
2348 | Q_D(const QMessageBox);
|
---|
2349 |
|
---|
2350 | if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {
|
---|
2351 | return abstractButton->text();
|
---|
2352 | } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {
|
---|
2353 | // for compatibility with Qt 4.0/4.1
|
---|
2354 | return QDialogButtonBox::tr("OK");
|
---|
2355 | }
|
---|
2356 | return QString();
|
---|
2357 | }
|
---|
2358 |
|
---|
2359 | /*!
|
---|
2360 | \obsolete
|
---|
2361 |
|
---|
2362 | Sets the text of the message box button \a button to \a text.
|
---|
2363 | Setting the text of a button that is not in the message box is
|
---|
2364 | silently ignored.
|
---|
2365 |
|
---|
2366 | Use addButton() instead.
|
---|
2367 | */
|
---|
2368 | void QMessageBox::setButtonText(int button, const QString &text)
|
---|
2369 | {
|
---|
2370 | Q_D(QMessageBox);
|
---|
2371 | if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {
|
---|
2372 | abstractButton->setText(text);
|
---|
2373 | } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {
|
---|
2374 | // for compatibility with Qt 4.0/4.1
|
---|
2375 | addButton(QMessageBox::Ok)->setText(text);
|
---|
2376 | }
|
---|
2377 | }
|
---|
2378 |
|
---|
2379 | #ifndef QT_NO_TEXTEDIT
|
---|
2380 | /*!
|
---|
2381 | \property QMessageBox::detailedText
|
---|
2382 | \brief the text to be displayed in the details area.
|
---|
2383 | \since 4.2
|
---|
2384 |
|
---|
2385 | The text will be interpreted as a plain text.
|
---|
2386 |
|
---|
2387 | By default, this property contains an empty string.
|
---|
2388 |
|
---|
2389 | \sa QMessageBox::text, QMessageBox::informativeText
|
---|
2390 | */
|
---|
2391 | QString QMessageBox::detailedText() const
|
---|
2392 | {
|
---|
2393 | Q_D(const QMessageBox);
|
---|
2394 | return d->detailsText ? d->detailsText->text() : QString();
|
---|
2395 | }
|
---|
2396 |
|
---|
2397 | void QMessageBox::setDetailedText(const QString &text)
|
---|
2398 | {
|
---|
2399 | Q_D(QMessageBox);
|
---|
2400 | if (text.isEmpty()) {
|
---|
2401 | delete d->detailsText;
|
---|
2402 | d->detailsText = 0;
|
---|
2403 | removeButton(d->detailsButton);
|
---|
2404 | delete d->detailsButton;
|
---|
2405 | d->detailsButton = 0;
|
---|
2406 | return;
|
---|
2407 | }
|
---|
2408 |
|
---|
2409 | if (!d->detailsText) {
|
---|
2410 | d->detailsText = new QMessageBoxDetailsText(this);
|
---|
2411 | QGridLayout* grid = qobject_cast<QGridLayout*>(layout());
|
---|
2412 | if (grid)
|
---|
2413 | grid->addWidget(d->detailsText, grid->rowCount(), 0, 1, grid->columnCount());
|
---|
2414 | d->detailsText->hide();
|
---|
2415 | }
|
---|
2416 | if (!d->detailsButton) {
|
---|
2417 | d->detailsButton = new QPushButton(d->detailsText->label(ShowLabel), this);
|
---|
2418 | QPushButton hideDetails(d->detailsText->label(HideLabel));
|
---|
2419 | d->detailsButton->setFixedSize(d->detailsButton->sizeHint().expandedTo(hideDetails.sizeHint()));
|
---|
2420 | }
|
---|
2421 | d->detailsText->setText(text);
|
---|
2422 | }
|
---|
2423 | #endif // QT_NO_TEXTEDIT
|
---|
2424 |
|
---|
2425 | /*!
|
---|
2426 | \property QMessageBox::informativeText
|
---|
2427 |
|
---|
2428 | \brief the informative text that provides a fuller description for
|
---|
2429 | the message
|
---|
2430 |
|
---|
2431 | \since 4.2
|
---|
2432 |
|
---|
2433 | Infromative text can be used to expand upon the text() to give more
|
---|
2434 | information to the user. On the Mac, this text appears in small
|
---|
2435 | system font below the text(). On other platforms, it is simply
|
---|
2436 | appended to the existing text.
|
---|
2437 |
|
---|
2438 | By default, this property contains an empty string.
|
---|
2439 |
|
---|
2440 | \sa QMessageBox::text, QMessageBox::detailedText
|
---|
2441 | */
|
---|
2442 | QString QMessageBox::informativeText() const
|
---|
2443 | {
|
---|
2444 | Q_D(const QMessageBox);
|
---|
2445 | return d->informativeLabel ? d->informativeLabel->text() : QString();
|
---|
2446 | }
|
---|
2447 |
|
---|
2448 | void QMessageBox::setInformativeText(const QString &text)
|
---|
2449 | {
|
---|
2450 | Q_D(QMessageBox);
|
---|
2451 | if (text.isEmpty()) {
|
---|
2452 | layout()->removeWidget(d->informativeLabel);
|
---|
2453 | delete d->informativeLabel;
|
---|
2454 | d->informativeLabel = 0;
|
---|
2455 | #ifndef Q_WS_MAC
|
---|
2456 | d->label->setContentsMargins(2, 0, 0, 0);
|
---|
2457 | #endif
|
---|
2458 | d->updateSize();
|
---|
2459 | return;
|
---|
2460 | }
|
---|
2461 |
|
---|
2462 | if (!d->informativeLabel) {
|
---|
2463 | QLabel *label = new QLabel;
|
---|
2464 | label->setObjectName(QLatin1String("qt_msgbox_informativelabel"));
|
---|
2465 | label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this)));
|
---|
2466 | label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
---|
2467 | label->setOpenExternalLinks(true);
|
---|
2468 | label->setWordWrap(true);
|
---|
2469 | #ifndef Q_WS_MAC
|
---|
2470 | d->label->setContentsMargins(2, 0, 0, 0);
|
---|
2471 | label->setContentsMargins(2, 0, 0, 6);
|
---|
2472 | label->setIndent(9);
|
---|
2473 | #else
|
---|
2474 | label->setContentsMargins(16, 0, 0, 0);
|
---|
2475 | // apply a smaller font the information label on the mac
|
---|
2476 | label->setFont(qt_app_fonts_hash()->value("QTipLabel"));
|
---|
2477 | #endif
|
---|
2478 | label->setWordWrap(true);
|
---|
2479 | QGridLayout *grid = static_cast<QGridLayout *>(layout());
|
---|
2480 | #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
|
---|
2481 | label->hide();
|
---|
2482 | QTextBrowser *textBrowser = new QTextBrowser(this);
|
---|
2483 | textBrowser->setOpenExternalLinks(true);
|
---|
2484 | grid->addWidget(textBrowser, 1, 1, 1, 1);
|
---|
2485 | d->textBrowser = textBrowser;
|
---|
2486 | #else
|
---|
2487 | grid->addWidget(label, 1, 1, 1, 1);
|
---|
2488 | #endif
|
---|
2489 | d->informativeLabel = label;
|
---|
2490 | }
|
---|
2491 | d->informativeLabel->setText(text);
|
---|
2492 |
|
---|
2493 | #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
|
---|
2494 | //We need to put the informative label inside textBrowser to enable scrolling of long texts.
|
---|
2495 | d->textBrowser->setText(d->informativeLabel->text());
|
---|
2496 | #endif
|
---|
2497 |
|
---|
2498 | d->updateSize();
|
---|
2499 | }
|
---|
2500 |
|
---|
2501 | /*!
|
---|
2502 | \since 4.2
|
---|
2503 |
|
---|
2504 | This function shadows QWidget::setWindowTitle().
|
---|
2505 |
|
---|
2506 | Sets the title of the message box to \a title. On Mac OS X,
|
---|
2507 | the window title is ignored (as required by the Mac OS X
|
---|
2508 | Guidelines).
|
---|
2509 | */
|
---|
2510 | void QMessageBox::setWindowTitle(const QString &title)
|
---|
2511 | {
|
---|
2512 | // Message boxes on the mac do not have a title
|
---|
2513 | #ifndef Q_WS_MAC
|
---|
2514 | QDialog::setWindowTitle(title);
|
---|
2515 | #else
|
---|
2516 | Q_UNUSED(title);
|
---|
2517 | #endif
|
---|
2518 | }
|
---|
2519 |
|
---|
2520 |
|
---|
2521 | /*!
|
---|
2522 | \since 4.2
|
---|
2523 |
|
---|
2524 | This function shadows QWidget::setWindowModality().
|
---|
2525 |
|
---|
2526 | Sets the modality of the message box to \a windowModality.
|
---|
2527 |
|
---|
2528 | On Mac OS X, if the modality is set to Qt::WindowModal and the message box
|
---|
2529 | has a parent, then the message box will be a Qt::Sheet, otherwise the
|
---|
2530 | message box will be a standard dialog.
|
---|
2531 | */
|
---|
2532 | void QMessageBox::setWindowModality(Qt::WindowModality windowModality)
|
---|
2533 | {
|
---|
2534 | QDialog::setWindowModality(windowModality);
|
---|
2535 |
|
---|
2536 | if (parentWidget() && windowModality == Qt::WindowModal)
|
---|
2537 | setParent(parentWidget(), Qt::Sheet);
|
---|
2538 | else
|
---|
2539 | setParent(parentWidget(), Qt::Dialog);
|
---|
2540 | setDefaultButton(d_func()->defaultButton);
|
---|
2541 | }
|
---|
2542 |
|
---|
2543 | #ifdef QT3_SUPPORT
|
---|
2544 | /*!
|
---|
2545 | \compat
|
---|
2546 |
|
---|
2547 | Constructs a message box with the given \a parent, \a name, and
|
---|
2548 | window flags, \a f.
|
---|
2549 | The window title is specified by \a title, and the message box
|
---|
2550 | displays message text and an icon specified by \a text and \a icon.
|
---|
2551 |
|
---|
2552 | The buttons that the user can access to respond to the message are
|
---|
2553 | defined by \a button0, \a button1, and \a button2.
|
---|
2554 | */
|
---|
2555 | QMessageBox::QMessageBox(const QString& title,
|
---|
2556 | const QString &text, Icon icon,
|
---|
2557 | int button0, int button1, int button2,
|
---|
2558 | QWidget *parent, const char *name,
|
---|
2559 | bool modal, Qt::WindowFlags f)
|
---|
2560 | : QDialog(*new QMessageBoxPrivate, parent,
|
---|
2561 | f | Qt::WStyle_Customize | Qt::WStyle_DialogBorder | Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WindowCloseButtonHint)
|
---|
2562 | {
|
---|
2563 | Q_D(QMessageBox);
|
---|
2564 | setObjectName(QString::fromAscii(name));
|
---|
2565 | d->init(title, text);
|
---|
2566 | d->addOldButtons(button0, button1, button2);
|
---|
2567 | setModal(modal);
|
---|
2568 | setIcon(icon);
|
---|
2569 | }
|
---|
2570 |
|
---|
2571 | /*!
|
---|
2572 | \compat
|
---|
2573 | Constructs a message box with the given \a parent and \a name.
|
---|
2574 | */
|
---|
2575 | QMessageBox::QMessageBox(QWidget *parent, const char *name)
|
---|
2576 | : QDialog(*new QMessageBoxPrivate, parent,
|
---|
2577 | Qt::WStyle_Customize | Qt::WStyle_DialogBorder | Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WindowCloseButtonHint)
|
---|
2578 | {
|
---|
2579 | Q_D(QMessageBox);
|
---|
2580 | setObjectName(QString::fromAscii(name));
|
---|
2581 | d->init();
|
---|
2582 | }
|
---|
2583 |
|
---|
2584 | /*!
|
---|
2585 | Returns the pixmap used for a standard icon. This
|
---|
2586 | allows the pixmaps to be used in more complex message boxes.
|
---|
2587 | \a icon specifies the required icon, e.g. QMessageBox::Information,
|
---|
2588 | QMessageBox::Warning or QMessageBox::Critical.
|
---|
2589 |
|
---|
2590 | \a style is unused.
|
---|
2591 | */
|
---|
2592 |
|
---|
2593 | QPixmap QMessageBox::standardIcon(Icon icon, Qt::GUIStyle style)
|
---|
2594 | {
|
---|
2595 | Q_UNUSED(style);
|
---|
2596 | return QMessageBox::standardIcon(icon);
|
---|
2597 | }
|
---|
2598 |
|
---|
2599 | /*!
|
---|
2600 | \fn int QMessageBox::message(const QString &title, const QString &text,
|
---|
2601 | const QString &buttonText, QWidget *parent = 0,
|
---|
2602 | const char *name = 0)
|
---|
2603 |
|
---|
2604 | Opens a modal message box with the given \a title and showing the
|
---|
2605 | given \a text. The message box has a single button which has the
|
---|
2606 | given \a buttonText (or tr("OK")). The message box is centred over
|
---|
2607 | its \a parent and is called \a name.
|
---|
2608 |
|
---|
2609 | Use information(), warning(), question(), or critical() instead.
|
---|
2610 |
|
---|
2611 | \oldcode
|
---|
2612 | QMessageBox::message(tr("My App"), tr("All occurrences replaced."),
|
---|
2613 | tr("Close"), this);
|
---|
2614 | \newcode
|
---|
2615 | QMessageBox::information(this, tr("My App"),
|
---|
2616 | tr("All occurrences replaced."),
|
---|
2617 | QMessageBox::Close);
|
---|
2618 | \endcode
|
---|
2619 | */
|
---|
2620 |
|
---|
2621 | /*!
|
---|
2622 | \fn bool QMessageBox::query(const QString &caption,
|
---|
2623 | const QString& text,
|
---|
2624 | const QString& yesButtonText,
|
---|
2625 | const QString& noButtonText,
|
---|
2626 | QWidget *parent, const char *name)
|
---|
2627 |
|
---|
2628 | \obsolete
|
---|
2629 |
|
---|
2630 | Queries the user using a modal message box with up to two buttons.
|
---|
2631 | The message box has the given \a caption (although some window
|
---|
2632 | managers don't show it), and shows the given \a text. The left
|
---|
2633 | button has the \a yesButtonText (or tr("OK")), and the right button
|
---|
2634 | has the \a noButtonText (or isn't shown). The message box is centred
|
---|
2635 | over its \a parent and is called \a name.
|
---|
2636 |
|
---|
2637 | Use information(), question(), warning(), or critical() instead.
|
---|
2638 | */
|
---|
2639 |
|
---|
2640 | #endif
|
---|
2641 |
|
---|
2642 | QPixmap QMessageBoxPrivate::standardIcon(QMessageBox::Icon icon, QMessageBox *mb)
|
---|
2643 | {
|
---|
2644 | QStyle *style = mb ? mb->style() : QApplication::style();
|
---|
2645 | int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, mb);
|
---|
2646 | QIcon tmpIcon;
|
---|
2647 | switch (icon) {
|
---|
2648 | case QMessageBox::Information:
|
---|
2649 | tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, mb);
|
---|
2650 | break;
|
---|
2651 | case QMessageBox::Warning:
|
---|
2652 | tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, mb);
|
---|
2653 | break;
|
---|
2654 | case QMessageBox::Critical:
|
---|
2655 | tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, mb);
|
---|
2656 | break;
|
---|
2657 | case QMessageBox::Question:
|
---|
2658 | tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mb);
|
---|
2659 | default:
|
---|
2660 | break;
|
---|
2661 | }
|
---|
2662 | if (!tmpIcon.isNull())
|
---|
2663 | return tmpIcon.pixmap(iconSize, iconSize);
|
---|
2664 | return QPixmap();
|
---|
2665 | }
|
---|
2666 |
|
---|
2667 | /*!
|
---|
2668 | \obsolete
|
---|
2669 |
|
---|
2670 | Returns the pixmap used for a standard icon. This allows the
|
---|
2671 | pixmaps to be used in more complex message boxes. \a icon
|
---|
2672 | specifies the required icon, e.g. QMessageBox::Question,
|
---|
2673 | QMessageBox::Information, QMessageBox::Warning or
|
---|
2674 | QMessageBox::Critical.
|
---|
2675 |
|
---|
2676 | Call QStyle::standardIcon() with QStyle::SP_MessageBoxInformation etc.
|
---|
2677 | instead.
|
---|
2678 | */
|
---|
2679 |
|
---|
2680 | QPixmap QMessageBox::standardIcon(Icon icon)
|
---|
2681 | {
|
---|
2682 | return QMessageBoxPrivate::standardIcon(icon, 0);
|
---|
2683 | }
|
---|
2684 |
|
---|
2685 | /*!
|
---|
2686 | \typedef QMessageBox::Button
|
---|
2687 | \obsolete
|
---|
2688 |
|
---|
2689 | Use QMessageBox::StandardButton instead.
|
---|
2690 | */
|
---|
2691 |
|
---|
2692 | /*!
|
---|
2693 | \fn int QMessageBox::information(QWidget *parent, const QString &title,
|
---|
2694 | const QString& text, StandardButton button0,
|
---|
2695 | StandardButton button1)
|
---|
2696 | \fn int QMessageBox::warning(QWidget *parent, const QString &title,
|
---|
2697 | const QString& text, StandardButton button0,
|
---|
2698 | StandardButton button1)
|
---|
2699 | \fn int QMessageBox::critical(QWidget *parent, const QString &title,
|
---|
2700 | const QString& text, StandardButton button0,
|
---|
2701 | StandardButton button1)
|
---|
2702 | \fn int QMessageBox::question(QWidget *parent, const QString &title,
|
---|
2703 | const QString& text, StandardButton button0,
|
---|
2704 | StandardButton button1)
|
---|
2705 | \internal
|
---|
2706 |
|
---|
2707 | ### Needed for Qt 4 source compatibility
|
---|
2708 | */
|
---|
2709 |
|
---|
2710 | /*!
|
---|
2711 | \fn int QMessageBox::exec()
|
---|
2712 |
|
---|
2713 | Shows the message box as a \l{QDialog#Modal Dialogs}{modal dialog},
|
---|
2714 | blocking until the user closes it.
|
---|
2715 |
|
---|
2716 | When using a QMessageBox with standard buttons, this functions returns a
|
---|
2717 | \l StandardButton value indicating the standard button that was clicked.
|
---|
2718 | When using QMessageBox with custom buttons, this function returns an
|
---|
2719 | opaque value; use clickedButton() to determine which button was clicked.
|
---|
2720 |
|
---|
2721 | Users cannot interact with any other window in the same
|
---|
2722 | application until they close the dialog, either by clicking a
|
---|
2723 | button or by using a mechanism provided by the window system.
|
---|
2724 |
|
---|
2725 | \sa show(), result()
|
---|
2726 | */
|
---|
2727 |
|
---|
2728 | QT_END_NAMESPACE
|
---|
2729 |
|
---|
2730 | #include "moc_qmessagebox.cpp"
|
---|
2731 |
|
---|
2732 | #endif // QT_NO_MESSAGEBOX
|
---|