diff options
author | Jan Arve Saether <jan-arve.saether@qt.io> | 2016-09-02 17:07:57 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-09-16 14:46:13 +0000 |
commit | c364b935f06256ec7adfaf486ef35b3996152804 (patch) | |
tree | 7d78f8fcfa14d772c9365ac7c37a20ca752e0de1 /tests/manual/pointer | |
parent | b8106804c87f70c3be034dc3e191966293a8b877 (diff) |
Fix rotation in PinchHandler
If we want to allow rotation with more than 2 fingers, its not
straightforward to calculate the rotation angle, because we cannot anymore
calculate the angle between the two touchpoints.
The approach chosen was to calculate the angle between the centroid and
the touchpoints, and take the average between the angles.
Then, for the next event we calculated the new average of the angles.
However, this is not really reliable in some scenarios, suppose we have
these three angles:
0 120 240, avg = 360/3 = 120
next, touch points rotate clockwise with 2 degrees, and we get these
angles:
358 118 238, avg = 714/3 = 238
So, just by rotating all fingers by 2 degrees, we got a jump by 118
degrees "in average".
Instead we need to track the angles of *all* touch points, and when the
next touch event is received we calculate how much the angle has changed
per touch point. We then take the average of those angles as the effective
"rotation" of the PinchHandler
Change-Id: I2bfdf80b886751177efe81bcc7b698af0d2938e3
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/manual/pointer')
-rw-r--r-- | tests/manual/pointer/pinchHandler.qml | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/tests/manual/pointer/pinchHandler.qml b/tests/manual/pointer/pinchHandler.qml index e4482a249d..d163343a3e 100644 --- a/tests/manual/pointer/pinchHandler.qml +++ b/tests/manual/pointer/pinchHandler.qml @@ -54,18 +54,21 @@ Rectangle { Text { anchors.centerIn: parent - text: "Pinch with 2 fingers to scale & rotate\nDrag with 1 finger\ncurrent rotation " + pinch2.rotation.toFixed(1) + text: "Pinch with 2 fingers to scale, rotate and translate" + + "\ncurrent rotation: " + pinch2.rotation.toFixed(1) + + "\nscale: " + pinch2.scale.toFixed(1) + + "\ntranslation: " + pinch2.translation } - DragHandler { objectName: "DragHandler" } - PinchHandler { id: pinch2 objectName: "2-finger pinch" minimumRotation: -45 maximumRotation: 45 - minimumScale: 0.1 - maximumScale: 10 + minimumScale: 0.5 + maximumScale: 3 + minimumX: 0 + maximumX: 600 pointDistanceThreshold: 150 } } @@ -79,8 +82,10 @@ Rectangle { Text { anchors.centerIn: parent - text: "Pinch with 3 fingers to scale & rotate\ncurrent rotation " + pinch3.rotation.toFixed(1) + text: "Pinch with 3 fingers to scale, rotate and translate\nDrag with 1 finger" + + "\ncurrent rotation " + pinch3.rotation.toFixed(1) } + DragHandler { objectName: "DragHandler" } PinchHandler { id: pinch3 @@ -90,4 +95,17 @@ Rectangle { maximumScale: 10 } } + + Rectangle { + id: centroidIndicator + property QtObject pincher: pinch2.active ? pinch2 : pinch3 + x: pincher.centroid.x + y: pincher.centroid.y + z: 1 + visible: pincher.active + radius: width / 2 + width: 10 + height: width + color: "red" + } } |