summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qprogressdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/dialogs/qprogressdialog.cpp')
-rw-r--r--src/widgets/dialogs/qprogressdialog.cpp105
1 files changed, 61 insertions, 44 deletions
diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp
index 662504fc25..ed856c266e 100644
--- a/src/widgets/dialogs/qprogressdialog.cpp
+++ b/src/widgets/dialogs/qprogressdialog.cpp
@@ -84,6 +84,9 @@ public:
void init(const QString &labelText, const QString &cancelText, int min, int max);
void layout();
void retranslateStrings();
+ void setCancelButtonText(const QString &cancelButtonText);
+ void adoptChildWidget(QWidget *c);
+ void ensureSizeIsAtLeastSizeHint();
void _q_disconnectOnClose();
QLabel *label;
@@ -178,9 +181,8 @@ void QProgressDialogPrivate::layout()
void QProgressDialogPrivate::retranslateStrings()
{
- Q_Q(QProgressDialog);
if (useDefaultCancelText)
- q->setCancelButtonText(QProgressDialog::tr("Cancel"));
+ setCancelButtonText(QProgressDialog::tr("Cancel"));
}
void QProgressDialogPrivate::_q_disconnectOnClose()
@@ -354,20 +356,14 @@ QProgressDialog::~QProgressDialog()
void QProgressDialog::setLabel(QLabel *label)
{
Q_D(QProgressDialog);
+ if (label == d->label) {
+ if (label)
+ qWarning("QProgressDialog::setLabel: Attempt to set the same label again");
+ return;
+ }
delete d->label;
d->label = label;
- if (label) {
- if (label->parentWidget() == this) {
- label->hide(); // until we resize
- } else {
- label->setParent(this, 0);
- }
- }
- int w = qMax(isVisible() ? width() : 0, sizeHint().width());
- int h = qMax(isVisible() ? height() : 0, sizeHint().height());
- resize(w, h);
- if (label)
- label->show();
+ d->adoptChildWidget(label);
}
@@ -391,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();
}
}
@@ -411,14 +405,14 @@ void QProgressDialog::setLabelText(const QString &text)
void QProgressDialog::setCancelButton(QPushButton *cancelButton)
{
Q_D(QProgressDialog);
+ if (d->cancel == cancelButton) {
+ if (cancelButton)
+ qWarning("QProgressDialog::setCancelButton: Attempt to set the same button again");
+ return;
+ }
delete d->cancel;
d->cancel = cancelButton;
if (cancelButton) {
- if (cancelButton->parentWidget() == this) {
- cancelButton->hide(); // until we resize
- } else {
- cancelButton->setParent(this, 0);
- }
connect(d->cancel, SIGNAL(clicked()), this, SIGNAL(canceled()));
#ifndef QT_NO_SHORTCUT
d->escapeShortcut = new QShortcut(Qt::Key_Escape, this, SIGNAL(canceled()));
@@ -429,11 +423,7 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton)
d->escapeShortcut = 0;
#endif
}
- int w = qMax(isVisible() ? width() : 0, sizeHint().width());
- int h = qMax(isVisible() ? height() : 0, sizeHint().height());
- resize(w, h);
- if (cancelButton)
- cancelButton->show();
+ d->adoptChildWidget(cancelButton);
}
/*!
@@ -448,19 +438,23 @@ void QProgressDialog::setCancelButtonText(const QString &cancelButtonText)
{
Q_D(QProgressDialog);
d->useDefaultCancelText = false;
+ d->setCancelButtonText(cancelButtonText);
+}
+
+void QProgressDialogPrivate::setCancelButtonText(const QString &cancelButtonText)
+{
+ Q_Q(QProgressDialog);
if (!cancelButtonText.isNull()) {
- if (d->cancel) {
- d->cancel->setText(cancelButtonText);
+ if (cancel) {
+ cancel->setText(cancelButtonText);
} else {
- setCancelButton(new QPushButton(cancelButtonText, this));
+ q->setCancelButton(new QPushButton(cancelButtonText, q));
}
} else {
- setCancelButton(0);
+ q->setCancelButton(0);
}
- int w = qMax(isVisible() ? width() : 0, sizeHint().width());
- int h = qMax(isVisible() ? height() : 0, sizeHint().height());
- resize(w, h);
+ ensureSizeIsAtLeastSizeHint();
}
@@ -483,11 +477,38 @@ void QProgressDialog::setBar(QProgressBar *bar)
qWarning("QProgressDialog::setBar: Cannot set a new progress bar "
"while the old one is active");
#endif
+ if (bar == d->bar) {
+ qWarning("QProgressDialog::setBar: Attempt to set the same progress bar again");
+ return;
+ }
delete d->bar;
d->bar = bar;
- int w = qMax(isVisible() ? width() : 0, sizeHint().width());
- int h = qMax(isVisible() ? height() : 0, sizeHint().height());
- resize(w, h);
+ d->adoptChildWidget(bar);
+}
+
+void QProgressDialogPrivate::adoptChildWidget(QWidget *c)
+{
+ Q_Q(QProgressDialog);
+
+ if (c) {
+ if (c->parentWidget() == q)
+ c->hide(); // until after ensureSizeIsAtLeastSizeHint()
+ else
+ c->setParent(q, 0);
+ }
+ ensureSizeIsAtLeastSizeHint();
+ if (c)
+ c->show();
+}
+
+void QProgressDialogPrivate::ensureSizeIsAtLeastSizeHint()
+{
+ Q_Q(QProgressDialog);
+
+ QSize size = q->sizeHint();
+ if (q->isVisible())
+ size = size.expandedTo(q->size());
+ q->resize(size);
}
@@ -507,7 +528,7 @@ bool QProgressDialog::wasCanceled() const
\property QProgressDialog::maximum
\brief the highest value represented by the progress bar
- The default is 0.
+ The default is 100.
\sa minimum, setRange()
*/
@@ -673,9 +694,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;
}
@@ -821,9 +840,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();
}