summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-08-09 20:57:54 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-27 05:56:09 +0200
commitf73518e7325faf1359b7f52333aa7c11ed393c8c (patch)
treeb293e58c6bb4e692b5d0cd6fdbc18991118a9808 /src
parent77e8ff66f0f9d798b386cf65bc5aa58a5738be9a (diff)
QMessageBox - move informative+details text to new layout function
Controlling the layout from different functions is not easy, so lets move it to the setupLayout function. Change-Id: I3120a2e98b2f8425befa135595d4ad7ce1b8ca56 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp86
1 files changed, 47 insertions, 39 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index 65b623d7e9..e51143cb7e 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -302,10 +302,16 @@ void QMessageBoxPrivate::setupLayout()
QGridLayout *grid = new QGridLayout;
grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop);
grid->addWidget(label, 0, 1, 1, 1);
+ 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);
@@ -318,6 +324,7 @@ void QMessageBoxPrivate::setupLayout()
q->setLayout(grid);
retranslateStrings();
+ updateSize();
}
int QMessageBoxPrivate::layoutMinimumWidth()
@@ -2460,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
@@ -2508,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();
}
/*!