From ca7cdd71ee33f0d77eb6bf1367d2532e26155cb2 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 11 Jun 2018 07:38:46 +0200 Subject: Make DragHandler a MultiPointHandler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That is, minimumPointCount can now be set to a value > 1 to require multiple fingers to do the dragging, or to track the displacement of multiple fingers to adjust some value (such as the tilt of a map). Task-number: QTBUG-68106 Change-Id: Ib35823e36deb81c8b277d3070fcc758c7c019564 Reviewed-by: Jan Arve Sæther --- tests/manual/pointer/content/FakeFlickable.qml | 2 +- tests/manual/pointer/flingAnimation.qml | 6 +-- tests/manual/pointer/map.qml | 14 +++++++ .../pointer/singlePointHandlerProperties.qml | 43 +++++++++++----------- 4 files changed, 39 insertions(+), 26 deletions(-) (limited to 'tests/manual') diff --git a/tests/manual/pointer/content/FakeFlickable.qml b/tests/manual/pointer/content/FakeFlickable.qml index 5a20a6825a..ffb5c4e914 100644 --- a/tests/manual/pointer/content/FakeFlickable.qml +++ b/tests/manual/pointer/content/FakeFlickable.qml @@ -67,7 +67,7 @@ Item { DragHandler { id: dragHandler - onActiveChanged: if (!active) anim.restart(point.velocity) + onActiveChanged: if (!active) anim.restart(centroid.velocity) } MomentumAnimation { id: anim diff --git a/tests/manual/pointer/flingAnimation.qml b/tests/manual/pointer/flingAnimation.qml index b17429f4e4..2bc6de7065 100644 --- a/tests/manual/pointer/flingAnimation.qml +++ b/tests/manual/pointer/flingAnimation.qml @@ -90,7 +90,7 @@ Rectangle { objectName: "dragHandler" + index onActiveChanged: { if (!active) - anim.restart(point.velocity) + anim.restart(centroid.velocity) } } Rectangle { @@ -103,12 +103,12 @@ Rectangle { Rectangle { visible: width > 0 - width: dragHandler.point.velocity.length() * 100 + width: dragHandler.centroid.velocity.length() * 100 height: 2 x: ball.width / 2 y: ball.height / 2 z: -1 - rotation: Math.atan2(dragHandler.point.velocity.y, dragHandler.point.velocity.x) * 180 / Math.PI + rotation: Math.atan2(dragHandler.centroid.velocity.y, dragHandler.centroid.velocity.x) * 180 / Math.PI transformOrigin: Item.BottomLeft antialiasing: true diff --git a/tests/manual/pointer/map.qml b/tests/manual/pointer/map.qml index ae7ec042d3..3ed732b523 100644 --- a/tests/manual/pointer/map.qml +++ b/tests/manual/pointer/map.qml @@ -39,6 +39,7 @@ Item { y: (parent.height - height) / 2 width: image.width height: image.height + transform: Rotation { id: tilt; origin.x: width / 2; origin.y: height / 2; axis { x: 1; y: 0; z: 0 } } Image { id: image @@ -57,16 +58,29 @@ Item { PinchHandler { id: pinch + objectName: "two-point pinch" target: map minimumScale: 0.1 maximumScale: 10 onActiveChanged: if (!active) reRenderIfNecessary() + grabPermissions: PinchHandler.TakeOverForbidden // don't allow takeover if pinch has started } DragHandler { + objectName: "single-point drag" target: map } + DragHandler { + id: tiltHandler + objectName: "two-point tilt" + minimumPointCount: 2 + maximumPointCount: 2 + xAxis.enabled: false + target: null + onTranslationChanged: tilt.angle = translation.y / -2 + } + function reRenderIfNecessary() { var newSourceWidth = image.sourceSize.width * pinch.scale var ratio = newSourceWidth / image.sourceSize.width diff --git a/tests/manual/pointer/singlePointHandlerProperties.qml b/tests/manual/pointer/singlePointHandlerProperties.qml index 40a4f49e5e..6ee88f9f9d 100644 --- a/tests/manual/pointer/singlePointHandlerProperties.qml +++ b/tests/manual/pointer/singlePointHandlerProperties.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the manual tests of the Qt Toolkit. @@ -36,11 +36,11 @@ Rectangle { Item { id: crosshairs - x: dragHandler.point.position.x - width / 2 - y: dragHandler.point.position.y - height / 2 + x: dragHandler.centroid.position.x - width / 2 + y: dragHandler.centroid.position.y - height / 2 width: parent.width / 2; height: parent.height / 2 visible: dragHandler.active - rotation: dragHandler.point.rotation + rotation: dragHandler.centroid.rotation Rectangle { color: "goldenrod" @@ -56,7 +56,7 @@ Rectangle { } Rectangle { color: "goldenrod" - width: Math.max(2, 50 * dragHandler.point.pressure) + width: Math.max(2, 50 * dragHandler.centroid.pressure) height: width radius: width / 2 anchors.centerIn: parent @@ -69,9 +69,9 @@ Rectangle { implicitHeight: label.implicitHeight Text { id: label - text: 'id: ' + dragHandler.point.id.toString(16) + " uid: " + dragHandler.point.uniqueId.numericId + - '\npos: (' + dragHandler.point.position.x.toFixed(2) + ', ' + dragHandler.point.position.y.toFixed(2) + ')' + - '\nmodifiers: ' + dragHandler.point.modifiers.toString(16) + text: 'id: ' + dragHandler.centroid.id.toString(16) + " uid: " + dragHandler.centroid.uniqueId.numericId + + '\npos: (' + dragHandler.centroid.position.x.toFixed(2) + ', ' + dragHandler.centroid.position.y.toFixed(2) + ')' + + '\nmodifiers: ' + dragHandler.centroid.modifiers.toString(16) } } } @@ -79,8 +79,8 @@ Rectangle { color: "transparent" border.color: "white" antialiasing: true - width: dragHandler.point.ellipseDiameters.width - height: dragHandler.point.ellipseDiameters.height + width: dragHandler.centroid.ellipseDiameters.width + height: dragHandler.centroid.ellipseDiameters.height radius: Math.min(width / 2, height / 2) anchors.centerIn: parent } @@ -88,11 +88,11 @@ Rectangle { Rectangle { id: velocityVector visible: width > 0 - width: dragHandler.point.velocity.length() * 100 + width: dragHandler.centroid.velocity.length() * 100 height: 2 - x: dragHandler.point.position.x - y: dragHandler.point.position.y - rotation: Math.atan2(dragHandler.point.velocity.y, dragHandler.point.velocity.x) * 180 / Math.PI + x: dragHandler.centroid.position.x + y: dragHandler.centroid.position.y + rotation: Math.atan2(dragHandler.centroid.velocity.y, dragHandler.centroid.velocity.x) * 180 / Math.PI transformOrigin: Item.BottomLeft antialiasing: true @@ -138,15 +138,14 @@ Rectangle { DragHandler { id: dragHandler target: null - acceptedButtons: Qt.AllButtons - onGrabChanged: if (active) { // 'point' is an implicit parameter referencing to a QQuickEventPoint instance - console.log("grabbed " + point.pointId + " @ " + point.sceneGrabPos) - grabbingLocationIndicator.createObject(root, {"x": point.sceneGrabPosition.x, "y": point.sceneGrabPosition.y - 16}) +// acceptedButtons: Qt.AllButtons // TODO: only SinglePointHandler has this so far + onGrabChanged: if (active) { + console.log("grabbed " + centroid.pointId + " @ " + centroid.sceneGrabPos) + grabbingLocationIndicator.createObject(root, {"x": centroid.sceneGrabPosition.x, "y": centroid.sceneGrabPosition.y - 16}) } - onPointChanged: { - // Here, 'point' is referring to the property of the DragHandler - if (point.pressedButtons) - mouseButtonIndicator.createObject(root, {"x": point.pressPosition.x - 44, "y": point.pressPosition.y - 64, "buttons": point.pressedButtons}) + onCentroidChanged: { + if (centroid.pressedButtons) + mouseButtonIndicator.createObject(root, {"x": centroid.pressPosition.x - 44, "y": centroid.pressPosition.y - 64, "buttons": centroid.pressedButtons}) } } } -- cgit v1.2.3