From f74566e08b38d11f2119daa145eda0c19f1d725b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 30 Jul 2014 13:00:30 +0200 Subject: QProgressDialog: Extract Method QProgressDialogPrivate::ensureSizeIsAtLeastSizeHint() The code was used in five different places, time to centralize. Change-Id: I32338bdae247169a180f59314c50a9b855cae5f0 Reviewed-by: David Faure --- src/widgets/dialogs/qprogressdialog.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp index 4a7ee41090..4a2b5cbea9 100644 --- a/src/widgets/dialogs/qprogressdialog.cpp +++ b/src/widgets/dialogs/qprogressdialog.cpp @@ -86,6 +86,7 @@ public: void retranslateStrings(); void setCancelButtonText(const QString &cancelButtonText); void adoptChildWidget(QWidget *c); + void ensureSizeIsAtLeastSizeHint(); void _q_disconnectOnClose(); QLabel *label; @@ -386,9 +387,7 @@ void QProgressDialog::setLabelText(const QString &text) Q_D(QProgressDialog); if (d->label) { d->label->setText(text); - int w = qMax(isVisible() ? width() : 0, sizeHint().width()); - int h = qMax(isVisible() ? height() : 0, sizeHint().height()); - resize(w, h); + d->ensureSizeIsAtLeastSizeHint(); } } @@ -455,9 +454,7 @@ void QProgressDialogPrivate::setCancelButtonText(const QString &cancelButtonText } else { q->setCancelButton(0); } - int w = qMax(q->isVisible() ? q->width() : 0, q->sizeHint().width()); - int h = qMax(q->isVisible() ? q->height() : 0, q->sizeHint().height()); - q->resize(w, h); + ensureSizeIsAtLeastSizeHint(); } @@ -495,15 +492,22 @@ void QProgressDialogPrivate::adoptChildWidget(QWidget *c) if (c) { if (c->parentWidget() == q) - c->hide(); // until we resize + c->hide(); // until after ensureSizeIsAtLeastSizeHint() else c->setParent(q, 0); } + ensureSizeIsAtLeastSizeHint(); + if (c) + c->show(); +} + +void QProgressDialogPrivate::ensureSizeIsAtLeastSizeHint() +{ + Q_Q(QProgressDialog); + int w = qMax(q->isVisible() ? q->width() : 0, q->sizeHint().width()); int h = qMax(q->isVisible() ? q->height() : 0, q->sizeHint().height()); q->resize(w, h); - if (c) - c->show(); } @@ -689,9 +693,7 @@ void QProgressDialog::setValue(int progress) } } if (need_show) { - int w = qMax(isVisible() ? width() : 0, sizeHint().width()); - int h = qMax(isVisible() ? height() : 0, sizeHint().height()); - resize(w, h); + d->ensureSizeIsAtLeastSizeHint(); show(); d->shown_once = true; } @@ -837,9 +839,7 @@ void QProgressDialog::showEvent(QShowEvent *e) { Q_D(QProgressDialog); QDialog::showEvent(e); - int w = qMax(isVisible() ? width() : 0, sizeHint().width()); - int h = qMax(isVisible() ? height() : 0, sizeHint().height()); - resize(w, h); + d->ensureSizeIsAtLeastSizeHint(); d->forceTimer->stop(); } -- cgit v1.2.3