diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-08-06 11:46:32 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-06 13:14:42 +0200 |
commit | b8abaebb5b4309ffb6d3e559ec422ef5cd527496 (patch) | |
tree | 8e62668700448e9d7e3c26c8005679e9eaad9160 | |
parent | 4fb189bb885c159125203f53128301dc220c7795 (diff) | |
download | qtquickcontrols-b8abaebb5b4309ffb6d3e559ec422ef5cd527496.tar.gz |
ScrollBar: support wheel scrolling
Task-number: QTBUG-32763
Change-Id: Ia37fa5f8021346a4cbeedd2f404e88476d9e7bd3
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
-rw-r--r-- | src/private/ScrollBar.qml | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/private/ScrollBar.qml b/src/private/ScrollBar.qml index 5257fe80..c21d6562 100644 --- a/src/private/ScrollBar.qml +++ b/src/private/ScrollBar.qml @@ -182,28 +182,40 @@ Item { pageDownPressed = false; } - function incrementPage() { - value += pageStep - if (value > maximumValue) - value = maximumValue + onWheel: { + var stepCount = -(wheel.angleDelta.x ? wheel.angleDelta.x : wheel.angleDelta.y) / 120 + if (stepCount != 0) { + if (wheel.modifiers & Qt.ControlModifier || wheel.modifiers & Qt.ShiftModifier) + incrementPage(stepCount) + else + increment(stepCount) + } + } + + function incrementPage(stepCount) { + value = boundValue(value + getSteps(pageStep, stepCount)) + } + + function decrementPage(stepCount) { + value = boundValue(value - getSteps(pageStep, stepCount)) + } + + function increment(stepCount) { + value = boundValue(value + getSteps(singleStep, stepCount)) } - function decrementPage() { - value -= pageStep - if (value < minimumValue) - value = minimumValue + function decrement(stepCount) { + value = boundValue(value - getSteps(singleStep, stepCount)) } - function increment() { - value += singleStep - if (value > maximumValue) - value = maximumValue + function boundValue(val) { + return Math.min(Math.max(val, minimumValue), maximumValue) } - function decrement() { - value -= singleStep - if (value < minimumValue) - value = minimumValue + function getSteps(step, count) { + if (count) + step *= count + return step } RangeModel { |