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