diff options
author | Thorbjørn Martsum <tmartsum@gmail.com> | 2013-08-12 19:56:01 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-13 22:06:26 +0200 |
commit | 62fbf3ca6fc2d1736c6f5d5456f66ae1cfe94be8 (patch) | |
tree | 9eeeb4d47088968c2c6f61a1ecc9f40558957c37 /src/widgets/dialogs/qmessagebox.cpp | |
parent | 92b0a7fa3ee874bc4a9a39da112896fa7e3a97e9 (diff) |
QMessageBox - move margins to a left spacer
This patch moves labels indent and contents margins into a
left spacer, and it only puts the iconLabel in the layout
if there is an icon.
Change-Id: I6f3563a08fc15ec6ec267e095adf1734f7828355
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/widgets/dialogs/qmessagebox.cpp')
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index e51143cb7e..5bcda9bf25 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -266,13 +266,7 @@ void QMessageBoxPrivate::init(const QString &title, const QString &text) label->setTextInteractionFlags(Qt::TextInteractionFlags(q->style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, q))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); -#if defined(Q_OS_MAC) - label->setContentsMargins(16, 0, 0, 0); -#else - label->setContentsMargins(2, 0, 0, 0); - label->setIndent(9); -#endif - iconLabel = new QLabel; + iconLabel = new QLabel(q); iconLabel->setObjectName(QLatin1String("qt_msgboxex_icon_label")); iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -300,26 +294,37 @@ void QMessageBoxPrivate::setupLayout() Q_Q(QMessageBox); delete q->layout(); 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); + bool hasIcon = iconLabel->pixmap() && !iconLabel->pixmap()->isNull(); + + if (hasIcon) + grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); + iconLabel->setVisible(hasIcon); +#ifdef Q_OS_MAC + QSpacerItem *indentSpacer = new QSpacerItem(14, 1, QSizePolicy::Fixed, QSizePolicy::Fixed); #else - grid->addWidget(buttonBox, 3, 1, 1, 1); + QSpacerItem *indentSpacer = new QSpacerItem(hasIcon ? 7 : 15, 1, QSizePolicy::Fixed, QSizePolicy::Fixed); #endif - if (detailsText) - grid->addWidget(detailsText, grid->rowCount(), 0, 1, grid->columnCount()); + grid->addItem(indentSpacer, 0, hasIcon ? 1 : 0, 2, 1); + grid->addWidget(label, 0, hasIcon ? 2 : 1, 1, 1); + if (informativeLabel) { +#ifndef Q_OS_MAC + informativeLabel->setContentsMargins(0, 7, 0, 7); +#endif + grid->addWidget(informativeLabel, 1, hasIcon ? 2 : 1, 1, 1); + } #ifdef Q_OS_MAC + grid->addWidget(buttonBox, 3, hasIcon ? 2 : 1, 1, 1); grid->setMargin(0); grid->setVerticalSpacing(8); grid->setHorizontalSpacing(0); q->setContentsMargins(24, 15, 24, 20); grid->setRowStretch(1, 100); grid->setRowMinimumHeight(2, 6); +#else + grid->addWidget(buttonBox, 2, 0, 1, grid->columnCount()); #endif - + if (detailsText) + grid->addWidget(detailsText, grid->rowCount(), 0, 1, grid->columnCount()); grid->setSizeConstraint(QLayout::SetNoConstraint); q->setLayout(grid); @@ -1228,8 +1233,8 @@ void QMessageBox::setIconPixmap(const QPixmap &pixmap) { Q_D(QMessageBox); d->iconLabel->setPixmap(pixmap); - d->updateSize(); d->icon = NoIcon; + d->setupLayout(); } /*! @@ -2523,9 +2528,6 @@ void QMessageBox::setInformativeText(const QString &text) d->informativeLabel->deleteLater(); } d->informativeLabel = 0; -#ifndef Q_OS_MAC - d->label->setContentsMargins(2, 0, 0, 0); -#endif } else { if (!d->informativeLabel) { QLabel *label = new QLabel; @@ -2534,12 +2536,7 @@ void QMessageBox::setInformativeText(const QString &text) 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); -#else - label->setContentsMargins(16, 0, 0, 0); +#ifdef Q_OS_MAC // apply a smaller font the information label on the mac label->setFont(qt_app_fonts_hash()->value("QTipLabel")); #endif |