diff options
author | Mitch Curtis <mitch.curtis@theqtcompany.com> | 2016-04-15 16:41:26 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@theqtcompany.com> | 2016-04-19 10:41:44 +0000 |
commit | e253427f93248983d18055c5020094799a2c6b3b (patch) | |
tree | 6daec4a792e0a68b236f0c11a891e7cb72e08907 /tests | |
parent | 30b2d62262e4ecfadf89dc0ee34644bebe5194fc (diff) |
Dial: add wrap property
This works by preventing changes in position that are considered
too large. A change is considered too large when the difference
between the old and new positions is greater than or equal to 0.5
*and* the position of the mouse is below the center of the dial.
This effectively makes it impossible to drag the dial from left
to right when the mouse is below its center, but still allows
doing so above its center.
This is useful for applications such as volume dials, where a
large change can be dangerous.
Change-Id: I1d7800e5ba16dbe0642974b8e53d8fcd921a01d7
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_dial.qml | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_dial.qml b/tests/auto/controls/data/tst_dial.qml index e0eba27e..0f7a4f85 100644 --- a/tests/auto/controls/data/tst_dial.qml +++ b/tests/auto/controls/data/tst_dial.qml @@ -179,6 +179,7 @@ TestCase { } function test_dragging(data) { + verify(dial.wrap); dial.from = data.from; dial.to = data.to; @@ -210,6 +211,43 @@ TestCase { valueSpy.clear(); } + function test_nonWrapping() { + dial.wrap = false; + dial.value = 0; + + // Ensure that dragging from bottom left to bottom right doesn't work. + var yPos = dial.height * 0.75; + mousePress(dial, dial.width * 0.25, yPos, Qt.LeftButton); + var positionAtPress = dial.position; + mouseMove(dial, dial.width * 0.5, yPos, Qt.LeftButton); + compare(dial.position, positionAtPress); + mouseMove(dial, dial.width * 0.75, yPos, Qt.LeftButton); + compare(dial.position, positionAtPress); + mouseRelease(dial, dial.width * 0.75, yPos, Qt.LeftButton); + compare(dial.position, positionAtPress); + + // Try the same thing, but a bit higher. + yPos = dial.height * 0.6; + mousePress(dial, dial.width * 0.25, yPos, Qt.LeftButton); + positionAtPress = dial.position; + mouseMove(dial, dial.width * 0.5, yPos, Qt.LeftButton); + compare(dial.position, positionAtPress); + mouseMove(dial, dial.width * 0.75, yPos, Qt.LeftButton); + compare(dial.position, positionAtPress); + mouseRelease(dial, dial.width * 0.75, yPos, Qt.LeftButton); + compare(dial.position, positionAtPress); + + // Going from below the center of the dial to above it should work (once it gets above the center). + mousePress(dial, dial.width * 0.25, dial.height * 0.75, Qt.LeftButton); + positionAtPress = dial.position; + mouseMove(dial, dial.width * 0.5, dial.height * 0.6, Qt.LeftButton); + compare(dial.position, positionAtPress); + mouseMove(dial, dial.width * 0.75, dial.height * 0.4, Qt.LeftButton); + verify(dial.position > positionAtPress); + mouseRelease(dial, dial.width * 0.75, dial.height * 0.3, Qt.LeftButton); + verify(dial.position > positionAtPress); + } + property Component focusTest: Component { FocusScope { signal receivedKeyPress |