diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-22 11:56:51 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-22 12:02:51 (GMT) |
commit | 27e5a1f9542b03a6930f002e8d7dafd97cf88a1a (patch) | |
tree | ed5dbaaa9a0824ba1910f89db8bf38374b574b58 | |
parent | 336954fb9b990c6d7c44ed3a8d676a6e21b2057f (diff) | |
download | Qt-27e5a1f9542b03a6930f002e8d7dafd97cf88a1a.zip Qt-27e5a1f9542b03a6930f002e8d7dafd97cf88a1a.tar.gz Qt-27e5a1f9542b03a6930f002e8d7dafd97cf88a1a.tar.bz2 |
Support for very large range in QProgressBar
Regression since my last commit.
Task-number: 152227
-rw-r--r-- | src/gui/styles/qcleanlooksstyle.cpp | 6 | ||||
-rw-r--r-- | src/gui/styles/qgtkstyle.cpp | 4 | ||||
-rw-r--r-- | src/gui/styles/qplastiquestyle.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/qprogressbar.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qprogressbar/tst_qprogressbar.cpp | 32 |
5 files changed, 39 insertions, 10 deletions
diff --git a/src/gui/styles/qcleanlooksstyle.cpp b/src/gui/styles/qcleanlooksstyle.cpp index 779fbc2..ccf81cb 100644 --- a/src/gui/styles/qcleanlooksstyle.cpp +++ b/src/gui/styles/qcleanlooksstyle.cpp @@ -1745,9 +1745,9 @@ void QCleanlooksStyle::drawControl(ControlElement element, const QStyleOption *o int maxWidth = rect.width() - 4; int minWidth = 4; - int progress = qMax(bar->progress, bar->minimum); // workaround for bug in QProgressBar - int progressBarWidth = qMax(minWidth, (progress - bar->minimum) * maxWidth / qMax(1, bar->maximum - bar->minimum)); - int width = indeterminate ? maxWidth : progressBarWidth; + qreal progress = qMax(bar->progress, bar->minimum); // workaround for bug in QProgressBar + int progressBarWidth = (progress - bar->minimum) * qreal(maxWidth) / qMax(1.0, qreal(bar->maximum) - bar->minimum); + int width = indeterminate ? maxWidth : qMax(minWidth, progressBarWidth); bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical; if (inverted) diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp index 2ba151e..53f3db9 100644 --- a/src/gui/styles/qgtkstyle.cpp +++ b/src/gui/styles/qgtkstyle.cpp @@ -2075,8 +2075,8 @@ void QGtkStyle::drawControl(ControlElement element, } if (vertical) rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height - const int progressIndicatorPos = (bar->progress - bar->minimum) * rect.width() / - qMax(1, bar->maximum - bar->minimum); + const int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) * rect.width() / + qMax(1.0, qreal(bar->maximum) - bar->minimum); if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width()) leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height()); if (vertical) diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp index cd0bd0a..80c9881 100644 --- a/src/gui/styles/qplastiquestyle.cpp +++ b/src/gui/styles/qplastiquestyle.cpp @@ -2571,8 +2571,7 @@ void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *op painter->setTransform(m, true); } - double vc6_workaround = ((bar->progress - qint64(bar->minimum)) / qMax(double(1.0), double(qint64(bar->maximum) - qint64(bar->minimum))) * rect.width()); - int progressIndicatorPos = int(vc6_workaround); + int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum) * rect.width(); bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted) || ((bar->direction == Qt::LeftToRight) && inverted))) || (vertical && ((!inverted && !bottomToTop) || (inverted && bottomToTop))); diff --git a/src/gui/widgets/qprogressbar.cpp b/src/gui/widgets/qprogressbar.cpp index 846f127..6b38e9f 100644 --- a/src/gui/widgets/qprogressbar.cpp +++ b/src/gui/widgets/qprogressbar.cpp @@ -447,7 +447,7 @@ QString QProgressBar::text() const || (d->value == INT_MIN && d->minimum == INT_MIN)) return QString(); - int totalSteps = d->maximum - d->minimum; + qint64 totalSteps = qint64(d->maximum) - d->minimum; QString result = d->format; result.replace(QLatin1String("%m"), QString::number(totalSteps)); @@ -461,7 +461,7 @@ QString QProgressBar::text() const return result; } - int progress = (d->value - d->minimum) * 100 / totalSteps; + int progress = (qreal(d->value) - d->minimum) * 100.0 / totalSteps; result.replace(QLatin1String("%p"), QString::number(progress)); return result; } diff --git a/tests/auto/qprogressbar/tst_qprogressbar.cpp b/tests/auto/qprogressbar/tst_qprogressbar.cpp index 403b56b..452250c 100644 --- a/tests/auto/qprogressbar/tst_qprogressbar.cpp +++ b/tests/auto/qprogressbar/tst_qprogressbar.cpp @@ -62,6 +62,8 @@ private slots: void format(); void setValueRepaint(); void sizeHint(); + void formatedText_data(); + void formatedText(); void task245201_testChangeStyleAndDelete_data(); void task245201_testChangeStyleAndDelete(); @@ -174,7 +176,7 @@ void tst_QProgressBar::format() bar.repainted = false; bar.setFormat("%v of %m (%p%)"); qApp->processEvents(); -#ifndef Q_WS_MAC +#ifndef Q_WS_MAC // The Mac scroll bar is animated, which means we get paint events all the time. QVERIFY(!bar.repainted); #endif @@ -225,6 +227,34 @@ void tst_QProgressBar::sizeHint() QCOMPARE(barSize.height(), size.height()); } +void tst_QProgressBar::formatedText_data() +{ + QTest::addColumn<int>("minimum"); + QTest::addColumn<int>("maximum"); + QTest::addColumn<int>("value"); + QTest::addColumn<QString>("format"); + QTest::addColumn<QString>("text"); + + QTest::newRow("1") << -100 << 100 << 0 << QString::fromLatin1(" %p - %v - %m ") << QString::fromLatin1(" 50 - 0 - 200 "); +// QTest::newRow("2") << -100 << 0 << -25 << QString::fromLatin1(" %p - %v - %m ") << QString::fromLatin1(" 75 - -25 - 100 "); + QTest::newRow("3") << 10 << 10 << 10 << QString::fromLatin1(" %p - %v - %m ") << QString::fromLatin1(" 100 - 10 - 0 "); + QTest::newRow("task152227") << INT_MIN << INT_MAX << 42 << QString::fromLatin1(" %p - %v - %m ") << QString::fromLatin1(" 50 - 42 - 4294967295 "); +} + +void tst_QProgressBar::formatedText() +{ + QFETCH(int, minimum); + QFETCH(int, maximum); + QFETCH(int, value); + QFETCH(QString, format); + QFETCH(QString, text); + QProgressBar bar; + bar.setRange(minimum, maximum); + bar.setValue(value); + bar.setFormat(format); + QCOMPARE(bar.text(), text); +} + void tst_QProgressBar::task245201_testChangeStyleAndDelete_data() { QTest::addColumn<QString>("style1_str"); |