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