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