diff options
author | Jens Bache-Wiig <jens.bache-wiig@digia.com> | 2013-05-22 13:33:43 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-23 08:30:05 +0200 |
commit | c5d6d214f964eb4f3f582c0cd7ab6fed7626f537 (patch) | |
tree | cc93300e5419ae859370c5531748a4a3ada8b7a5 /src/controls/Slider.qml | |
parent | d314f546f544384b7716ba5dc59ddfc56fa10e48 (diff) | |
download | qtquickcontrols-c5d6d214f964eb4f3f582c0cd7ab6fed7626f537.tar.gz |
Slider: pressing the handle should not change the slider position
We have to maintain the handle offset until the drag operation
has ended. If the user clicks outside the handle, we center
on the cursor position as before.
Task-number: QTBUG-31042
Change-Id: I8f23d998774278c6353d31b6fffea54596f7158e
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/Slider.qml')
-rw-r--r-- | src/controls/Slider.qml | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/controls/Slider.qml b/src/controls/Slider.qml index 95cda60f..d53255a3 100644 --- a/src/controls/Slider.qml +++ b/src/controls/Slider.qml @@ -221,20 +221,22 @@ Control { width: parent.width height: parent.height + property int clickOffset: 0 + function clamp ( val ) { return Math.max(range.positionAtMinimum, Math.min(range.positionAtMaximum, val)) } onMouseXChanged: { if (pressed && __horizontal) { - var pos = clamp (mouse.x - fakeHandle.width/2) + var pos = clamp (mouse.x + clickOffset - fakeHandle.width/2) fakeHandle.x = pos } } onMouseYChanged: { if (pressed && !__horizontal) { - var pos = clamp (mouse.y - fakeHandle.height/2) + var pos = clamp (mouse.y + clickOffset- fakeHandle.height/2) fakeHandle.y = pos } } @@ -242,6 +244,11 @@ Control { onPressed: { if (slider.activeFocusOnPress) slider.forceActiveFocus(); + + var point = mouseArea.mapToItem(fakeHandle, mouse.x, mouse.y) + if (fakeHandle.contains(Qt.point(point.x, point.y))) { + clickOffset = __horizontal ? fakeHandle.width/2 - point.x : fakeHandle.height/2 - point.y + } } onReleased: { @@ -249,6 +256,7 @@ Control { // moment that the range is updated. if (!slider.updateValueWhileDragging) range.position = __horizontal ? fakeHandle.x : fakeHandle.y; + clickOffset = 0 } } |