From 3eeffae835b3474c8a3ca62125cb8ec24acdaa84 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Tue, 13 Dec 2016 11:38:23 +0100 Subject: Let pinchhandler operate on QQuickItem properties This requires coordinate system mapping that varies with the transformOrigin. The properties exposed from PinchHandler (rotation, scale and translation) are currently relative to the point when the pinch became active. (Therefore, rotation, will reset back to 0 when a new pinch is activated). Its still unclear how the properties that limits the transform should influence. With this patch, they are like this: * {min,max}imumRotation applies to the actual rotation of the item. * {min,max}imumScale applies to the actual scale of the item. * {min,max}imum{X,Y} applies to the actual position of the item. (This has some unfortunate side-effects when the item is scaled or rotated, since the items actual position will change as it rotates) In addition, the behavior described above means that the limits won't have any effect if there is no target item. Change-Id: I279fb03667cd75324e8337039ae2594658265d13 Reviewed-by: Shawn Rutledge --- tests/manual/pointer/pinchHandler.qml | 41 ++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'tests/manual') diff --git a/tests/manual/pointer/pinchHandler.qml b/tests/manual/pointer/pinchHandler.qml index 3ab196a10a..f317f361e2 100644 --- a/tests/manual/pointer/pinchHandler.qml +++ b/tests/manual/pointer/pinchHandler.qml @@ -44,25 +44,38 @@ import Qt.labs.handlers 1.0 Rectangle { width: 1024; height: 600 color: "#eee" + + function getTransformationDetails(item, pinchhandler) { + return "\n\npinch.scale:" + pinchhandler.scale.toFixed(2) + + "\npinch.rotation:" + pinchhandler.rotation.toFixed(2) + + "\npinch.translation:" + "(" + pinchhandler.translation.x.toFixed(2) + "," + pinchhandler.translation.y.toFixed(2) + ")" + + "\nrect.scale: " + item.scale.toFixed(2) + + "\nrect.rotation: " + item.rotation.toFixed(2) + + "\nrect.position: " + "(" + item.x.toFixed(2) + "," + item.y.toFixed(2) + ")" + } + Rectangle { - id: root - color: "black" - width: 900 - height: 600 - x: 100 + // Purpose of this item is just to make sure the rectangles are transformed into + // a coordinate system that is different from the scene coordinate system. + anchors.fill: parent + anchors.margins: 50 + color: "#ffe0e0e0" Rectangle { + id: rect2 width: 400 height: 300 color: "lightsteelblue" antialiasing: true + x: 100 + y: 200 + rotation: 30 + transformOrigin: Item.TopRight Text { anchors.centerIn: parent text: "Pinch with 2 fingers to scale, rotate and translate" - + "\ncurrent rotation: " + pinch2.rotation.toFixed(1) - + "\nscale: " + pinch2.scale.toFixed(1) - + "\ntranslation: " + pinch2.translation + + getTransformationDetails(rect2, pinch2) } PinchHandler { @@ -74,11 +87,12 @@ Rectangle { maximumScale: 3 minimumX: 0 maximumX: 600 - pointDistanceThreshold: 150 + pointDistanceThreshold: 0 } } Rectangle { + id: rect3 x: 500 width: 400 height: 300 @@ -88,9 +102,7 @@ Rectangle { Text { anchors.centerIn: parent text: "Pinch with 3 fingers to scale, rotate and translate\nDrag with 1 finger" - + "\ncurrent rotation " + pinch3.rotation.toFixed(1) - + "\nscale: " + pinch3.scale.toFixed(1) - + "\ntranslation: " + pinch3.translation + + getTransformationDetails(rect3, pinch3) } DragHandler { objectName: "DragHandler" } @@ -102,13 +114,12 @@ Rectangle { maximumScale: 10 } } - } Rectangle { id: centroidIndicator property QtObject pincher: pinch2.active ? pinch2 : pinch3 - x: pincher.centroid.x - y: pincher.centroid.y + x: pincher.centroid.x - radius + y: pincher.centroid.y - radius z: 1 visible: pincher.active radius: width / 2 -- cgit v1.2.3