diff options
author | Pasi Pentikainen <ext-pasi.a.pentikainen@nokia.com> | 2012-02-13 17:59:23 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-27 16:14:14 (GMT) |
commit | 21b9d81d527f100e25a4c6dedaf423cdd8f6827c (patch) | |
tree | 6073eb2e76f93ec182b3be52eb1641b8ed455aeb /src/gui | |
parent | 2fa9c829faae10f445fd580627114a8383b753ab (diff) | |
download | Qt-21b9d81d527f100e25a4c6dedaf423cdd8f6827c.zip Qt-21b9d81d527f100e25a4c6dedaf423cdd8f6827c.tar.gz Qt-21b9d81d527f100e25a4c6dedaf423cdd8f6827c.tar.bz2 |
Fix mouse wheel page-by-page scrolling on windows
In windows, the page-by-page mouse wheel scrolling is configured with
scroll lines value of -1, which maps to INT_MAX. The scroll calculations
had an integer overflow issue which caused the wheel scrolling to scroll
only downwards when configured with large enough value like this.
Task-number: QTBUG-11336
Change-Id: Ib4440367ce2617f96797c1f8cc8ec9e6a2f8467c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Andrew Semenenko
Reviewed-by: Shane Kearns <ext-shane.2.kearns@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/widgets/qabstractslider.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index 17afa29..9919658 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -689,6 +689,16 @@ void QAbstractSlider::sliderChange(SliderChange) update(); } +/*! + \internal + + Truncate qreal to int without flipping on overflow. +*/ +static inline int clampScrollStep(qreal x) +{ + return int(qBound(qreal(INT_MIN), x, qreal(INT_MAX))); +} + bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta) { Q_Q(QAbstractSlider); @@ -700,7 +710,7 @@ bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::Keyb if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) { // Scroll one page regardless of delta: - stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep); + stepsToScroll = qBound(-pageStep, clampScrollStep(offset * pageStep), pageStep); offset_accumulated = 0; } else { // Calculate how many lines to scroll. Depending on what delta is (and @@ -718,14 +728,14 @@ bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::Keyb offset_accumulated += stepsToScrollF; #ifndef Q_WS_MAC // Don't scroll more than one page in any case: - stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep); + stepsToScroll = qBound(-pageStep, clampScrollStep(offset_accumulated), pageStep); #else // Native UI-elements on Mac can scroll hundreds of lines at a time as // a result of acceleration. So keep the same behaviour in Qt, and // don't restrict stepsToScroll to certain maximum (pageStep): - stepsToScroll = int(offset_accumulated); + stepsToScroll = clampScrollStep(offset_accumulated); #endif - offset_accumulated -= int(offset_accumulated); + offset_accumulated -= clampScrollStep(offset_accumulated); if (stepsToScroll == 0) return false; } |