| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | enum Button { Old_Ok = 1, Old_Cancel = 2, Old_Yes = 3, Old_No = 4, Old_Abort = 5, Old_Retry = 6, | - |
| 12 | Old_Ignore = 7, Old_YesAll = 8, Old_NoAll = 9, Old_ButtonMask = 0xFF, | - |
| 13 | NewButtonMask = 0xFFFFFC00 }; | - |
| 14 | | - |
| 15 | enum DetailButtonLabel { ShowLabel = 0, HideLabel = 1 }; | - |
| 16 | | - |
| 17 | class QMessageBoxDetailsText : public QWidget | - |
| 18 | { | - |
| 19 | public: | - |
| 20 | class TextEdit : public QTextEdit | - |
| 21 | { | - |
| 22 | public: | - |
| 23 | TextEdit(QWidget *parent=0) : QTextEdit(parent) { } | - |
| 24 | void contextMenuEvent(QContextMenuEvent * e) | - |
| 25 | { | - |
| 26 | | - |
| 27 | QMenu *menu = createStandardContextMenu(); | - |
| 28 | menu->setAttribute(Qt::WA_DeleteOnClose); | - |
| 29 | menu->popup(e->globalPos()); | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | } | - |
| 34 | }; | - |
| 35 | | - |
| 36 | QMessageBoxDetailsText(QWidget *parent=0) | - |
| 37 | : QWidget(parent) | - |
| 38 | { | - |
| 39 | QVBoxLayout *layout = new QVBoxLayout; | - |
| 40 | layout->setMargin(0); | - |
| 41 | QFrame *line = new QFrame(this); | - |
| 42 | line->setFrameShape(QFrame::HLine); | - |
| 43 | line->setFrameShadow(QFrame::Sunken); | - |
| 44 | layout->addWidget(line); | - |
| 45 | textEdit = new TextEdit(); | - |
| 46 | textEdit->setFixedHeight(100); | - |
| 47 | textEdit->setFocusPolicy(Qt::NoFocus); | - |
| 48 | textEdit->setReadOnly(true); | - |
| 49 | layout->addWidget(textEdit); | - |
| 50 | setLayout(layout); | - |
| 51 | } | - |
| 52 | void setText(const QString &text) { textEdit->setPlainText(text); } | - |
| 53 | QString text() const { return textEdit->toPlainText(); } | - |
| 54 | private: | - |
| 55 | TextEdit *textEdit; | - |
| 56 | }; | - |
| 57 | | - |
| 58 | | - |
| 59 | class DetailButton : public QPushButton | - |
| 60 | { | - |
| 61 | public: | - |
| 62 | DetailButton(QWidget *parent) : QPushButton(label(ShowLabel), parent) | - |
| 63 | { | - |
| 64 | setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | - |
| 65 | } | - |
| 66 | | - |
| 67 | QString label(DetailButtonLabel label) const | - |
| 68 | { return label == ShowLabel ? QMessageBox::tr("Show Details...") : QMessageBox::tr("Hide Details..."); } | - |
| 69 | | - |
| 70 | void setLabel(DetailButtonLabel lbl) | - |
| 71 | { setText(label(lbl)); } | - |
| 72 | | - |
| 73 | QSize sizeHint() const | - |
| 74 | { | - |
| 75 | ensurePolished(); | - |
| 76 | QStyleOptionButton opt; | - |
| 77 | initStyleOption(&opt); | - |
| 78 | const QFontMetrics fm = fontMetrics(); | - |
| 79 | opt.text = label(ShowLabel); | - |
| 80 | QSize sz = fm.size(Qt::TextShowMnemonic, opt.text); | - |
| 81 | QSize ret = style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this). | - |
| 82 | expandedTo(QApplication::globalStrut()); | - |
| 83 | opt.text = label(HideLabel); | - |
| 84 | sz = fm.size(Qt::TextShowMnemonic, opt.text); | - |
| 85 | ret = ret.expandedTo(style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this). | - |
| 86 | expandedTo(QApplication::globalStrut())); | - |
| 87 | return ret; | - |
| 88 | } | - |
| 89 | }; | - |
| 90 | | - |
| 91 | | - |
| 92 | class QMessageBoxPrivate : public QDialogPrivate | - |
| 93 | { | - |
| 94 | inline QMessageBox* q_func() { return static_cast<QMessageBox *>(q_ptr); } inline const QMessageBox* q_func() const { return static_cast<const QMessageBox *>(q_ptr); } friend class QMessageBox; | - |
| 95 | | - |
| 96 | public: | - |
| 97 | QMessageBoxPrivate() : escapeButton(0), defaultButton(0), clickedButton(0), detailsButton(0), | - |
| 98 | | - |
| 99 | detailsText(0), | - |
| 100 | | - |
| 101 | compatMode(false), autoAddOkButton(true), | - |
| 102 | detectedEscapeButton(0), informativeLabel(0) { } | - |
| 103 | | - |
| 104 | void init(const QString &title = QString(), const QString &text = QString()); | - |
| 105 | void _q_buttonClicked(QAbstractButton *); | - |
| 106 | | - |
| 107 | QAbstractButton *findButton(int button0, int button1, int button2, int flags); | - |
| 108 | void addOldButtons(int button0, int button1, int button2); | - |
| 109 | | - |
| 110 | QAbstractButton *abstractButtonForId(int id) const; | - |
| 111 | int execReturnCode(QAbstractButton *button); | - |
| 112 | | - |
| 113 | void detectEscapeButton(); | - |
| 114 | void updateSize(); | - |
| 115 | int layoutMinimumWidth(); | - |
| 116 | void retranslateStrings(); | - |
| 117 | | - |
| 118 | | - |
| 119 | | - |
| 120 | | - |
| 121 | | - |
| 122 | static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, | - |
| 123 | const QString &title, const QString &text, | - |
| 124 | int button0, int button1, int button2); | - |
| 125 | static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, | - |
| 126 | const QString &title, const QString &text, | - |
| 127 | const QString &button0Text, | - |
| 128 | const QString &button1Text, | - |
| 129 | const QString &button2Text, | - |
| 130 | int defaultButtonNumber, | - |
| 131 | int escapeButtonNumber); | - |
| 132 | | - |
| 133 | static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, | - |
| 134 | QMessageBox::Icon icon, const QString& title, const QString& text, | - |
| 135 | QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton); | - |
| 136 | | - |
| 137 | static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb); | - |
| 138 | | - |
| 139 | QLabel *label; | - |
| 140 | QMessageBox::Icon icon; | - |
| 141 | QLabel *iconLabel; | - |
| 142 | QDialogButtonBox *buttonBox; | - |
| 143 | QList<QAbstractButton *> customButtonList; | - |
| 144 | QAbstractButton *escapeButton; | - |
| 145 | QPushButton *defaultButton; | - |
| 146 | QAbstractButton *clickedButton; | - |
| 147 | DetailButton *detailsButton; | - |
| 148 | | - |
| 149 | QMessageBoxDetailsText *detailsText; | - |
| 150 | | - |
| 151 | bool compatMode; | - |
| 152 | bool autoAddOkButton; | - |
| 153 | QAbstractButton *detectedEscapeButton; | - |
| 154 | QLabel *informativeLabel; | - |
| 155 | QPointer<QObject> receiverToDisconnectOnClose; | - |
| 156 | QByteArray memberToDisconnectOnClose; | - |
| 157 | QByteArray signalToDisconnectOnClose; | - |
| 158 | }; | - |
| 159 | | - |
| 160 | void QMessageBoxPrivate::init(const QString &title, const QString &text) | - |
| 161 | { | - |
| 162 | QMessageBox * const q = q_func(); | - |
| 163 | | - |
| 164 | label = new QLabel; | - |
| 165 | label->setObjectName(QLatin1String("qt_msgbox_label")); | - |
| 166 | label->setTextInteractionFlags(Qt::TextInteractionFlags(q->style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, q))); | - |
| 167 | label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); | - |
| 168 | label->setOpenExternalLinks(true); | - |
| 169 | | - |
| 170 | | - |
| 171 | | - |
| 172 | label->setContentsMargins(2, 0, 0, 0); | - |
| 173 | label->setIndent(9); | - |
| 174 | | - |
| 175 | icon = QMessageBox::NoIcon; | - |
| 176 | iconLabel = new QLabel; | - |
| 177 | iconLabel->setObjectName(QLatin1String("qt_msgboxex_icon_label")); | - |
| 178 | iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | - |
| 179 | | - |
| 180 | buttonBox = new QDialogButtonBox; | - |
| 181 | buttonBox->setObjectName(QLatin1String("qt_msgbox_buttonbox")); | - |
| 182 | buttonBox->setCenterButtons(q->style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, q)); | - |
| 183 | QObject::connect(buttonBox, "2""clicked(QAbstractButton*)", | - |
| 184 | q, "1""_q_buttonClicked(QAbstractButton*)"); | - |
| 185 | | - |
| 186 | QGridLayout *grid = new QGridLayout; | - |
| 187 | | - |
| 188 | grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); | - |
| 189 | grid->addWidget(label, 0, 1, 1, 1); | - |
| 190 | | - |
| 191 | grid->addWidget(buttonBox, 2, 0, 1, 2); | - |
| 192 | grid->setSizeConstraint(QLayout::SetNoConstraint); | - |
| 193 | q->setLayout(grid); | - |
| 194 | | - |
| 195 | if (!title.isEmpty() || !text.isEmpty()) { | - |
| 196 | q->setWindowTitle(title); | - |
| 197 | q->setText(text); | - |
| 198 | } | - |
| 199 | q->setModal(true); | - |
| 200 | | - |
| 201 | | - |
| 202 | | - |
| 203 | | - |
| 204 | | - |
| 205 | | - |
| 206 | retranslateStrings(); | - |
| 207 | } | - |
| 208 | | - |
| 209 | int QMessageBoxPrivate::layoutMinimumWidth() | - |
| 210 | { | - |
| 211 | layout->activate(); | - |
| 212 | return layout->totalMinimumSize().width(); | - |
| 213 | } | - |
| 214 | | - |
| 215 | void QMessageBoxPrivate::updateSize() | - |
| 216 | { | - |
| 217 | QMessageBox * const q = q_func(); | - |
| 218 | | - |
| 219 | if (!q->isVisible()) | - |
| 220 | return; | - |
| 221 | | - |
| 222 | QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size(); | - |
| 223 | | - |
| 224 | | - |
| 225 | | - |
| 226 | | - |
| 227 | int hardLimit = qMin(screenSize.width() - 480, 1000); | - |
| 228 | | - |
| 229 | if (screenSize.width() <= 1024) | - |
| 230 | hardLimit = screenSize.width(); | - |
| 231 | | - |
| 232 | | - |
| 233 | | - |
| 234 | | - |
| 235 | | - |
| 236 | | - |
| 237 | int softLimit = qMin(screenSize.width()/2, 500); | - |
| 238 | | - |
| 239 | | - |
| 240 | | - |
| 241 | | - |
| 242 | | - |
| 243 | if (informativeLabel) | - |
| 244 | informativeLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); | - |
| 245 | | - |
| 246 | label->setWordWrap(false); | - |
| 247 | int width = layoutMinimumWidth(); | - |
| 248 | | - |
| 249 | if (width > softLimit) { | - |
| 250 | label->setWordWrap(true); | - |
| 251 | width = qMax(softLimit, layoutMinimumWidth()); | - |
| 252 | | - |
| 253 | if (width > hardLimit) { | - |
| 254 | label->d_func()->ensureTextControl(); | - |
| 255 | if (QWidgetTextControl *control = label->d_func()->control) { | - |
| 256 | QTextOption opt = control->document()->defaultTextOption(); | - |
| 257 | opt.setWrapMode(QTextOption::WrapAnywhere); | - |
| 258 | control->document()->setDefaultTextOption(opt); | - |
| 259 | } | - |
| 260 | width = hardLimit; | - |
| 261 | } | - |
| 262 | } | - |
| 263 | | - |
| 264 | if (informativeLabel) { | - |
| 265 | label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); | - |
| 266 | QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Preferred); | - |
| 267 | policy.setHeightForWidth(true); | - |
| 268 | informativeLabel->setSizePolicy(policy); | - |
| 269 | width = qMax(width, layoutMinimumWidth()); | - |
| 270 | if (width > hardLimit) { | - |
| 271 | informativeLabel->d_func()->ensureTextControl(); | - |
| 272 | if (QWidgetTextControl *control = informativeLabel->d_func()->control) { | - |
| 273 | QTextOption opt = control->document()->defaultTextOption(); | - |
| 274 | opt.setWrapMode(QTextOption::WrapAnywhere); | - |
| 275 | control->document()->setDefaultTextOption(opt); | - |
| 276 | } | - |
| 277 | width = hardLimit; | - |
| 278 | } | - |
| 279 | policy.setHeightForWidth(label->wordWrap()); | - |
| 280 | label->setSizePolicy(policy); | - |
| 281 | } | - |
| 282 | | - |
| 283 | QFontMetrics fm(QApplication::font("QMdiSubWindowTitleBar")); | - |
| 284 | int windowTitleWidth = qMin(fm.width(q->windowTitle()) + 50, hardLimit); | - |
| 285 | if (windowTitleWidth > width) | - |
| 286 | width = windowTitleWidth; | - |
| 287 | | - |
| 288 | layout->activate(); | - |
| 289 | int height = (layout->hasHeightForWidth()) | - |
| 290 | ? layout->totalHeightForWidth(width) | - |
| 291 | : layout->totalMinimumSize().height(); | - |
| 292 | | - |
| 293 | q->setFixedSize(width, height); | - |
| 294 | QCoreApplication::removePostedEvents(q, QEvent::LayoutRequest); | - |
| 295 | } | - |
| 296 | static int oldButton(int button) | - |
| 297 | { | - |
| 298 | switch (button & QMessageBox::ButtonMask) { | - |
| 299 | case QMessageBox::Ok: | - |
| 300 | return Old_Ok; | - |
| 301 | case QMessageBox::Cancel: | - |
| 302 | return Old_Cancel; | - |
| 303 | case QMessageBox::Yes: | - |
| 304 | return Old_Yes; | - |
| 305 | case QMessageBox::No: | - |
| 306 | return Old_No; | - |
| 307 | case QMessageBox::Abort: | - |
| 308 | return Old_Abort; | - |
| 309 | case QMessageBox::Retry: | - |
| 310 | return Old_Retry; | - |
| 311 | case QMessageBox::Ignore: | - |
| 312 | return Old_Ignore; | - |
| 313 | case QMessageBox::YesToAll: | - |
| 314 | return Old_YesAll; | - |
| 315 | case QMessageBox::NoToAll: | - |
| 316 | return Old_NoAll; | - |
| 317 | default: | - |
| 318 | return 0; | - |
| 319 | } | - |
| 320 | } | - |
| 321 | | - |
| 322 | int QMessageBoxPrivate::execReturnCode(QAbstractButton *button) | - |
| 323 | { | - |
| 324 | int ret = buttonBox->standardButton(button); | - |
| 325 | if (ret == QMessageBox::NoButton) { | - |
| 326 | ret = customButtonList.indexOf(button); | - |
| 327 | } else if (compatMode) { | - |
| 328 | ret = oldButton(ret); | - |
| 329 | } | - |
| 330 | return ret; | - |
| 331 | } | - |
| 332 | | - |
| 333 | void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button) | - |
| 334 | { | - |
| 335 | QMessageBox * const q = q_func(); | - |
| 336 | | - |
| 337 | if (detailsButton && detailsText && button == detailsButton) { | - |
| 338 | detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel); | - |
| 339 | detailsText->setHidden(!detailsText->isHidden()); | - |
| 340 | updateSize(); | - |
| 341 | } else | - |
| 342 | | - |
| 343 | { | - |
| 344 | clickedButton = button; | - |
| 345 | q->done(execReturnCode(button)); | - |
| 346 | q->buttonClicked(button); | - |
| 347 | | - |
| 348 | if (receiverToDisconnectOnClose) { | - |
| 349 | QObject::disconnect(q, signalToDisconnectOnClose, receiverToDisconnectOnClose, | - |
| 350 | memberToDisconnectOnClose); | - |
| 351 | receiverToDisconnectOnClose = 0; | - |
| 352 | } | - |
| 353 | signalToDisconnectOnClose.clear(); | - |
| 354 | memberToDisconnectOnClose.clear(); | - |
| 355 | } | - |
| 356 | } | - |
| 357 | QMessageBox::QMessageBox(QWidget *parent) | - |
| 358 | : QDialog(*new QMessageBoxPrivate, parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint) | - |
| 359 | { | - |
| 360 | QMessageBoxPrivate * const d = d_func(); | - |
| 361 | d->init(); | - |
| 362 | } | - |
| 363 | QMessageBox::QMessageBox(Icon icon, const QString &title, const QString &text, | - |
| 364 | StandardButtons buttons, QWidget *parent, | - |
| 365 | Qt::WindowFlags f) | - |
| 366 | : QDialog(*new QMessageBoxPrivate, parent, f | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint) | - |
| 367 | { | - |
| 368 | QMessageBoxPrivate * const d = d_func(); | - |
| 369 | d->init(title, text); | - |
| 370 | setIcon(icon); | - |
| 371 | if (buttons != NoButton) | - |
| 372 | setStandardButtons(buttons); | - |
| 373 | } | - |
| 374 | | - |
| 375 | | - |
| 376 | | - |
| 377 | | - |
| 378 | QMessageBox::~QMessageBox() | - |
| 379 | { | - |
| 380 | } | - |
| 381 | void QMessageBox::addButton(QAbstractButton *button, ButtonRole role) | - |
| 382 | { | - |
| 383 | QMessageBoxPrivate * const d = d_func(); | - |
| 384 | if (!button) | - |
| 385 | return; | - |
| 386 | removeButton(button); | - |
| 387 | d->buttonBox->addButton(button, (QDialogButtonBox::ButtonRole)role); | - |
| 388 | d->customButtonList.append(button); | - |
| 389 | d->autoAddOkButton = false; | - |
| 390 | } | - |
| 391 | QPushButton *QMessageBox::addButton(const QString& text, ButtonRole role) | - |
| 392 | { | - |
| 393 | QMessageBoxPrivate * const d = d_func(); | - |
| 394 | QPushButton *pushButton = new QPushButton(text); | - |
| 395 | addButton(pushButton, role); | - |
| 396 | d->updateSize(); | - |
| 397 | return pushButton; | - |
| 398 | } | - |
| 399 | QPushButton *QMessageBox::addButton(StandardButton button) | - |
| 400 | { | - |
| 401 | QMessageBoxPrivate * const d = d_func(); | - |
| 402 | QPushButton *pushButton = d->buttonBox->addButton((QDialogButtonBox::StandardButton)button); | - |
| 403 | if (pushButton) | - |
| 404 | d->autoAddOkButton = false; | - |
| 405 | return pushButton; | - |
| 406 | } | - |
| 407 | void QMessageBox::removeButton(QAbstractButton *button) | - |
| 408 | { | - |
| 409 | QMessageBoxPrivate * const d = d_func(); | - |
| 410 | d->customButtonList.removeAll(button); | - |
| 411 | if (d->escapeButton == button) | - |
| 412 | d->escapeButton = 0; | - |
| 413 | if (d->defaultButton == button) | - |
| 414 | d->defaultButton = 0; | - |
| 415 | d->buttonBox->removeButton(button); | - |
| 416 | d->updateSize(); | - |
| 417 | } | - |
| 418 | void QMessageBox::setStandardButtons(StandardButtons buttons) | - |
| 419 | { | - |
| 420 | QMessageBoxPrivate * const d = d_func(); | - |
| 421 | d->buttonBox->setStandardButtons(QDialogButtonBox::StandardButtons(int(buttons))); | - |
| 422 | | - |
| 423 | QList<QAbstractButton *> buttonList = d->buttonBox->buttons(); | - |
| 424 | if (!buttonList.contains(d->escapeButton)) | - |
| 425 | d->escapeButton = 0; | - |
| 426 | if (!buttonList.contains(d->defaultButton)) | - |
| 427 | d->defaultButton = 0; | - |
| 428 | d->autoAddOkButton = false; | - |
| 429 | d->updateSize(); | - |
| 430 | } | - |
| 431 | | - |
| 432 | QMessageBox::StandardButtons QMessageBox::standardButtons() const | - |
| 433 | { | - |
| 434 | const QMessageBoxPrivate * const d = d_func(); | - |
| 435 | return QMessageBox::StandardButtons(int(d->buttonBox->standardButtons())); | - |
| 436 | } | - |
| 437 | QMessageBox::StandardButton QMessageBox::standardButton(QAbstractButton *button) const | - |
| 438 | { | - |
| 439 | const QMessageBoxPrivate * const d = d_func(); | - |
| 440 | return (QMessageBox::StandardButton)d->buttonBox->standardButton(button); | - |
| 441 | } | - |
| 442 | QAbstractButton *QMessageBox::button(StandardButton which) const | - |
| 443 | { | - |
| 444 | const QMessageBoxPrivate * const d = d_func(); | - |
| 445 | return d->buttonBox->button(QDialogButtonBox::StandardButton(which)); | - |
| 446 | } | - |
| 447 | QAbstractButton *QMessageBox::escapeButton() const | - |
| 448 | { | - |
| 449 | const QMessageBoxPrivate * const d = d_func(); | - |
| 450 | return d->escapeButton; | - |
| 451 | } | - |
| 452 | void QMessageBox::setEscapeButton(QAbstractButton *button) | - |
| 453 | { | - |
| 454 | QMessageBoxPrivate * const d = d_func(); | - |
| 455 | if (d->buttonBox->buttons().contains(button)) | - |
| 456 | d->escapeButton = button; | - |
| 457 | } | - |
| 458 | void QMessageBox::setEscapeButton(QMessageBox::StandardButton button) | - |
| 459 | { | - |
| 460 | QMessageBoxPrivate * const d = d_func(); | - |
| 461 | setEscapeButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button))); | - |
| 462 | } | - |
| 463 | | - |
| 464 | void QMessageBoxPrivate::detectEscapeButton() | - |
| 465 | { | - |
| 466 | if (escapeButton) { | - |
| 467 | detectedEscapeButton = escapeButton; | - |
| 468 | return; | - |
| 469 | } | - |
| 470 | | - |
| 471 | | - |
| 472 | detectedEscapeButton = buttonBox->button(QDialogButtonBox::Cancel); | - |
| 473 | if (detectedEscapeButton) | - |
| 474 | return; | - |
| 475 | | - |
| 476 | | - |
| 477 | const QList<QAbstractButton *> buttons = buttonBox->buttons(); | - |
| 478 | if (buttons.count() == 1) { | - |
| 479 | detectedEscapeButton = buttons.first(); | - |
| 480 | return; | - |
| 481 | } | - |
| 482 | | - |
| 483 | | - |
| 484 | for (int i = 0; i < buttons.count(); i++) { | - |
| 485 | if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::RejectRole) { | - |
| 486 | if (detectedEscapeButton) { | - |
| 487 | detectedEscapeButton = 0; | - |
| 488 | break; | - |
| 489 | } | - |
| 490 | detectedEscapeButton = buttons.at(i); | - |
| 491 | } | - |
| 492 | } | - |
| 493 | if (detectedEscapeButton) | - |
| 494 | return; | - |
| 495 | | - |
| 496 | | - |
| 497 | for (int i = 0; i < buttons.count(); i++) { | - |
| 498 | if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::NoRole) { | - |
| 499 | if (detectedEscapeButton) { | - |
| 500 | detectedEscapeButton = 0; | - |
| 501 | break; | - |
| 502 | } | - |
| 503 | detectedEscapeButton = buttons.at(i); | - |
| 504 | } | - |
| 505 | } | - |
| 506 | } | - |
| 507 | QAbstractButton *QMessageBox::clickedButton() const | - |
| 508 | { | - |
| 509 | const QMessageBoxPrivate * const d = d_func(); | - |
| 510 | return d->clickedButton; | - |
| 511 | } | - |
| 512 | QPushButton *QMessageBox::defaultButton() const | - |
| 513 | { | - |
| 514 | const QMessageBoxPrivate * const d = d_func(); | - |
| 515 | return d->defaultButton; | - |
| 516 | } | - |
| 517 | void QMessageBox::setDefaultButton(QPushButton *button) | - |
| 518 | { | - |
| 519 | QMessageBoxPrivate * const d = d_func(); | - |
| 520 | if (!d->buttonBox->buttons().contains(button)) | - |
| 521 | return; | - |
| 522 | d->defaultButton = button; | - |
| 523 | button->setDefault(true); | - |
| 524 | button->setFocus(); | - |
| 525 | } | - |
| 526 | void QMessageBox::setDefaultButton(QMessageBox::StandardButton button) | - |
| 527 | { | - |
| 528 | QMessageBoxPrivate * const d = d_func(); | - |
| 529 | setDefaultButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button))); | - |
| 530 | } | - |
| 531 | QString QMessageBox::text() const | - |
| 532 | { | - |
| 533 | const QMessageBoxPrivate * const d = d_func(); | - |
| 534 | return d->label->text(); | - |
| 535 | } | - |
| 536 | | - |
| 537 | void QMessageBox::setText(const QString &text) | - |
| 538 | { | - |
| 539 | QMessageBoxPrivate * const d = d_func(); | - |
| 540 | d->label->setText(text); | - |
| 541 | d->label->setWordWrap(d->label->textFormat() == Qt::RichText | - |
| 542 | || (d->label->textFormat() == Qt::AutoText && Qt::mightBeRichText(text))); | - |
| 543 | d->updateSize(); | - |
| 544 | } | - |
| 545 | QMessageBox::Icon QMessageBox::icon() const | - |
| 546 | { | - |
| 547 | const QMessageBoxPrivate * const d = d_func(); | - |
| 548 | return d->icon; | - |
| 549 | } | - |
| 550 | | - |
| 551 | void QMessageBox::setIcon(Icon icon) | - |
| 552 | { | - |
| 553 | QMessageBoxPrivate * const d = d_func(); | - |
| 554 | setIconPixmap(QMessageBoxPrivate::standardIcon((QMessageBox::Icon)icon, | - |
| 555 | this)); | - |
| 556 | d->icon = icon; | - |
| 557 | } | - |
| 558 | QPixmap QMessageBox::iconPixmap() const | - |
| 559 | { | - |
| 560 | const QMessageBoxPrivate * const d = d_func(); | - |
| 561 | if (d->iconLabel && d->iconLabel->pixmap()) | - |
| 562 | return *d->iconLabel->pixmap(); | - |
| 563 | return QPixmap(); | - |
| 564 | } | - |
| 565 | | - |
| 566 | void QMessageBox::setIconPixmap(const QPixmap &pixmap) | - |
| 567 | { | - |
| 568 | QMessageBoxPrivate * const d = d_func(); | - |
| 569 | d->iconLabel->setPixmap(pixmap); | - |
| 570 | d->updateSize(); | - |
| 571 | d->icon = NoIcon; | - |
| 572 | } | - |
| 573 | Qt::TextFormat QMessageBox::textFormat() const | - |
| 574 | { | - |
| 575 | const QMessageBoxPrivate * const d = d_func(); | - |
| 576 | return d->label->textFormat(); | - |
| 577 | } | - |
| 578 | | - |
| 579 | void QMessageBox::setTextFormat(Qt::TextFormat format) | - |
| 580 | { | - |
| 581 | QMessageBoxPrivate * const d = d_func(); | - |
| 582 | d->label->setTextFormat(format); | - |
| 583 | d->label->setWordWrap(format == Qt::RichText | - |
| 584 | || (format == Qt::AutoText && Qt::mightBeRichText(d->label->text()))); | - |
| 585 | d->updateSize(); | - |
| 586 | } | - |
| 587 | | - |
| 588 | | - |
| 589 | | - |
| 590 | | - |
| 591 | bool QMessageBox::event(QEvent *e) | - |
| 592 | { | - |
| 593 | bool result =QDialog::event(e); | - |
| 594 | switch (e->type()) { | - |
| 595 | case QEvent::LayoutRequest: | - |
| 596 | d_func()->updateSize(); | - |
| 597 | break; | - |
| 598 | case QEvent::LanguageChange: | - |
| 599 | d_func()->retranslateStrings(); | - |
| 600 | break; | - |
| 601 | default: | - |
| 602 | break; | - |
| 603 | } | - |
| 604 | return result; | - |
| 605 | } | - |
| 606 | | - |
| 607 | | - |
| 608 | | - |
| 609 | | - |
| 610 | void QMessageBox::resizeEvent(QResizeEvent *event) | - |
| 611 | { | - |
| 612 | QDialog::resizeEvent(event); | - |
| 613 | } | - |
| 614 | | - |
| 615 | | - |
| 616 | | - |
| 617 | | - |
| 618 | void QMessageBox::closeEvent(QCloseEvent *e) | - |
| 619 | { | - |
| 620 | QMessageBoxPrivate * const d = d_func(); | - |
| 621 | if (!d->detectedEscapeButton) { | - |
| 622 | e->ignore(); | - |
| 623 | return; | - |
| 624 | } | - |
| 625 | QDialog::closeEvent(e); | - |
| 626 | d->clickedButton = d->detectedEscapeButton; | - |
| 627 | setResult(d->execReturnCode(d->detectedEscapeButton)); | - |
| 628 | } | - |
| 629 | | - |
| 630 | | - |
| 631 | | - |
| 632 | | - |
| 633 | void QMessageBox::changeEvent(QEvent *ev) | - |
| 634 | { | - |
| 635 | QMessageBoxPrivate * const d = d_func(); | - |
| 636 | switch (ev->type()) { | - |
| 637 | case QEvent::StyleChange: | - |
| 638 | { | - |
| 639 | if (d->icon != NoIcon) | - |
| 640 | setIcon(d->icon); | - |
| 641 | Qt::TextInteractionFlags flags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this)); | - |
| 642 | d->label->setTextInteractionFlags(flags); | - |
| 643 | d->buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this)); | - |
| 644 | if (d->informativeLabel) | - |
| 645 | d->informativeLabel->setTextInteractionFlags(flags); | - |
| 646 | | - |
| 647 | } | - |
| 648 | case QEvent::FontChange: | - |
| 649 | case QEvent::ApplicationFontChange: | - |
| 650 | | - |
| 651 | | - |
| 652 | | - |
| 653 | | - |
| 654 | | - |
| 655 | | - |
| 656 | | - |
| 657 | default: | - |
| 658 | break; | - |
| 659 | } | - |
| 660 | QDialog::changeEvent(ev); | - |
| 661 | } | - |
| 662 | | - |
| 663 | | - |
| 664 | | - |
| 665 | | - |
| 666 | void QMessageBox::keyPressEvent(QKeyEvent *e) | - |
| 667 | { | - |
| 668 | QMessageBoxPrivate * const d = d_func(); | - |
| 669 | if (e->key() == Qt::Key_Escape | - |
| 670 | | - |
| 671 | | - |
| 672 | | - |
| 673 | ) { | - |
| 674 | if (d->detectedEscapeButton) { | - |
| 675 | | - |
| 676 | | - |
| 677 | | - |
| 678 | d->detectedEscapeButton->click(); | - |
| 679 | | - |
| 680 | } | - |
| 681 | return; | - |
| 682 | } | - |
| 683 | if (!(e->modifiers() & Qt::AltModifier)) { | - |
| 684 | int key = e->key() & ~Qt::MODIFIER_MASK; | - |
| 685 | if (key) { | - |
| 686 | const QList<QAbstractButton *> buttons = d->buttonBox->buttons(); | - |
| 687 | for (int i = 0; i < buttons.count(); ++i) { | - |
| 688 | QAbstractButton *pb = buttons.at(i); | - |
| 689 | QKeySequence shortcut = pb->shortcut(); | - |
| 690 | if (!shortcut.isEmpty() && key == int(shortcut[0] & ~Qt::MODIFIER_MASK)) { | - |
| 691 | pb->animateClick(); | - |
| 692 | return; | - |
| 693 | } | - |
| 694 | } | - |
| 695 | } | - |
| 696 | } | - |
| 697 | | - |
| 698 | QDialog::keyPressEvent(e); | - |
| 699 | } | - |
| 700 | void QMessageBox::open(QObject *receiver, const char *member) | - |
| 701 | { | - |
| 702 | QMessageBoxPrivate * const d = d_func(); | - |
| 703 | const char *signal = member && strchr(member, '*') ? "2""buttonClicked(QAbstractButton*)" | - |
| 704 | : "2""finished(int)"; | - |
| 705 | connect(this, signal, receiver, member); | - |
| 706 | d->signalToDisconnectOnClose = signal; | - |
| 707 | d->receiverToDisconnectOnClose = receiver; | - |
| 708 | d->memberToDisconnectOnClose = member; | - |
| 709 | QDialog::open(); | - |
| 710 | } | - |
| 711 | QList<QAbstractButton *> QMessageBox::buttons() const | - |
| 712 | { | - |
| 713 | const QMessageBoxPrivate * const d = d_func(); | - |
| 714 | return d->buttonBox->buttons(); | - |
| 715 | } | - |
| 716 | QMessageBox::ButtonRole QMessageBox::buttonRole(QAbstractButton *button) const | - |
| 717 | { | - |
| 718 | const QMessageBoxPrivate * const d = d_func(); | - |
| 719 | return QMessageBox::ButtonRole(d->buttonBox->buttonRole(button)); | - |
| 720 | } | - |
| 721 | | - |
| 722 | | - |
| 723 | | - |
| 724 | | - |
| 725 | void QMessageBox::showEvent(QShowEvent *e) | - |
| 726 | { | - |
| 727 | QMessageBoxPrivate * const d = d_func(); | - |
| 728 | if (d->autoAddOkButton) { | - |
| 729 | addButton(Ok); | - |
| 730 | | - |
| 731 | | - |
| 732 | | - |
| 733 | } | - |
| 734 | if (d->detailsButton) | - |
| 735 | addButton(d->detailsButton, QMessageBox::ActionRole); | - |
| 736 | d->detectEscapeButton(); | - |
| 737 | d->updateSize(); | - |
| 738 | | - |
| 739 | | - |
| 740 | QAccessibleEvent event(this, QAccessible::Alert); | - |
| 741 | QAccessible::updateAccessibility(&event); | - |
| 742 | | - |
| 743 | | - |
| 744 | | - |
| 745 | | - |
| 746 | | - |
| 747 | | - |
| 748 | | - |
| 749 | QDialog::showEvent(e); | - |
| 750 | } | - |
| 751 | | - |
| 752 | | - |
| 753 | static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, | - |
| 754 | QMessageBox::Icon icon, | - |
| 755 | const QString& title, const QString& text, | - |
| 756 | QMessageBox::StandardButtons buttons, | - |
| 757 | QMessageBox::StandardButton defaultButton) | - |
| 758 | { | - |
| 759 | | - |
| 760 | | - |
| 761 | if (defaultButton && !(buttons & defaultButton)) | - |
| 762 | return (QMessageBox::StandardButton) | - |
| 763 | QMessageBoxPrivate::showOldMessageBox(parent, icon, title, | - |
| 764 | text, int(buttons), | - |
| 765 | int(defaultButton), 0); | - |
| 766 | | - |
| 767 | QMessageBox msgBox(icon, title, text, QMessageBox::NoButton, parent); | - |
| 768 | QDialogButtonBox *buttonBox = msgBox.findChild<QDialogButtonBox*>(); | - |
| 769 | qt_noop(); | - |
| 770 | | - |
| 771 | uint mask = QMessageBox::FirstButton; | - |
| 772 | while (mask <= QMessageBox::LastButton) { | - |
| 773 | uint sb = buttons & mask; | - |
| 774 | mask <<= 1; | - |
| 775 | if (!sb) | - |
| 776 | continue; | - |
| 777 | QPushButton *button = msgBox.addButton((QMessageBox::StandardButton)sb); | - |
| 778 | | - |
| 779 | if (msgBox.defaultButton()) | - |
| 780 | continue; | - |
| 781 | if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) | - |
| 782 | || (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton))) | - |
| 783 | msgBox.setDefaultButton(button); | - |
| 784 | } | - |
| 785 | if (msgBox.exec() == -1) | - |
| 786 | return QMessageBox::Cancel; | - |
| 787 | return msgBox.standardButton(msgBox.clickedButton()); | - |
| 788 | } | - |
| 789 | QMessageBox::StandardButton QMessageBox::information(QWidget *parent, const QString &title, | - |
| 790 | const QString& text, StandardButtons buttons, | - |
| 791 | StandardButton defaultButton) | - |
| 792 | { | - |
| 793 | return showNewMessageBox(parent, Information, title, text, buttons, | - |
| 794 | defaultButton); | - |
| 795 | } | - |
| 796 | QMessageBox::StandardButton QMessageBox::question(QWidget *parent, const QString &title, | - |
| 797 | const QString& text, StandardButtons buttons, | - |
| 798 | StandardButton defaultButton) | - |
| 799 | { | - |
| 800 | return showNewMessageBox(parent, Question, title, text, buttons, defaultButton); | - |
| 801 | } | - |
| 802 | QMessageBox::StandardButton QMessageBox::warning(QWidget *parent, const QString &title, | - |
| 803 | const QString& text, StandardButtons buttons, | - |
| 804 | StandardButton defaultButton) | - |
| 805 | { | - |
| 806 | return showNewMessageBox(parent, Warning, title, text, buttons, defaultButton); | - |
| 807 | } | - |
| 808 | QMessageBox::StandardButton QMessageBox::critical(QWidget *parent, const QString &title, | - |
| 809 | const QString& text, StandardButtons buttons, | - |
| 810 | StandardButton defaultButton) | - |
| 811 | { | - |
| 812 | return showNewMessageBox(parent, Critical, title, text, buttons, defaultButton); | - |
| 813 | } | - |
| 814 | void QMessageBox::about(QWidget *parent, const QString &title, const QString &text) | - |
| 815 | { | - |
| 816 | QMessageBox *msgBox = new QMessageBox(title, text, Information, 0, 0, 0, parent | - |
| 817 | | - |
| 818 | | - |
| 819 | | - |
| 820 | ); | - |
| 821 | msgBox->setAttribute(Qt::WA_DeleteOnClose); | - |
| 822 | QIcon icon = msgBox->windowIcon(); | - |
| 823 | QSize size = icon.actualSize(QSize(64, 64)); | - |
| 824 | msgBox->setIconPixmap(icon.pixmap(size)); | - |
| 825 | msgBox->exec(); | - |
| 826 | | - |
| 827 | } | - |
| 828 | void QMessageBox::aboutQt(QWidget *parent, const QString &title) | - |
| 829 | { | - |
| 830 | QString translatedTextAboutQtCaption; | - |
| 831 | translatedTextAboutQtCaption = QMessageBox::tr( | - |
| 832 | "<h3>About Qt</h3>" | - |
| 833 | "<p>This program uses Qt version %1.</p>" | - |
| 834 | ).arg(QLatin1String("5.0.1"2")); | - |
| 835 | QString translatedTextAboutQtText; | - |
| 836 | translatedTextAboutQtText = QMessageBox::tr( | - |
| 837 | "<p>Qt is a C++ toolkit for cross-platform application " | - |
| 838 | "development.</p>" | - |
| 839 | "<p>Qt provides single-source portability across all major desktop " | - |
| 840 | "operating systems. It is also available for embedded Linux and other " | - |
| 841 | "embedded and mobile operating systems.</p>" | - |
| 842 | "<p>Qt is available under three different licensing options designed " | - |
| 843 | "to accommodate the needs of our various users.</p>" | - |
| 844 | "<p>Qt licensed under our commercial license agreement is appropriate " | - |
| 845 | "for development of proprietary/commercial software where you do not " | - |
| 846 | "want to share any source code with third parties or otherwise cannot " | - |
| 847 | "comply with the terms of the GNU LGPL version 2.1 or GNU GPL version " | - |
| 848 | "3.0.</p>" | - |
| 849 | "<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the " | - |
| 850 | "development of Qt applications provided you can comply with the terms " | - |
| 851 | "and conditions of the GNU LGPL version 2.1.</p>" | - |
| 852 | "<p>Qt licensed under the GNU General Public License version 3.0 is " | - |
| 853 | "appropriate for the development of Qt applications where you wish to " | - |
| 854 | "use such applications in combination with software subject to the " | - |
| 855 | "terms of the GNU GPL version 3.0 or where you are otherwise willing " | - |
| 856 | "to comply with the terms of the GNU GPL version 3.0.</p>" | - |
| 857 | "<p>Please see <a href=\"http://qt.digia.com/Product/Licensing/\">qt.digia.com/Product/Licensing</a> " | - |
| 858 | "for an overview of Qt licensing.</p>" | - |
| 859 | "<p>Copyright (C) 20122013 Digia Plc and/or its subsidiary(-ies) and other " | - |
| 860 | "contributors.</p>" | - |
| 861 | "<p>Qt and the Qt logo are trademarks of Digia Plc and/or its subsidiary(-ies).</p>" | - |
| 862 | "<p>Qt is developed as an open source project on " | - |
| 863 | "<a href=\"http://qt-project.org/\">qt-project.org</a>.</p>" | - |
| 864 | "<p>Qt is a Digia product. See <a href=\"http://qt.digia.com/\">qt.digia.com</a> " | - |
| 865 | "for more information.</p>" | - |
| 866 | ); | - |
| 867 | QMessageBox *msgBox = new QMessageBox(parent); | - |
| 868 | msgBox->setAttribute(Qt::WA_DeleteOnClose); | - |
| 869 | msgBox->setWindowTitle(title.isEmpty() ? tr("About Qt") : title); | - |
| 870 | msgBox->setText(translatedTextAboutQtCaption); | - |
| 871 | msgBox->setInformativeText(translatedTextAboutQtText); | - |
| 872 | | - |
| 873 | QPixmap pm(QLatin1String(":/qt-project.org/qmessagebox/images/qtlogo-64.png")); | - |
| 874 | if (!pm.isNull()) partially evaluated: !pm.isNull()| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 875 | msgBox->setIconPixmap(pm); executed: msgBox->setIconPixmap(pm);Execution Count:1 | 1 |
| 876 | msgBox->exec(); | - |
| 877 | | - |
| 878 | } executed: }Execution Count:1 | 1 |
| 879 | | - |
| 880 | | - |
| 881 | | - |
| 882 | | - |
| 883 | static QMessageBox::StandardButton newButton(int button) | - |
| 884 | { | - |
| 885 | | - |
| 886 | if (button == QMessageBox::NoButton || (button & NewButtonMask)) | - |
| 887 | return QMessageBox::StandardButton(button & QMessageBox::ButtonMask); | - |
| 888 | return QMessageBox::NoButton; | - |
| 889 | | - |
| 890 | } | - |
| 891 | | - |
| 892 | static bool detectedCompat(int button0, int button1, int button2) | - |
| 893 | { | - |
| 894 | if (button0 != 0 && !(button0 & NewButtonMask)) | - |
| 895 | return true; | - |
| 896 | if (button1 != 0 && !(button1 & NewButtonMask)) | - |
| 897 | return true; | - |
| 898 | if (button2 != 0 && !(button2 & NewButtonMask)) | - |
| 899 | return true; | - |
| 900 | return false; | - |
| 901 | } | - |
| 902 | | - |
| 903 | QAbstractButton *QMessageBoxPrivate::findButton(int button0, int button1, int button2, int flags) | - |
| 904 | { | - |
| 905 | QMessageBox * const q = q_func(); | - |
| 906 | int button = 0; | - |
| 907 | | - |
| 908 | if (button0 & flags) { | - |
| 909 | button = button0; | - |
| 910 | } else if (button1 & flags) { | - |
| 911 | button = button1; | - |
| 912 | } else if (button2 & flags) { | - |
| 913 | button = button2; | - |
| 914 | } | - |
| 915 | return q->button(newButton(button)); | - |
| 916 | } | - |
| 917 | | - |
| 918 | void QMessageBoxPrivate::addOldButtons(int button0, int button1, int button2) | - |
| 919 | { | - |
| 920 | QMessageBox * const q = q_func(); | - |
| 921 | q->addButton(newButton(button0)); | - |
| 922 | q->addButton(newButton(button1)); | - |
| 923 | q->addButton(newButton(button2)); | - |
| 924 | q->setDefaultButton( | - |
| 925 | static_cast<QPushButton *>(findButton(button0, button1, button2, QMessageBox::Default))); | - |
| 926 | q->setEscapeButton(findButton(button0, button1, button2, QMessageBox::Escape)); | - |
| 927 | compatMode = detectedCompat(button0, button1, button2); | - |
| 928 | } | - |
| 929 | | - |
| 930 | QAbstractButton *QMessageBoxPrivate::abstractButtonForId(int id) const | - |
| 931 | { | - |
| 932 | const QMessageBox * const q = q_func(); | - |
| 933 | QAbstractButton *result = customButtonList.value(id); | - |
| 934 | if (result) | - |
| 935 | return result; | - |
| 936 | if (id & QMessageBox::FlagMask) | - |
| 937 | return 0; | - |
| 938 | return q->button(newButton(id)); | - |
| 939 | } | - |
| 940 | | - |
| 941 | int QMessageBoxPrivate::showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, | - |
| 942 | const QString &title, const QString &text, | - |
| 943 | int button0, int button1, int button2) | - |
| 944 | { | - |
| 945 | QMessageBox messageBox(icon, title, text, QMessageBox::NoButton, parent); | - |
| 946 | messageBox.d_func()->addOldButtons(button0, button1, button2); | - |
| 947 | return messageBox.exec(); | - |
| 948 | } | - |
| 949 | | - |
| 950 | int QMessageBoxPrivate::showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, | - |
| 951 | const QString &title, const QString &text, | - |
| 952 | const QString &button0Text, | - |
| 953 | const QString &button1Text, | - |
| 954 | const QString &button2Text, | - |
| 955 | int defaultButtonNumber, | - |
| 956 | int escapeButtonNumber) | - |
| 957 | { | - |
| 958 | QMessageBox messageBox(icon, title, text, QMessageBox::NoButton, parent); | - |
| 959 | QString myButton0Text = button0Text; | - |
| 960 | if (myButton0Text.isEmpty()) | - |
| 961 | myButton0Text = QDialogButtonBox::tr("OK"); | - |
| 962 | messageBox.addButton(myButton0Text, QMessageBox::ActionRole); | - |
| 963 | if (!button1Text.isEmpty()) | - |
| 964 | messageBox.addButton(button1Text, QMessageBox::ActionRole); | - |
| 965 | if (!button2Text.isEmpty()) | - |
| 966 | messageBox.addButton(button2Text, QMessageBox::ActionRole); | - |
| 967 | | - |
| 968 | const QList<QAbstractButton *> &buttonList = messageBox.d_func()->customButtonList; | - |
| 969 | messageBox.setDefaultButton(static_cast<QPushButton *>(buttonList.value(defaultButtonNumber))); | - |
| 970 | messageBox.setEscapeButton(buttonList.value(escapeButtonNumber)); | - |
| 971 | | - |
| 972 | return messageBox.exec(); | - |
| 973 | } | - |
| 974 | | - |
| 975 | void QMessageBoxPrivate::retranslateStrings() | - |
| 976 | { | - |
| 977 | | - |
| 978 | if (detailsButton) | - |
| 979 | detailsButton->setLabel(detailsText->isHidden() ? ShowLabel : HideLabel); | - |
| 980 | | - |
| 981 | } | - |
| 982 | QMessageBox::QMessageBox(const QString &title, const QString &text, Icon icon, | - |
| 983 | int button0, int button1, int button2, QWidget *parent, | - |
| 984 | Qt::WindowFlags f) | - |
| 985 | : QDialog(*new QMessageBoxPrivate, parent, | - |
| 986 | f | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint) | - |
| 987 | { | - |
| 988 | QMessageBoxPrivate * const d = d_func(); | - |
| 989 | d->init(title, text); | - |
| 990 | setIcon(icon); | - |
| 991 | d->addOldButtons(button0, button1, button2); | - |
| 992 | } | - |
| 993 | int QMessageBox::information(QWidget *parent, const QString &title, const QString& text, | - |
| 994 | int button0, int button1, int button2) | - |
| 995 | { | - |
| 996 | return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text, | - |
| 997 | button0, button1, button2); | - |
| 998 | } | - |
| 999 | int QMessageBox::information(QWidget *parent, const QString &title, const QString& text, | - |
| 1000 | const QString& button0Text, const QString& button1Text, | - |
| 1001 | const QString& button2Text, int defaultButtonNumber, | - |
| 1002 | int escapeButtonNumber) | - |
| 1003 | { | - |
| 1004 | return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text, | - |
| 1005 | button0Text, button1Text, button2Text, | - |
| 1006 | defaultButtonNumber, escapeButtonNumber); | - |
| 1007 | } | - |
| 1008 | int QMessageBox::question(QWidget *parent, const QString &title, const QString& text, | - |
| 1009 | int button0, int button1, int button2) | - |
| 1010 | { | - |
| 1011 | return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text, | - |
| 1012 | button0, button1, button2); | - |
| 1013 | } | - |
| 1014 | int QMessageBox::question(QWidget *parent, const QString &title, const QString& text, | - |
| 1015 | const QString& button0Text, const QString& button1Text, | - |
| 1016 | const QString& button2Text, int defaultButtonNumber, | - |
| 1017 | int escapeButtonNumber) | - |
| 1018 | { | - |
| 1019 | return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text, | - |
| 1020 | button0Text, button1Text, button2Text, | - |
| 1021 | defaultButtonNumber, escapeButtonNumber); | - |
| 1022 | } | - |
| 1023 | int QMessageBox::warning(QWidget *parent, const QString &title, const QString& text, | - |
| 1024 | int button0, int button1, int button2) | - |
| 1025 | { | - |
| 1026 | return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text, | - |
| 1027 | button0, button1, button2); | - |
| 1028 | } | - |
| 1029 | int QMessageBox::warning(QWidget *parent, const QString &title, const QString& text, | - |
| 1030 | const QString& button0Text, const QString& button1Text, | - |
| 1031 | const QString& button2Text, int defaultButtonNumber, | - |
| 1032 | int escapeButtonNumber) | - |
| 1033 | { | - |
| 1034 | return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text, | - |
| 1035 | button0Text, button1Text, button2Text, | - |
| 1036 | defaultButtonNumber, escapeButtonNumber); | - |
| 1037 | } | - |
| 1038 | int QMessageBox::critical(QWidget *parent, const QString &title, const QString& text, | - |
| 1039 | int button0, int button1, int button2) | - |
| 1040 | { | - |
| 1041 | return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text, | - |
| 1042 | button0, button1, button2); | - |
| 1043 | } | - |
| 1044 | int QMessageBox::critical(QWidget *parent, const QString &title, const QString& text, | - |
| 1045 | const QString& button0Text, const QString& button1Text, | - |
| 1046 | const QString& button2Text, int defaultButtonNumber, | - |
| 1047 | int escapeButtonNumber) | - |
| 1048 | { | - |
| 1049 | return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text, | - |
| 1050 | button0Text, button1Text, button2Text, | - |
| 1051 | defaultButtonNumber, escapeButtonNumber); | - |
| 1052 | } | - |
| 1053 | QString QMessageBox::buttonText(int button) const | - |
| 1054 | { | - |
| 1055 | const QMessageBoxPrivate * const d = d_func(); | - |
| 1056 | | - |
| 1057 | if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) { | - |
| 1058 | return abstractButton->text(); | - |
| 1059 | } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) { | - |
| 1060 | | - |
| 1061 | return QDialogButtonBox::tr("OK"); | - |
| 1062 | } | - |
| 1063 | return QString(); | - |
| 1064 | } | - |
| 1065 | void QMessageBox::setButtonText(int button, const QString &text) | - |
| 1066 | { | - |
| 1067 | QMessageBoxPrivate * const d = d_func(); | - |
| 1068 | if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) { | - |
| 1069 | abstractButton->setText(text); | - |
| 1070 | } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) { | - |
| 1071 | | - |
| 1072 | addButton(QMessageBox::Ok)->setText(text); | - |
| 1073 | } | - |
| 1074 | } | - |
| 1075 | QString QMessageBox::detailedText() const | - |
| 1076 | { | - |
| 1077 | const QMessageBoxPrivate * const d = d_func(); | - |
| 1078 | return d->detailsText ? d->detailsText->text() : QString(); | - |
| 1079 | } | - |
| 1080 | | - |
| 1081 | void QMessageBox::setDetailedText(const QString &text) | - |
| 1082 | { | - |
| 1083 | QMessageBoxPrivate * const d = d_func(); | - |
| 1084 | if (text.isEmpty()) { | - |
| 1085 | delete d->detailsText; | - |
| 1086 | d->detailsText = 0; | - |
| 1087 | removeButton(d->detailsButton); | - |
| 1088 | delete d->detailsButton; | - |
| 1089 | d->detailsButton = 0; | - |
| 1090 | return; | - |
| 1091 | } | - |
| 1092 | | - |
| 1093 | if (!d->detailsText) { | - |
| 1094 | d->detailsText = new QMessageBoxDetailsText(this); | - |
| 1095 | QGridLayout* grid = qobject_cast<QGridLayout*>(layout()); | - |
| 1096 | if (grid) | - |
| 1097 | grid->addWidget(d->detailsText, grid->rowCount(), 0, 1, grid->columnCount()); | - |
| 1098 | d->detailsText->hide(); | - |
| 1099 | } | - |
| 1100 | if (!d->detailsButton) | - |
| 1101 | d->detailsButton = new DetailButton(this); | - |
| 1102 | d->detailsText->setText(text); | - |
| 1103 | } | - |
| 1104 | QString QMessageBox::informativeText() const | - |
| 1105 | { | - |
| 1106 | const QMessageBoxPrivate * const d = d_func(); | - |
| 1107 | return d->informativeLabel ? d->informativeLabel->text() : QString(); | - |
| 1108 | } | - |
| 1109 | | - |
| 1110 | void QMessageBox::setInformativeText(const QString &text) | - |
| 1111 | { | - |
| 1112 | QMessageBoxPrivate * const d = d_func(); | - |
| 1113 | if (text.isEmpty()) { | - |
| 1114 | layout()->removeWidget(d->informativeLabel); | - |
| 1115 | delete d->informativeLabel; | - |
| 1116 | d->informativeLabel = 0; | - |
| 1117 | | - |
| 1118 | d->label->setContentsMargins(2, 0, 0, 0); | - |
| 1119 | | - |
| 1120 | d->updateSize(); | - |
| 1121 | return; | - |
| 1122 | } | - |
| 1123 | | - |
| 1124 | if (!d->informativeLabel) { | - |
| 1125 | QLabel *label = new QLabel; | - |
| 1126 | label->setObjectName(QLatin1String("qt_msgbox_informativelabel")); | - |
| 1127 | label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); | - |
| 1128 | label->setAlignment(Qt::AlignTop | Qt::AlignLeft); | - |
| 1129 | label->setOpenExternalLinks(true); | - |
| 1130 | label->setWordWrap(true); | - |
| 1131 | | - |
| 1132 | d->label->setContentsMargins(2, 0, 0, 0); | - |
| 1133 | label->setContentsMargins(2, 0, 0, 6); | - |
| 1134 | label->setIndent(9); | - |
| 1135 | | - |
| 1136 | | - |
| 1137 | | - |
| 1138 | | - |
| 1139 | | - |
| 1140 | label->setWordWrap(true); | - |
| 1141 | QGridLayout *grid = static_cast<QGridLayout *>(layout()); | - |
| 1142 | grid->addWidget(label, 1, 1, 1, 1); | - |
| 1143 | d->informativeLabel = label; | - |
| 1144 | } | - |
| 1145 | d->informativeLabel->setText(text); | - |
| 1146 | d->updateSize(); | - |
| 1147 | } | - |
| 1148 | void QMessageBox::setWindowTitle(const QString &title) | - |
| 1149 | { | - |
| 1150 | | - |
| 1151 | | - |
| 1152 | QDialog::setWindowTitle(title); | - |
| 1153 | | - |
| 1154 | | - |
| 1155 | | - |
| 1156 | } | - |
| 1157 | void QMessageBox::setWindowModality(Qt::WindowModality windowModality) | - |
| 1158 | { | - |
| 1159 | QDialog::setWindowModality(windowModality); | - |
| 1160 | | - |
| 1161 | if (parentWidget() && windowModality == Qt::WindowModal) | - |
| 1162 | setParent(parentWidget(), Qt::Sheet); | - |
| 1163 | else | - |
| 1164 | setParent(parentWidget(), Qt::Dialog); | - |
| 1165 | setDefaultButton(d_func()->defaultButton); | - |
| 1166 | } | - |
| 1167 | | - |
| 1168 | | - |
| 1169 | QPixmap QMessageBoxPrivate::standardIcon(QMessageBox::Icon icon, QMessageBox *mb) | - |
| 1170 | { | - |
| 1171 | QStyle *style = mb ? mb->style() : QApplication::style(); | - |
| 1172 | int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, mb); | - |
| 1173 | QIcon tmpIcon; | - |
| 1174 | switch (icon) { | - |
| 1175 | case QMessageBox::Information: | - |
| 1176 | tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, mb); | - |
| 1177 | break; | - |
| 1178 | case QMessageBox::Warning: | - |
| 1179 | tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, mb); | - |
| 1180 | break; | - |
| 1181 | case QMessageBox::Critical: | - |
| 1182 | tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, mb); | - |
| 1183 | break; | - |
| 1184 | case QMessageBox::Question: | - |
| 1185 | tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mb); | - |
| 1186 | default: | - |
| 1187 | break; | - |
| 1188 | } | - |
| 1189 | if (!tmpIcon.isNull()) | - |
| 1190 | return tmpIcon.pixmap(iconSize, iconSize); | - |
| 1191 | return QPixmap(); | - |
| 1192 | } | - |
| 1193 | QPixmap QMessageBox::standardIcon(Icon icon) | - |
| 1194 | { | - |
| 1195 | return QMessageBoxPrivate::standardIcon(icon, 0); | - |
| 1196 | } | - |
| 1197 | | - |
| 1198 | | - |
| 1199 | | - |
| | |