source: trunk/src/gui/dialogs/qmessagebox.cpp@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

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