aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2024-04-24 10:33:41 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2024-04-25 07:04:32 +0000
commit75bcaf70e5c871a15abb54f4e4eed06419f33379 (patch)
treee371c407a654d56350e50f8f2fa93ca2dfe382d0
parent645e1ee76b56fe351170bd76d54dd08d56bb917f (diff)
Add autotest for dialing a non-squared Dial
There was a bug where the Dial background would be aligned top-left on some styles (Universal). This caused issues with mouse/touch input because the Dial assumed that the Dial background was centered. This was especially noticeable when the Dial was much wider than taller, since the Dial background was unexpectedly at x == 0: If you tried to move the handle to almost the middle (e.g. width/2 - 1) it would move the handle towards its left side (but the mouse cursor was on the right side of the visual Dial background because it was left-aligned). Also, just clicking on the handle would cause it to jump to a different position in most cases. While investigating, this appears to have been fixed (probably with bb7ba7667b4cf3565aa1849d08cc71b9ac011e77 ), so my fix is not needed any longer. However, in order to avoid regressions, add the autotest. Change-Id: Iba9b599dd2945695a973e7de57f54f9907035a8d Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--tests/auto/quickcontrols/controls/data/tst_dial.qml38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/quickcontrols/controls/data/tst_dial.qml b/tests/auto/quickcontrols/controls/data/tst_dial.qml
index cfe901bc79..1f2b9fdd5c 100644
--- a/tests/auto/quickcontrols/controls/data/tst_dial.qml
+++ b/tests/auto/quickcontrols/controls/data/tst_dial.qml
@@ -826,4 +826,42 @@ TestCase {
compare(dial.endAngle, 300.)
}
}
+
+ function test_notSquareGeometry() {
+ let dial = createTemporaryObject(dialComponent, testCase)
+ verify(dial);
+ if (!dial.handle) {
+ skip("Test cannot run on styles where handle == null (macOS style)")
+ }
+ dial.from = 0
+ dial.to = 1
+ dial.live = true
+ dial.wrap = true
+ dial.startAngle = -180
+ dial.endAngle = 180
+
+ // Dial input handling always assumes that the dial is in the *center*.
+ // Instantiate a Dial with a geometries of 400x100 and then 100x400
+ // Some styles always could wrongly align the Dial background and handle in the topLeft
+ // corner. Pressing in the handle would cause the Dial to move because the dial
+ // assumes that the "Dial circle" is center aligned in its geometry.
+ for (let pass = 0; pass < 2; ++pass) {
+ if (pass === 0) {
+ dial.width = testCase.width
+ dial.height = 100
+ } else {
+ dial.width = 100
+ dial.height = testCase.height
+ }
+
+ let val = pass * 0.25
+ dial.value = val
+ // find coordinates in the middle of the handle
+ let pt2 = dial.mapFromItem(dial.handle, dial.handle.width/2, dial.handle.height/2)
+ // press the knob in the middle. It shouldn't move (except from due to rounding errors)
+ mousePress(dial, pt2.x, pt2.y)
+ fuzzyCompare(dial.value, val, 0.1)
+ }
+ }
+
}