diff options
Diffstat (limited to 'src/widgets/dialogs/qmessagebox.cpp')
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 124 |
1 files changed, 67 insertions, 57 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 995d279e13..e51143cb7e 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -201,6 +201,7 @@ public: detectedEscapeButton(0), informativeLabel(0) { } void init(const QString &title = QString(), const QString &text = QString()); + void setupLayout(); void _q_buttonClicked(QAbstractButton *); QAbstractButton *findButton(int button0, int button1, int button2, int flags); @@ -271,7 +272,6 @@ void QMessageBoxPrivate::init(const QString &title, const QString &text) label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); #endif - icon = QMessageBox::NoIcon; iconLabel = new QLabel; iconLabel->setObjectName(QLatin1String("qt_msgboxex_icon_label")); iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -281,41 +281,50 @@ void QMessageBoxPrivate::init(const QString &title, const QString &text) buttonBox->setCenterButtons(q->style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, q)); QObject::connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), q, SLOT(_q_buttonClicked(QAbstractButton*))); + setupLayout(); + if (!title.isEmpty() || !text.isEmpty()) { + q->setWindowTitle(title); + q->setText(text); + } + q->setModal(true); +#ifdef Q_OS_MAC + QFont f = q->font(); + f.setBold(true); + label->setFont(f); +#endif + icon = QMessageBox::NoIcon; +} +void QMessageBoxPrivate::setupLayout() +{ + Q_Q(QMessageBox); + delete q->layout(); QGridLayout *grid = new QGridLayout; -#ifndef Q_OS_MAC grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); grid->addWidget(label, 0, 1, 1, 1); - // -- leave space for information label -- + if (informativeLabel) + grid->addWidget(informativeLabel, 1, 1, 1, 1); +#ifndef Q_OS_MAC grid->addWidget(buttonBox, 2, 0, 1, 2); #else + grid->addWidget(buttonBox, 3, 1, 1, 1); +#endif + if (detailsText) + grid->addWidget(detailsText, grid->rowCount(), 0, 1, grid->columnCount()); +#ifdef Q_OS_MAC grid->setMargin(0); grid->setVerticalSpacing(8); grid->setHorizontalSpacing(0); q->setContentsMargins(24, 15, 24, 20); - grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop | Qt::AlignLeft); - grid->addWidget(label, 0, 1, 1, 1); - // -- leave space for information label -- grid->setRowStretch(1, 100); grid->setRowMinimumHeight(2, 6); - grid->addWidget(buttonBox, 3, 1, 1, 1); #endif grid->setSizeConstraint(QLayout::SetNoConstraint); q->setLayout(grid); - if (!title.isEmpty() || !text.isEmpty()) { - q->setWindowTitle(title); - q->setText(text); - } - q->setModal(true); - -#ifdef Q_OS_MAC - QFont f = q->font(); - f.setBold(true); - label->setFont(f); -#endif retranslateStrings(); + updateSize(); } int QMessageBoxPrivate::layoutMinimumWidth() @@ -2458,24 +2467,27 @@ void QMessageBox::setDetailedText(const QString &text) { Q_D(QMessageBox); if (text.isEmpty()) { - delete d->detailsText; + if (d->detailsText) { + d->detailsText->hide(); + d->detailsText->deleteLater(); + } d->detailsText = 0; removeButton(d->detailsButton); - delete d->detailsButton; + if (d->detailsButton) { + d->detailsButton->hide(); + d->detailsButton->deleteLater(); + } d->detailsButton = 0; - return; - } - - if (!d->detailsText) { - d->detailsText = new QMessageBoxDetailsText(this); - QGridLayout* grid = qobject_cast<QGridLayout*>(layout()); - if (grid) - grid->addWidget(d->detailsText, grid->rowCount(), 0, 1, grid->columnCount()); - d->detailsText->hide(); + } else { + if (!d->detailsText) { + d->detailsText = new QMessageBoxDetailsText(this); + d->detailsText->hide(); + } + if (!d->detailsButton) + d->detailsButton = new DetailButton(this); + d->detailsText->setText(text); } - if (!d->detailsButton) - d->detailsButton = new DetailButton(this); - d->detailsText->setText(text); + d->setupLayout(); } #endif // QT_NO_TEXTEDIT @@ -2506,39 +2518,37 @@ void QMessageBox::setInformativeText(const QString &text) { Q_D(QMessageBox); if (text.isEmpty()) { - layout()->removeWidget(d->informativeLabel); - delete d->informativeLabel; + if (d->informativeLabel) { + d->informativeLabel->hide(); + d->informativeLabel->deleteLater(); + } d->informativeLabel = 0; #ifndef Q_OS_MAC d->label->setContentsMargins(2, 0, 0, 0); #endif - d->updateSize(); - return; - } - - if (!d->informativeLabel) { - QLabel *label = new QLabel; - label->setObjectName(QLatin1String("qt_msgbox_informativelabel")); - label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); - label->setAlignment(Qt::AlignTop | Qt::AlignLeft); - label->setOpenExternalLinks(true); - label->setWordWrap(true); + } else { + if (!d->informativeLabel) { + QLabel *label = new QLabel; + label->setObjectName(QLatin1String("qt_msgbox_informativelabel")); + label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); + label->setAlignment(Qt::AlignTop | Qt::AlignLeft); + label->setOpenExternalLinks(true); + label->setWordWrap(true); #ifndef Q_OS_MAC - d->label->setContentsMargins(2, 0, 0, 0); - label->setContentsMargins(2, 0, 0, 6); - label->setIndent(9); + d->label->setContentsMargins(2, 0, 0, 0); + label->setContentsMargins(2, 0, 0, 6); + label->setIndent(9); #else - label->setContentsMargins(16, 0, 0, 0); - // apply a smaller font the information label on the mac - label->setFont(qt_app_fonts_hash()->value("QTipLabel")); + label->setContentsMargins(16, 0, 0, 0); + // apply a smaller font the information label on the mac + label->setFont(qt_app_fonts_hash()->value("QTipLabel")); #endif - label->setWordWrap(true); - QGridLayout *grid = static_cast<QGridLayout *>(layout()); - grid->addWidget(label, 1, 1, 1, 1); - d->informativeLabel = label; + label->setWordWrap(true); + d->informativeLabel = label; + } + d->informativeLabel->setText(text); } - d->informativeLabel->setText(text); - d->updateSize(); + d->setupLayout(); } /*! |