aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2015-10-08 12:48:06 +0200
committerMitch Curtis <mitch.curtis@theqtcompany.com>2015-10-14 11:58:33 +0000
commit090db511a36464c78f11df3b6596a56f09986951 (patch)
tree389bf7e9b04fa6cf7dfbc035e9568b98cf7b8e44 /tests/auto
parentb5b6fc732bb7a09996c06b1df3b71cf2548b0d7c (diff)
Add RangeSlider
This is basically Slider, except with two handles. It's used to specify a range of values. Task-number: QTBUG-48667 Change-Id: Ib4f9afe5dc8343e307610943d338a2b574a01e4d Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/accessibility/data/rangeslider.qml18
-rw-r--r--tests/auto/accessibility/tst_accessibility.cpp1
-rw-r--r--tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml4
-rw-r--r--tests/auto/activeFocusOnTab/tst_activeFocusOnTab.cpp44
-rw-r--r--tests/auto/controls/data/tst_rangeslider.qml580
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-rangeslider-background.qml11
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-rangeslider-disabled.qml8
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-rangeslider-first-handle-focused.qml8
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-rangeslider-first-handle.qml12
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-rangeslider-normal.qml7
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-rangeslider-second-handle-focused.qml8
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-rangeslider-second-handle.qml12
-rw-r--r--tests/auto/snippets/data/qtlabscontrols-rangeslider-track.qml12
13 files changed, 723 insertions, 2 deletions
diff --git a/tests/auto/accessibility/data/rangeslider.qml b/tests/auto/accessibility/data/rangeslider.qml
new file mode 100644
index 00000000..9262f3cd
--- /dev/null
+++ b/tests/auto/accessibility/data/rangeslider.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import Qt.labs.controls 1.0
+
+Window {
+ visible: true
+
+ RangeSlider {
+ id: rangeSlider
+ objectName: "rangeslider"
+ from: 0
+ to: 100
+ first.value: 25
+ second.value: 75
+ stepSize: 1
+ orientation: "Horizontal"
+ }
+}
diff --git a/tests/auto/accessibility/tst_accessibility.cpp b/tests/auto/accessibility/tst_accessibility.cpp
index 857cefd2..7baec700 100644
--- a/tests/auto/accessibility/tst_accessibility.cpp
+++ b/tests/auto/accessibility/tst_accessibility.cpp
@@ -78,6 +78,7 @@ void tst_accessibility::a11y_data()
QTest::newRow("PageIndicator") << "pageindicator" << 0x00000027 << ""; //QAccessible::Indicator
QTest::newRow("ProgressBar") << "progressbar" << 0x00000030 << ""; //QAccessible::ProgressBar
QTest::newRow("RadioButton") << "radiobutton" << 0x0000002D << "RadioButton"; //QAccessible::RadioButton
+ QTest::newRow("RangeSlider") << "rangeslider" << 0x00000033 << ""; //QAccessible::Slider
QTest::newRow("ScrollBar") << "scrollbar" << 0x00000003 << ""; //QAccessible::ScrollBar
QTest::newRow("ScrollIndicator") << "scrollindicator" << 0x00000027 << ""; //QAccessible::Indicator
QTest::newRow("Slider") << "slider" << 0x00000033 << ""; //QAccessible::Slider
diff --git a/tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml b/tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml
index 05cb464b..5ab0191e 100644
--- a/tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml
+++ b/tests/auto/activeFocusOnTab/data/activeFocusOnTab.qml
@@ -127,6 +127,10 @@ Item {
}
}
}
+ RangeSlider {
+ id: rangeslider
+ objectName: "rangeslider"
+ }
// ScrollBar
ScrollIndicator {
id: scrollindicator
diff --git a/tests/auto/activeFocusOnTab/tst_activeFocusOnTab.cpp b/tests/auto/activeFocusOnTab/tst_activeFocusOnTab.cpp
index 79532b45..88607514 100644
--- a/tests/auto/activeFocusOnTab/tst_activeFocusOnTab.cpp
+++ b/tests/auto/activeFocusOnTab/tst_activeFocusOnTab.cpp
@@ -162,7 +162,27 @@ void tst_activeFocusOnTab::allControls()
QVERIFY(item);
QVERIFY(item->hasActiveFocus());
- // Tab: radiobutton2->slider
+ // Tab: radiobutton2->rangeslider.first.handle
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
+ QGuiApplication::sendEvent(window, &key);
+ QVERIFY(key.isAccepted());
+
+ item = findItem<QQuickItem>(window->rootObject(), "rangeslider");
+ QVERIFY(item);
+ item = item->property("first").value<QObject*>()->property("handle").value<QQuickItem*>();
+ QVERIFY(item->hasActiveFocus());
+
+ // Tab: rangeslider.first.handle->rangeslider.second.handle
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
+ QGuiApplication::sendEvent(window, &key);
+ QVERIFY(key.isAccepted());
+
+ item = findItem<QQuickItem>(window->rootObject(), "rangeslider");
+ QVERIFY(item);
+ item = item->property("second").value<QObject*>()->property("handle").value<QQuickItem*>();
+ QVERIFY(item->hasActiveFocus());
+
+ // Tab: rangeslider.second.handle->slider
key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
QGuiApplication::sendEvent(window, &key);
QVERIFY(key.isAccepted());
@@ -279,7 +299,27 @@ void tst_activeFocusOnTab::allControls()
QVERIFY(item);
QVERIFY(item->hasActiveFocus());
- // BackTab: slider->radiobutton2
+ // BackTab: slider->rangeslider.second.handle
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
+ QGuiApplication::sendEvent(window, &key);
+ QVERIFY(key.isAccepted());
+
+ item = findItem<QQuickItem>(window->rootObject(), "rangeslider");
+ QVERIFY(item);
+ item = item->property("second").value<QObject*>()->property("handle").value<QQuickItem*>();
+ QVERIFY(item->hasActiveFocus());
+
+ // BackTab: rangeslider.second.handle->rangeslider.first.handle
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
+ QGuiApplication::sendEvent(window, &key);
+ QVERIFY(key.isAccepted());
+
+ item = findItem<QQuickItem>(window->rootObject(), "rangeslider");
+ QVERIFY(item);
+ item = item->property("first").value<QObject*>()->property("handle").value<QQuickItem*>();
+ QVERIFY(item->hasActiveFocus());
+
+ // BackTab: rangeslider.first.handle->radiobutton2
key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
QGuiApplication::sendEvent(window, &key);
QVERIFY(key.isAccepted());
diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml
new file mode 100644
index 00000000..345013f2
--- /dev/null
+++ b/tests/auto/controls/data/tst_rangeslider.qml
@@ -0,0 +1,580 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtTest 1.0
+import Qt.labs.controls 1.0
+
+TestCase {
+ id: testCase
+ width: 400
+ height: 400
+ visible: true
+ when: windowShown
+ name: "RangeSlider"
+
+ SignalSpy {
+ id: firstPressedSpy
+ signalName: "pressedChanged"
+ }
+
+ SignalSpy {
+ id: secondPressedSpy
+ signalName: "pressedChanged"
+ }
+
+ Component {
+ id: sliderComponent
+ RangeSlider {
+ id: slider
+
+ Component.onCompleted: {
+ first.handle.objectName = "firstHandle"
+ second.handle.objectName = "secondHandle"
+ }
+
+ Text {
+ text: "1"
+ parent: slider.first.handle
+ anchors.centerIn: parent
+ }
+
+ Text {
+ text: "2"
+ parent: slider.second.handle
+ anchors.centerIn: parent
+ }
+ }
+ }
+
+ function init() {
+ verify(!firstPressedSpy.target)
+ compare(firstPressedSpy.count, 0)
+
+ verify(!secondPressedSpy.target)
+ compare(secondPressedSpy.count, 0)
+ }
+
+ function cleanup() {
+ firstPressedSpy.target = null
+ firstPressedSpy.clear()
+ secondPressedSpy.target = null
+ secondPressedSpy.clear()
+ }
+
+ function test_defaults() {
+ var control = sliderComponent.createObject(testCase)
+ verify(control)
+
+ compare(control.stepSize, 0)
+ compare(control.snapMode, RangeSlider.NoSnap)
+ compare(control.orientation, Qt.Horizontal)
+
+ control.destroy()
+ }
+
+ function test_values() {
+ var control = sliderComponent.createObject(testCase)
+ verify(control)
+
+ compare(control.first.value, 0.0)
+ compare(control.second.value, 1.0)
+ control.first.value = 0.5
+ compare(control.first.value, 0.5)
+ control.first.value = 1.0
+ compare(control.first.value, 1.0)
+ control.first.value = -1.0
+ compare(control.first.value, 0.0)
+ control.first.value = 2.0
+ compare(control.first.value, 1.0)
+
+ control.first.value = 0
+ compare(control.first.value, 0.0)
+ control.second.value = 0.5
+ compare(control.second.value, 0.5)
+ control.first.value = 1
+ compare(control.first.value, 0.5)
+ control.second.value = 0
+ compare(control.second.value, 0.5)
+
+ control.destroy()
+ }
+
+ function test_range() {
+ var control = sliderComponent.createObject(testCase, { from: 0, to: 100, "first.value": 50, "second.value": 100 })
+ verify(control)
+
+ compare(control.from, 0)
+ compare(control.to, 100)
+ compare(control.first.value, 50)
+ compare(control.second.value, 100)
+ compare(control.first.position, 0.5)
+ compare(control.second.position, 1.0)
+
+ control.first.value = 1000
+ compare(control.first.value, 100)
+ compare(control.first.position, 1.0)
+
+ control.first.value = -1
+ compare(control.first.value, 0)
+ compare(control.first.position, 0)
+
+ control.from = 25
+ compare(control.from, 25)
+ compare(control.first.value, 25)
+ compare(control.first.position, 0)
+
+ control.to = 75
+ compare(control.to, 75)
+ compare(control.second.value, 75)
+ compare(control.second.position, 1.0)
+
+ control.first.value = 50
+ compare(control.first.value, 50)
+ compare(control.first.position, 0.5)
+
+ control.destroy()
+ }
+
+ function test_setValues() {
+ var control = sliderComponent.createObject(testCase)
+ verify(control)
+
+ compare(control.from, 0)
+ compare(control.to, 1)
+ compare(control.first.value, 0)
+ compare(control.second.value, 1)
+ compare(control.first.position, 0.0)
+ compare(control.second.position, 1.0)
+
+ control.setValues(100, 200)
+ compare(control.first.value, 1)
+ compare(control.second.value, 1)
+ compare(control.first.position, 1.0)
+ compare(control.second.position, 1.0)
+
+ control.to = 300;
+ control.setValues(100, 200)
+ compare(control.first.value, 100)
+ compare(control.second.value, 200)
+ compare(control.first.position, 0.333333)
+ compare(control.second.position, 0.666666)
+
+ control.destroy()
+ }
+
+ function test_inverted() {
+ var control = sliderComponent.createObject(testCase, { from: 1.0, to: -1.0 })
+ verify(control)
+
+ compare(control.from, 1.0)
+ compare(control.to, -1.0)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.5)
+ compare(control.second.value, 0.0);
+ compare(control.second.position, 0.5);
+
+ control.first.value = 2.0
+ compare(control.first.value, 1.0)
+ compare(control.first.position, 0.0)
+ compare(control.second.value, 0.0);
+ compare(control.second.position, 0.5);
+
+ control.first.value = -2.0
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.5)
+ compare(control.second.value, 0.0);
+ compare(control.second.position, 0.5);
+
+ control.first.value = 0.0
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.5)
+ compare(control.second.value, 0.0);
+ compare(control.second.position, 0.5);
+
+ control.destroy()
+ }
+
+ function test_visualPosition() {
+ var control = sliderComponent.createObject(testCase)
+ verify(control)
+
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.0)
+ compare(control.first.visualPosition, 0.0)
+ compare(control.second.value, 1.0)
+ compare(control.second.position, 1.0)
+ compare(control.second.visualPosition, 1.0)
+
+ control.first.value = 0.25
+ compare(control.first.value, 0.25)
+ compare(control.first.position, 0.25)
+ compare(control.first.visualPosition, 0.25)
+ compare(control.second.value, 1.0)
+ compare(control.second.position, 1.0)
+ compare(control.second.visualPosition, 1.0)
+
+ control.layoutDirection = Qt.RightToLeft
+ compare(control.first.visualPosition, 0.75)
+ compare(control.second.visualPosition, 0.0)
+
+ control.LayoutMirroring.enabled = true
+ compare(control.first.visualPosition, 0.25)
+ compare(control.second.visualPosition, 1.0)
+
+ control.layoutDirection = Qt.LeftToRight
+ compare(control.first.visualPosition, 0.75)
+ compare(control.second.visualPosition, 0.0)
+
+ control.LayoutMirroring.enabled = false
+ compare(control.first.visualPosition, 0.25)
+ compare(control.second.visualPosition, 1.0)
+
+ control.destroy()
+ }
+
+ function test_orientation() {
+ var control = sliderComponent.createObject(testCase)
+ verify(control)
+
+ compare(control.orientation, Qt.Horizontal)
+ verify(control.width > control.height)
+ control.orientation = Qt.Vertical
+ compare(control.orientation, Qt.Vertical)
+ verify(control.width < control.height)
+
+ control.destroy()
+ }
+
+ function test_mouse_data() {
+ return [
+ { tag: "horizontal", orientation: Qt.Horizontal },
+ { tag: "vertical", orientation: Qt.Vertical }
+ ]
+ }
+
+ function test_mouse(data) {
+ var control = sliderComponent.createObject(testCase, { orientation: data.orientation })
+ verify(control)
+
+ firstPressedSpy.target = control.first
+ verify(firstPressedSpy.valid)
+
+ secondPressedSpy.target = control.second
+ verify(secondPressedSpy.valid)
+
+ mousePress(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton)
+ compare(firstPressedSpy.count, 0)
+ compare(secondPressedSpy.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, 1.0)
+ compare(control.second.position, 1.0)
+
+ mouseRelease(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton)
+ compare(firstPressedSpy.count, 0)
+ compare(secondPressedSpy.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, 1.0)
+ compare(control.second.position, 1.0)
+
+ mousePress(control, 0, 0, Qt.LeftButton)
+ compare(firstPressedSpy.count, 0)
+ compare(secondPressedSpy.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, 1.0)
+ compare(control.second.position, 1.0)
+
+ mouseRelease(control, 0, 0, Qt.LeftButton)
+ compare(firstPressedSpy.count, 0)
+ compare(secondPressedSpy.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, 1.0)
+ compare(control.second.position, 1.0)
+
+ mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton)
+ compare(firstPressedSpy.count, 1)
+ compare(secondPressedSpy.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, 1.0)
+ compare(control.second.position, 1.0)
+
+ var horizontal = control.orientation === Qt.Horizontal
+ var toX = horizontal ? control.width * 0.5 : control.first.handle.x
+ var toY = horizontal ? control.first.handle.y : control.height * 0.5
+ mouseMove(control, toX, toY, Qt.LeftButton)
+ compare(firstPressedSpy.count, 1)
+ compare(secondPressedSpy.count, 0)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.5)
+ compare(control.first.visualPosition, 0.5)
+ compare(control.second.pressed, false)
+ compare(control.second.value, 1.0)
+ compare(control.second.position, 1.0)
+ compare(control.second.visualPosition, horizontal ? 1.0 : 0.0)
+
+ control.destroy()
+ }
+
+ function test_overlappingHandles() {
+ var control = sliderComponent.createObject(testCase, { orientation: data.orientation })
+ verify(control)
+
+ // By default, we force the second handle to be after the first in
+ // terms of stacking order *and* z value.
+ compare(control.second.handle.z, 1)
+ compare(control.first.handle.z, 0)
+ control.first.value = 0
+ control.second.value = 0
+
+ // Both are at the same position, so it doesn't matter whose coordinates we use.
+ mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton)
+ verify(control.second.pressed)
+ compare(control.second.handle.z, 1)
+ compare(control.first.handle.z, 0)
+
+ // Move the second handle out of the way.
+ mouseMove(control, control.width, control.first.handle.y, Qt.LeftButton)
+ mouseRelease(control, control.width, control.first.handle.y, Qt.LeftButton)
+ verify(!control.second.pressed)
+ compare(control.second.value, 1.0)
+ compare(control.second.handle.z, 1)
+ compare(control.first.handle.z, 0)
+
+ // Move the first handle on top of the second.
+ mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton)
+ verify(control.first.pressed)
+ compare(control.first.handle.z, 1)
+ compare(control.second.handle.z, 0)
+
+ mouseMove(control, control.width, control.first.handle.y, Qt.LeftButton)
+ mouseRelease(control, control.width, control.first.handle.y, Qt.LeftButton)
+ verify(!control.first.pressed)
+ compare(control.first.handle.z, 1)
+ compare(control.second.handle.z, 0)
+
+ // The most recently pressed handle (the first) should have the higher z value.
+ mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton)
+ verify(control.first.pressed)
+ compare(control.first.handle.z, 1)
+ compare(control.second.handle.z, 0)
+
+ mouseRelease(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton)
+ verify(!control.first.pressed)
+ compare(control.first.handle.z, 1)
+ compare(control.second.handle.z, 0)
+
+ control.destroy()
+ }
+
+ function test_keys_data() {
+ return [
+ { tag: "horizontal", orientation: Qt.Horizontal, decrease: Qt.Key_Left, increase: Qt.Key_Right },
+ { tag: "vertical", orientation: Qt.Vertical, decrease: Qt.Key_Down, increase: Qt.Key_Up }
+ ]
+ }
+
+ function test_keys(data) {
+ var control = sliderComponent.createObject(testCase, { orientation: data.orientation })
+ verify(control)
+
+ var pressedCount = 0
+
+ firstPressedSpy.target = control.first
+ verify(firstPressedSpy.valid)
+
+ control.first.handle.forceActiveFocus()
+ verify(control.first.handle.activeFocus)
+
+ control.first.value = 0.5
+
+ for (var d1 = 1; d1 <= 10; ++d1) {
+ keyPress(data.decrease)
+ compare(control.first.pressed, true)
+ compare(firstPressedSpy.count, ++pressedCount)
+
+ compare(control.first.value, Math.max(0.0, 0.5 - d1 * 0.1))
+ compare(control.first.value, control.first.position)
+
+ keyRelease(data.decrease)
+ compare(control.first.pressed, false)
+ compare(firstPressedSpy.count, ++pressedCount)
+ }
+
+ for (var i1 = 1; i1 <= 20; ++i1) {
+ keyPress(data.increase)
+ compare(control.first.pressed, true)
+ compare(firstPressedSpy.count, ++pressedCount)
+
+ compare(control.first.value, Math.min(1.0, 0.0 + i1 * 0.1))
+ compare(control.first.value, control.first.position)
+
+ keyRelease(data.increase)
+ compare(control.first.pressed, false)
+ compare(firstPressedSpy.count, ++pressedCount)
+ }
+
+ control.first.value = 0;
+ control.stepSize = 0.25
+
+ pressedCount = 0;
+ secondPressedSpy.target = control.second
+ verify(secondPressedSpy.valid)
+
+ control.second.handle.forceActiveFocus()
+ verify(control.second.handle.activeFocus)
+
+ for (var d2 = 1; d2 <= 10; ++d2) {
+ keyPress(data.decrease)
+ compare(control.second.pressed, true)
+ compare(secondPressedSpy.count, ++pressedCount)
+
+ compare(control.second.value, Math.max(0.0, 1.0 - d2 * 0.25))
+ compare(control.second.value, control.second.position)
+
+ keyRelease(data.decrease)
+ compare(control.second.pressed, false)
+ compare(secondPressedSpy.count, ++pressedCount)
+ }
+
+ for (var i2 = 1; i2 <= 10; ++i2) {
+ keyPress(data.increase)
+ compare(control.second.pressed, true)
+ compare(secondPressedSpy.count, ++pressedCount)
+
+ compare(control.second.value, Math.min(1.0, 0.0 + i2 * 0.25))
+ compare(control.second.value, control.second.position)
+
+ keyRelease(data.increase)
+ compare(control.second.pressed, false)
+ compare(secondPressedSpy.count, ++pressedCount)
+ }
+
+ control.destroy()
+ }
+
+ function test_padding() {
+ // test with "unbalanced" paddings (left padding != right padding) to ensure
+ // that the slider position calculation is done taking padding into account
+ // ==> the position is _not_ 0.5 in the middle of the control
+ var control = sliderComponent.createObject(testCase, { leftPadding: 10, rightPadding: 20 })
+ verify(control)
+
+ firstPressedSpy.target = control.first
+ verify(firstPressedSpy.valid)
+
+ mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton)
+ compare(firstPressedSpy.count, 1)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.0)
+ compare(control.first.visualPosition, 0.0)
+
+ mouseMove(control, control.leftPadding + control.availableWidth * 0.5, control.height * 0.5, 0, Qt.LeftButton)
+ compare(firstPressedSpy.count, 1)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.5)
+ compare(control.first.visualPosition, 0.5)
+
+ mouseMove(control, control.width * 0.5, control.height * 0.5, 0, Qt.LeftButton)
+ compare(firstPressedSpy.count, 1)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.0)
+ verify(control.first.position > 0.5)
+ verify(control.first.visualPosition > 0.5)
+
+ mouseRelease(control, control.leftPadding + control.availableWidth * 0.5, control.height * 0.5, Qt.LeftButton)
+ compare(firstPressedSpy.count, 2)
+ compare(control.first.pressed, false)
+ compare(control.first.value, 0.5)
+ compare(control.first.position, 0.5)
+ compare(control.first.visualPosition, 0.5)
+
+ // RTL
+ control.first.value = 0
+ control.layoutDirection = Qt.RightToLeft
+
+ mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton)
+ compare(firstPressedSpy.count, 3)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.0)
+ compare(control.first.visualPosition, 1.0)
+
+ mouseMove(control, control.leftPadding + control.availableWidth * 0.5, control.height * 0.5, 0, Qt.LeftButton)
+ compare(firstPressedSpy.count, 3)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.0)
+ compare(control.first.position, 0.5)
+ compare(control.first.visualPosition, 0.5)
+
+ mouseMove(control, control.width * 0.5, control.height * 0.5, 0, Qt.LeftButton)
+ compare(firstPressedSpy.count, 3)
+ compare(control.first.pressed, true)
+ compare(control.first.value, 0.0)
+ verify(control.first.position < 0.5)
+ verify(control.first.visualPosition > 0.5)
+
+ mouseRelease(control, control.leftPadding + control.availableWidth * 0.5, control.height * 0.5, Qt.LeftButton)
+ compare(firstPressedSpy.count, 4)
+ compare(control.first.pressed, false)
+ compare(control.first.value, 0.5)
+ compare(control.first.position, 0.5)
+ compare(control.first.visualPosition, 0.5)
+
+ control.destroy()
+ }
+}
diff --git a/tests/auto/snippets/data/qtlabscontrols-rangeslider-background.qml b/tests/auto/snippets/data/qtlabscontrols-rangeslider-background.qml
new file mode 100644
index 00000000..88a97a70
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-rangeslider-background.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+RangeSlider {
+ first.value: 0.25
+ second.value: 0.75
+ background: Rectangle {
+ color: "transparent"
+ border.color: "red"
+ }
+}
diff --git a/tests/auto/snippets/data/qtlabscontrols-rangeslider-disabled.qml b/tests/auto/snippets/data/qtlabscontrols-rangeslider-disabled.qml
new file mode 100644
index 00000000..648e283d
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-rangeslider-disabled.qml
@@ -0,0 +1,8 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+RangeSlider {
+ first.value: 0.25
+ second.value: 0.75
+ enabled: false
+}
diff --git a/tests/auto/snippets/data/qtlabscontrols-rangeslider-first-handle-focused.qml b/tests/auto/snippets/data/qtlabscontrols-rangeslider-first-handle-focused.qml
new file mode 100644
index 00000000..03241df2
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-rangeslider-first-handle-focused.qml
@@ -0,0 +1,8 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+RangeSlider {
+ first.value: 0.25
+ second.value: 0.75
+ first.handle.focus: true
+}
diff --git a/tests/auto/snippets/data/qtlabscontrols-rangeslider-first-handle.qml b/tests/auto/snippets/data/qtlabscontrols-rangeslider-first-handle.qml
new file mode 100644
index 00000000..a9a28d90
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-rangeslider-first-handle.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+RangeSlider {
+ first.value: 0.25
+ second.value: 0.75
+ Rectangle {
+ anchors.fill: first.handle
+ color: "transparent"
+ border.color: "red"
+ }
+}
diff --git a/tests/auto/snippets/data/qtlabscontrols-rangeslider-normal.qml b/tests/auto/snippets/data/qtlabscontrols-rangeslider-normal.qml
new file mode 100644
index 00000000..51cdacd2
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-rangeslider-normal.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+RangeSlider {
+ first.value: 0.25
+ second.value: 0.75
+}
diff --git a/tests/auto/snippets/data/qtlabscontrols-rangeslider-second-handle-focused.qml b/tests/auto/snippets/data/qtlabscontrols-rangeslider-second-handle-focused.qml
new file mode 100644
index 00000000..c820ed66
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-rangeslider-second-handle-focused.qml
@@ -0,0 +1,8 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+RangeSlider {
+ first.value: 0.25
+ second.value: 0.75
+ second.handle.focus: true
+}
diff --git a/tests/auto/snippets/data/qtlabscontrols-rangeslider-second-handle.qml b/tests/auto/snippets/data/qtlabscontrols-rangeslider-second-handle.qml
new file mode 100644
index 00000000..5edce3f1
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-rangeslider-second-handle.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+RangeSlider {
+ first.value: 0.25
+ second.value: 0.75
+ Rectangle {
+ anchors.fill: second.handle
+ color: "transparent"
+ border.color: "red"
+ }
+}
diff --git a/tests/auto/snippets/data/qtlabscontrols-rangeslider-track.qml b/tests/auto/snippets/data/qtlabscontrols-rangeslider-track.qml
new file mode 100644
index 00000000..b39e7541
--- /dev/null
+++ b/tests/auto/snippets/data/qtlabscontrols-rangeslider-track.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+RangeSlider {
+ first.value: 0.25
+ second.value: 0.75
+ Rectangle {
+ anchors.fill: track
+ color: "transparent"
+ border.color: "red"
+ }
+}