aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2023-04-18 15:47:43 +0200
committerDoris Verria <doris.verria@qt.io>2023-05-04 03:33:13 +0000
commite5e5ab7bd3c659fee04a432d53a5f15d8fd79b9d (patch)
treed19ed39d54d436982a88ccdcc04a8074797f1ada /tests
parent7973b58a1bdf59ea05bcc5daeefeca143a00a8fe (diff)
RangeSlider: Don't update position only if mouse/touch is grabbed
A mouseClick will cause the RangeSlider handle to move to the click position and we should expect the same for a touch press. We update the position of the handle in handleRelease if keepMouse/ TouchGrab is set to true. However, we don't grab the touch on a touch press in case eg.: a flickable wants to steal the event. So we can remove the check as we shouldn't update the position only if grabbed. This makes the behavior similar to the slider too. Fixes: QTBUG-112945 Change-Id: Id2cf99416a52b5e42989a4adda1532e3ac550a93 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit f6fb9252c6af824ee4544b34a039c20872c5b4ed)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quickcontrols/controls/data/tst_rangeslider.qml157
1 files changed, 153 insertions, 4 deletions
diff --git a/tests/auto/quickcontrols/controls/data/tst_rangeslider.qml b/tests/auto/quickcontrols/controls/data/tst_rangeslider.qml
index 91e366c819..60380a5b91 100644
--- a/tests/auto/quickcontrols/controls/data/tst_rangeslider.qml
+++ b/tests/auto/quickcontrols/controls/data/tst_rangeslider.qml
@@ -439,7 +439,8 @@ TestCase {
// Press and release the first handle without moving it.
var touch = touchEvent(control)
- touch.press(0, control, control.width * 0.25, control.height * 0.75).commit()
+ control.setValues(0, 1);
+ touch.press(0, control, control.leftPadding, control.height - control.bottomPadding - 1).commit()
compare(firstPressedSpy.count, 1)
compare(firstMovedSpy.count, 0)
compare(secondPressedSpy.count, 0)
@@ -451,7 +452,7 @@ TestCase {
compare(control.second.value, 1.0)
compare(control.second.position, 1.0)
- touch.release(0, control, control.width * 0.25, control.height * 0.75).commit()
+ touch.release(0, control, control.leftPadding, control.height - control.bottomPadding - 1).commit()
compare(firstPressedSpy.count, 2)
compare(firstMovedSpy.count, 0)
compare(secondPressedSpy.count, 0)
@@ -464,7 +465,7 @@ TestCase {
compare(control.second.position, 1.0)
// Press and release the second handle without moving it.
- touch.press(0, control, control.width * 0.75, control.height * 0.25).commit()
+ touch.press(0, control, control.width - control.rightPadding - 1, control.topPadding).commit()
compare(firstPressedSpy.count, 2)
compare(secondPressedSpy.count, 1)
compare(control.first.pressed, false)
@@ -474,7 +475,7 @@ TestCase {
compare(control.second.value, 1.0)
compare(control.second.position, 1.0)
- touch.release(0, control, control.width * 0.75, control.height * 0.25).commit()
+ touch.release(0, control, control.width - control.rightPadding - 1, control.topPadding).commit()
compare(firstPressedSpy.count, 2)
compare(secondPressedSpy.count, 2)
compare(control.first.pressed, false)
@@ -1081,4 +1082,152 @@ TestCase {
compare(control.valueAt(0.5), data.values[2])
compare(control.valueAt(1.0), data.values[3])
}
+
+ function test_updatePositionOnPress() {
+ var control = createTemporaryObject(sliderComponent, testCase)
+ verify(control)
+
+ var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"})
+ verify(firstPressedSpy.valid)
+
+ var firstMovedSpy = signalSpy.createObject(control, {target: control.first, signalName: "moved"})
+ verify(firstMovedSpy.valid)
+
+ var secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"})
+ verify(secondPressedSpy.valid)
+
+ var secondMovedSpy = signalSpy.createObject(control, {target: control.second, signalName: "moved"})
+ verify(secondMovedSpy.valid)
+
+ // Touch press and release on the left corner
+ control.setValues(0.2, 0.8)
+ compare(control.first.value, 0.2)
+ compare(control.second.value, 0.8)
+ var touch = touchEvent(control)
+ touch.press(0, control, 0, control.height * 0.75).commit()
+ compare(firstPressedSpy.count, 1)
+ compare(firstMovedSpy.count, 0)
+ compare(secondPressedSpy.count, 0)
+ compare(secondMovedSpy.count, 0)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.2)
+ compare(control.first.position, 0.2)
+ compare(control.second.pressed, false)
+ compare(control.second.value, 0.8)
+ compare(control.second.position, 0.8)
+
+ touch.release(0, control, 0, control.height * 0.75).commit()
+ compare(firstPressedSpy.count, 2)
+ compare(firstMovedSpy.count, 1)
+ compare(secondPressedSpy.count, 0)
+ compare(secondMovedSpy.count, 0)
+ compare(control.first.pressed, false)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.0)
+ compare(control.second.pressed, false)
+ compare(control.second.value, 0.8)
+ compare(control.second.position, 0.8)
+
+ firstPressedSpy.clear()
+ firstMovedSpy.clear()
+ secondPressedSpy.clear()
+ secondMovedSpy.clear()
+
+ // Touch press and release on the right corner
+ // On touch, the handle position is updated on release
+ control.setValues(0.2, 0.8)
+ compare(control.first.value, 0.2)
+ compare(control.second.value, 0.8)
+ var touch = touchEvent(control)
+ touch.press(0, control, control.width - control.rightPadding - 1, control.height * 0.75).commit()
+ compare(secondPressedSpy.count, 1)
+ compare(secondMovedSpy.count, 0)
+ compare(firstPressedSpy.count, 0)
+ compare(firstMovedSpy.count, 0)
+ compare(control.second.pressed, true)
+ compare(control.second.value, 0.8)
+ compare(control.second.position, 0.8)
+ compare(control.first.pressed, false)
+ compare(control.first.value, 0.2)
+ compare(control.first.position, 0.2)
+
+ touch.release(0, control, control.width - control.rightPadding - 1, control.height * 0.75).commit()
+ compare(secondPressedSpy.count, 2)
+ compare(secondMovedSpy.count, 1)
+ compare(firstPressedSpy.count, 0)
+ compare(firstMovedSpy.count, 0)
+ compare(control.second.pressed, false)
+ compare(control.second.value, 1.0)
+ compare(control.second.position, 1.0)
+ compare(control.first.pressed, false)
+ compare(control.first.value, 0.2)
+ compare(control.first.position, 0.2)
+
+ firstPressedSpy.clear()
+ firstMovedSpy.clear()
+ secondPressedSpy.clear()
+ secondMovedSpy.clear()
+
+ // Mouse press and release on the left corner
+ // On mouse, the position is immediately updated on press
+ control.setValues(0.2, 0.8)
+ compare(control.first.value, 0.2)
+ compare(control.second.value, 0.8)
+ mousePress(control, 0, control.height * 0.75, Qt.LeftButton)
+ compare(firstPressedSpy.count, 1)
+ compare(firstMovedSpy.count, 1)
+ compare(secondPressedSpy.count, 0)
+ compare(secondMovedSpy.count, 0)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.0)
+ compare(control.second.pressed, false)
+ compare(control.second.value, 0.8)
+ compare(control.second.position, 0.8)
+
+ mouseRelease(control, 0, control.height * 0.75, Qt.LeftButton)
+ compare(firstPressedSpy.count, 2)
+ compare(firstMovedSpy.count, 1)
+ compare(secondPressedSpy.count, 0)
+ compare(secondMovedSpy.count, 0)
+ compare(control.first.pressed, false)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.0)
+ compare(control.second.pressed, false)
+ compare(control.second.value, 0.8)
+ compare(control.second.position, 0.8)
+
+ firstPressedSpy.clear()
+ firstMovedSpy.clear()
+ secondPressedSpy.clear()
+ secondMovedSpy.clear()
+
+ // Mouse press and release on the right corner
+ control.setValues(0.2, 0.8)
+ compare(control.first.value, 0.2)
+ compare(control.second.value, 0.8)
+ mousePress(control, control.width - control.rightPadding - 1, control.height * 0.75, Qt.LeftButton)
+ compare(secondPressedSpy.count, 1)
+ compare(secondMovedSpy.count, 1)
+ compare(firstPressedSpy.count, 0)
+ compare(firstMovedSpy.count, 0)
+ compare(control.second.pressed, true)
+ compare(control.second.value, 1.0)
+ compare(control.second.position, 1.0)
+ compare(control.first.pressed, false)
+ compare(control.first.value, 0.2)
+ compare(control.first.position, 0.2)
+
+ mouseRelease(control, control.width - control.rightPadding - 1, control.height * 0.75, Qt.LeftButton)
+ compare(secondPressedSpy.count, 2)
+ compare(secondMovedSpy.count, 1)
+ compare(firstPressedSpy.count, 0)
+ compare(firstMovedSpy.count, 0)
+ compare(control.second.pressed, false)
+ compare(control.second.value, 1.0)
+ compare(control.second.position, 1.0)
+ compare(control.first.pressed, false)
+ compare(control.first.value, 0.2)
+ compare(control.first.position, 0.2)
+ }
}