summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPasi Pentikainen <ext-pasi.a.pentikainen@nokia.com>2012-02-13 19:59:23 +0200
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-03-09 14:18:47 +0100
commita41219484a5ab064ca919871a0b7469d0be41419 (patch)
tree990b9ea3f725c61a5be43ae09d33f98ead18a6b1
parenta96672bc77642e3e5a030fd9e78f700b47e11ccb (diff)
downloadqt4-tools-a41219484a5ab064ca919871a0b7469d0be41419.tar.gz
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> (cherry picked from commit 21b9d81d527f100e25a4c6dedaf423cdd8f6827c)
-rw-r--r--src/gui/widgets/qabstractslider.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp
index c86146e83e..5c9b475de6 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;
}