From f5e0aad26351ecf760458a7fa5866532243f4cb5 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 5 Feb 2016 15:19:17 +0100 Subject: 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 --- tests/auto/controls/data/tst_slider.qml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') 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() + } } -- cgit v1.2.3