From 1cf6abc8ba5547f12352467db8ce1c3d09921960 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 4 Apr 2017 17:41:14 +0200 Subject: Slider: react immediately when using a mouse The initial drag threshold is a necessary evil on touch to avoid conflicting with flickables, but leads to bad experience (QTBUG-47081) when using a mouse. Now that we have separate mouse and touch handling, we can apply immediate moves when using a mouse, but keep the old behavior on touch. Changing the behavior is simple, but auto tests need quite many tweaks so RangeSlider and Dial will be done separate follow up changes. [ChangeLog][Important Behavior Changes] Sliders and Dials now react immediately when using a mouse. Now the initial drag threshold applies only on touch, to avoid conflicting with flickables. Task-number: QTBUG-59920 Change-Id: Ifc1e6ed74c7894c3c854c975dff5238278827590 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickslider.cpp | 6 +++--- tests/auto/controls/data/tst_slider.qml | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/quicktemplates2/qquickslider.cpp b/src/quicktemplates2/qquickslider.cpp index fbf9755d..77e5856c 100644 --- a/src/quicktemplates2/qquickslider.cpp +++ b/src/quicktemplates2/qquickslider.cpp @@ -194,8 +194,6 @@ void QQuickSliderPrivate::handlePress(const QPointF &point) void QQuickSliderPrivate::handleMove(const QPointF &point) { Q_Q(QQuickSlider); - if (!q->keepMouseGrab() && !q->keepTouchGrab()) - return; const qreal oldPos = position; qreal pos = positionAt(point); if (snapMode == QQuickSlider::SnapAlways) @@ -621,6 +619,7 @@ void QQuickSlider::mousePressEvent(QMouseEvent *event) Q_D(QQuickSlider); QQuickControl::mousePressEvent(event); d->handlePress(event->localPos()); + d->handleMove(event->localPos()); } void QQuickSlider::mouseMoveEvent(QMouseEvent *event) @@ -675,7 +674,8 @@ void QQuickSlider::touchEvent(QTouchEvent *event) else setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().y() - d->pressPoint.y(), Qt::YAxis, &point)); } - d->handleMove(point.pos()); + if (keepTouchGrab()) + d->handleMove(point.pos()); } break; diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml index 40bb389d..b02e77d0 100644 --- a/tests/auto/controls/data/tst_slider.qml +++ b/tests/auto/controls/data/tst_slider.qml @@ -229,7 +229,7 @@ TestCase { var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) verify(movedSpy.valid) - mousePress(control, 0, 0, Qt.LeftButton) + mousePress(control, 0, control.height, Qt.LeftButton) compare(pressedSpy.count, ++pressedCount) compare(movedSpy.count, movedCount) compare(control.pressed, true) @@ -258,17 +258,17 @@ TestCase { compare(control.value, 0.5) compare(control.position, 0.5) - mousePress(control, control.width, control.height, Qt.LeftButton) + mousePress(control, control.width, 0, Qt.LeftButton) compare(pressedSpy.count, ++pressedCount) - compare(movedSpy.count, movedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, true) - compare(control.value, 0.5) - compare(control.position, 0.5) + compare(control.value, data.live ? 1.0 : 0.5) + compare(control.position, 1.0) // maximum on the right in horizontal vs. at the top in vertical mouseMove(control, control.width * 2, -control.height, 0) compare(pressedSpy.count, pressedCount) - compare(movedSpy.count, ++movedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, true) compare(control.value, data.live ? 1.0 : 0.5) compare(control.position, 1.0) @@ -617,8 +617,8 @@ TestCase { compare(pressedSpy.count, 3) compare(control.pressed, true) compare(control.value, 0.0) - compare(control.position, 0.0) - compare(control.visualPosition, 1.0) + compare(control.position, 1.0) + compare(control.visualPosition, 0.0) mouseMove(control, control.leftPadding + control.availableWidth * 0.5, control.height * 0.5, 0) compare(pressedSpy.count, 3) @@ -642,22 +642,22 @@ TestCase { compare(control.visualPosition, 0.5) } - function test_snapMode_data() { + function test_snapMode_data(immediate) { return [ { tag: "NoSnap", snapMode: Slider.NoSnap, from: 0, to: 2, values: [0, 0, 0.25], positions: [0, 0.1, 0.1] }, { tag: "SnapAlways (0..2)", snapMode: Slider.SnapAlways, from: 0, to: 2, values: [0.0, 0.0, 0.2], positions: [0.0, 0.1, 0.1] }, { tag: "SnapAlways (1..3)", snapMode: Slider.SnapAlways, from: 1, to: 3, values: [1.0, 1.0, 1.2], positions: [0.0, 0.1, 0.1] }, - { tag: "SnapAlways (-1..1)", snapMode: Slider.SnapAlways, from: -1, to: 1, values: [0.0, 0.0, -0.8], positions: [0.5, 0.1, 0.1] }, - { tag: "SnapAlways (1..-1)", snapMode: Slider.SnapAlways, from: 1, to: -1, values: [0.0, 0.0, 0.8], positions: [0.5, 0.1, 0.1] }, + { tag: "SnapAlways (-1..1)", snapMode: Slider.SnapAlways, from: -1, to: 1, values: [0.0, 0.0, -0.8], positions: [immediate ? 0.0 : 0.5, 0.1, 0.1] }, + { tag: "SnapAlways (1..-1)", snapMode: Slider.SnapAlways, from: 1, to: -1, values: [0.0, 0.0, 0.8], positions: [immediate ? 0.0 : 0.5, 0.1, 0.1] }, { tag: "SnapOnRelease (0..2)", snapMode: Slider.SnapOnRelease, from: 0, to: 2, values: [0.0, 0.0, 0.2], positions: [0.0, 0.1, 0.1] }, { tag: "SnapOnRelease (1..3)", snapMode: Slider.SnapOnRelease, from: 1, to: 3, values: [1.0, 1.0, 1.2], positions: [0.0, 0.1, 0.1] }, - { tag: "SnapOnRelease (-1..1)", snapMode: Slider.SnapOnRelease, from: -1, to: 1, values: [0.0, 0.0, -0.8], positions: [0.5, 0.1, 0.1] }, - { tag: "SnapOnRelease (1..-1)", snapMode: Slider.SnapOnRelease, from: 1, to: -1, values: [0.0, 0.0, 0.8], positions: [0.5, 0.1, 0.1] } + { tag: "SnapOnRelease (-1..1)", snapMode: Slider.SnapOnRelease, from: -1, to: 1, values: [0.0, 0.0, -0.8], positions: [immediate ? 0.0 : 0.5, 0.1, 0.1] }, + { tag: "SnapOnRelease (1..-1)", snapMode: Slider.SnapOnRelease, from: 1, to: -1, values: [0.0, 0.0, 0.8], positions: [immediate ? 0.0 : 0.5, 0.1, 0.1] } ] } function test_snapMode_mouse_data() { - return test_snapMode_data() + return test_snapMode_data(true) } function test_snapMode_mouse(data) { @@ -681,7 +681,7 @@ TestCase { } function test_snapMode_touch_data() { - return test_snapMode_data() + return test_snapMode_data(false) } function test_snapMode_touch(data) { -- cgit v1.2.3