diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-05 15:19:17 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-08 10:31:44 +0000 |
commit | f5e0aad26351ecf760458a7fa5866532243f4cb5 (patch) | |
tree | 165f3d3b30739cd41cb7af8a6da86e325b73808e /tests/auto/controls/data/tst_slider.qml | |
parent | acacc09f85a4f4bafc05819986de55667fd42111 (diff) |
Slider: fix stepSize handling when snapping is enabled
The value range and step size are configurable, whereas position is
always in the range [0.0..1.0]. The snap handling was applying step
size to the position as is, without taking the value range into
account. Thus, snapping worked correctly only for the default
[0.0..1.0] value range, which happens to match with the position range.
Change-Id: If2f48d36c95554de25598d507842576a49e643b9
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'tests/auto/controls/data/tst_slider.qml')
-rw-r--r-- | tests/auto/controls/data/tst_slider.qml | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml index 5957442f..53e2fb8f 100644 --- a/tests/auto/controls/data/tst_slider.qml +++ b/tests/auto/controls/data/tst_slider.qml @@ -439,4 +439,36 @@ TestCase { control.destroy() } + + function test_snapMode_data() { + return [ + { tag: "NoSnap", snapMode: Slider.NoSnap, values: [0, 0, 0.25], positions: [0, 0.1, 0.1] }, + { tag: "SnapAlways", snapMode: Slider.SnapAlways, values: [0, 0, 0.2], positions: [0, 0.1, 0.1] }, + { tag: "SnapOnRelease", snapMode: Slider.SnapOnRelease, values: [0, 0, 0.2], positions: [0, 0.1, 0.1] } + ] + } + + function test_snapMode(data) { + var control = slider.createObject(testCase, {snapMode: data.snapMode, from: 0, to: 2, stepSize: 0.2}) + verify(control) + + function sliderCompare(left, right) { + return Math.abs(left - right) < 0.05 + } + + mousePress(control, control.leftPadding) + compare(control.value, data.values[0]) + compare(control.position, data.positions[0]) + + mouseMove(control, control.leftPadding + 0.15 * (control.availableWidth + control.handle.width / 2)) + + verify(sliderCompare(control.value, data.values[1])) + verify(sliderCompare(control.position, data.positions[1])) + + mouseRelease(control, control.leftPadding + 0.15 * (control.availableWidth + control.handle.width / 2)) + verify(sliderCompare(control.value, data.values[2])) + verify(sliderCompare(control.position, data.positions[2])) + + control.destroy() + } } |