diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-01-05 09:12:10 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-01-20 17:49:52 +0000 |
commit | 9831a84d7b80bbeadc092d39c7bfefcd826bb680 (patch) | |
tree | 7bd92a708c05ec7ceb40fab0bdf781a0892fd8c0 /src/plugins | |
parent | 6aa540a1060ce4c9167e380e2f8341cdc536ee51 (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>
(cherry picked from commit 3f996edbb69a575267a4ff816f09510f14729149)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/styles/bb10style/qpixmapstyle.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/plugins/styles/bb10style/qpixmapstyle.cpp b/src/plugins/styles/bb10style/qpixmapstyle.cpp index 3090c42959..9b9b6bbd3a 100644 --- a/src/plugins/styles/bb10style/qpixmapstyle.cpp +++ b/src/plugins/styles/bb10style/qpixmapstyle.cpp @@ -650,11 +650,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 qint64 totalSteps = qint64(pbar->maximum) - pbar->minimum; + const qint64 progressSteps = qint64(pbar->progress) - pbar->minimum; + const int availablePixels = vertical ? option->rect.height() : option->rect.width(); + const double pixelsPerStep = double(availablePixels) / totalSteps; + + const int progress = static_cast<int>(progressSteps * pixelsPerStep); // width in pixels QRect optRect = option->rect; if (vertical) { |