diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-01-05 09:12:10 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-01-07 08:19:38 +0000 |
commit | 3f996edbb69a575267a4ff816f09510f14729149 (patch) | |
tree | ad0e2f276aabe15cc341f9b8be0df5f2565cb3f8 /src/widgets | |
parent | a3d0983f5909c37205cf0bdd4c4eba15d26d58c9 (diff) |
QPixmapStyle: do not assume minimum == 0 when painting progress bars
The arithmetic used to calculate the size of the progress bar fill in
QPixmapStyle assumed minimum == 0, but that does not necessarily
hold, since the minimum value is user-defined.
So, fix the arithmetic to take the minimum into account, taking care,
as done elsewhere, to avoid signed integer and qreal=float overflows,
by using qint64 and double, respectively.
[ChangeLog][QtWidgets][QPixmapStyle] Now handles progress bars with
minimum != 0 correctly.
Change-Id: I738ded56e8234716c36a5e9fde15bae691c43a35
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/styles/qpixmapstyle.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/widgets/styles/qpixmapstyle.cpp b/src/widgets/styles/qpixmapstyle.cpp index e973a96a91..ce37065fb6 100644 --- a/src/widgets/styles/qpixmapstyle.cpp +++ b/src/widgets/styles/qpixmapstyle.cpp @@ -819,11 +819,14 @@ void QPixmapStyle::drawProgressBarFill(const QStyleOption *option, drawCachedPixmap(vertical ? PB_VComplete : PB_HComplete, option->rect, painter); } else { - if (pbar->progress == 0) + if (pbar->progress == pbar->minimum) return; - const int maximum = pbar->maximum; - const qreal ratio = qreal(vertical?option->rect.height():option->rect.width())/maximum; - const int progress = pbar->progress*ratio; + const auto totalSteps = qint64(pbar->maximum) - pbar->minimum; + const auto progressSteps = qint64(pbar->progress) - pbar->minimum; + const auto availablePixels = vertical ? option->rect.height() : option->rect.width(); + const auto pixelsPerStep = double(availablePixels) / totalSteps; + + const auto progress = static_cast<int>(progressSteps * pixelsPerStep); // width in pixels QRect optRect = option->rect; if (vertical) { |