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>
This commit is contained in:
Thorbjørn Martsum 2013-08-09 20:57:54 +02:00 committed by The Qt Project
parent 77e8ff66f0
commit f73518e732

View File

@ -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,25 +2467,28 @@ 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;
d->detailsButton = 0;
return;
if (d->detailsButton) {
d->detailsButton->hide();
d->detailsButton->deleteLater();
}
d->detailsButton = 0;
} else {
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();
}
if (!d->detailsButton)
d->detailsButton = new DetailButton(this);
d->detailsText->setText(text);
}
d->setupLayout();
}
#endif // QT_NO_TEXTEDIT
/*!
@ -2508,16 +2518,15 @@ 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;
}
} else {
if (!d->informativeLabel) {
QLabel *label = new QLabel;
label->setObjectName(QLatin1String("qt_msgbox_informativelabel"));
@ -2535,12 +2544,11 @@ void QMessageBox::setInformativeText(const QString &text)
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;
}
d->informativeLabel->setText(text);
d->updateSize();
}
d->setupLayout();
}
/*!