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 bb7ba7667b ), 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>
This commit is contained in:
Jan Arve Sæther 2024-04-24 10:33:41 +02:00
parent 645e1ee76b
commit 75bcaf70e5
1 changed files with 38 additions and 0 deletions

View File

@ -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)
}
}
}