diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-05-03 20:33:56 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-05-04 23:40:45 +0200 |
commit | 7642205be45135add120373299df02e05f4ffc58 (patch) | |
tree | 17cb510bb44bedb0df221fef246c7657e6916903 /tests | |
parent | 051dd3178bc4c9214af60c69cecfc2c28f13174d (diff) |
Make PinchArea translate correctly inside a rotated parent
Pick-to: 5.15 6.1
Fixes: QTBUG-63673
Change-Id: I91231bb8555b7eb02a9580f9f184b261d8bd44c8
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickpincharea/data/draggablePinchArea.qml | 70 | ||||
-rw-r--r-- | tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp | 63 |
2 files changed, 133 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickpincharea/data/draggablePinchArea.qml b/tests/auto/quick/qquickpincharea/data/draggablePinchArea.qml new file mode 100644 index 0000000000..3acf67b4b6 --- /dev/null +++ b/tests/auto/quick/qquickpincharea/data/draggablePinchArea.qml @@ -0,0 +1,70 @@ +import QtQuick 2.12 + +Rectangle { + id: root + width: 600 + height: 600 + + Rectangle { + objectName: "paContainer" + width: parent.width -100 + height: parent.height - 100 + border.color: "black" + anchors.centerIn: parent + transformOrigin: Item.Center + + Rectangle { + width: 300 + height: 300 + color: "tomato" + PinchArea { + id: pa + anchors.fill: parent + pinch.target: parent + pinch.minimumScale: 0.5 + pinch.maximumScale: 2 + pinch.minimumRotation: -360 + pinch.maximumRotation: 360 + pinch.dragAxis: Pinch.XAndYAxis + pinch.minimumX: -100 + pinch.maximumX: 300 + pinch.minimumY: -100 + pinch.maximumY: 300 + } + + + Text { text: "this way up" } + } + } + + // only for touch feedback / troubleshooting + Item { + id: glassPane + z: 10000 + anchors.fill: parent + + PointHandler { + id: ph1 + target: Rectangle { + parent: glassPane + color: "green" + visible: ph1.active + x: ph1.point.position.x - width / 2 + y: ph1.point.position.y - height / 2 + width: 20; height: width; radius: width / 2 + } + } + + PointHandler { + id: ph2 + target: Rectangle { + parent: glassPane + color: "blue" + visible: ph2.active + x: ph2.point.position.x - width / 2 + y: ph2.point.position.y - height / 2 + width: 20; height: width; radius: width / 2 + } + } + } +} diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp index a9f35e8727..7375804893 100644 --- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp +++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp @@ -52,6 +52,8 @@ private slots: void cancel(); void transformedPinchArea_data(); void transformedPinchArea(); + void dragTransformedPinchArea_data(); + void dragTransformedPinchArea(); private: QQuickView *createView(); @@ -576,6 +578,67 @@ void tst_QQuickPinchArea::transformedPinchArea() } } +void tst_QQuickPinchArea::dragTransformedPinchArea_data() +{ + QTest::addColumn<int>("rotation"); + QTest::addColumn<QPoint>("p1"); + QTest::addColumn<QPoint>("p2"); + QTest::addColumn<QPoint>("delta"); + + QTest::newRow("unrotated") + << 0 << QPoint(100, 100) << QPoint(200, 100) << QPoint(40, 40); + QTest::newRow("20 deg") + << 20 << QPoint(100, 100) << QPoint(200, 100) << QPoint(40, 40); + QTest::newRow("90 deg") + << 90 << QPoint(100, 100) << QPoint(200, 100) << QPoint(0, 40); + QTest::newRow("180 deg") + << 180 << QPoint(100, 100) << QPoint(200, 100) << QPoint(40, 0); + QTest::newRow("225 deg") + << 210 << QPoint(200, 200) << QPoint(300, 200) << QPoint(80, 80); +} + +void tst_QQuickPinchArea::dragTransformedPinchArea() // QTBUG-63673 +{ + QFETCH(int, rotation); + QFETCH(QPoint, p1); + QFETCH(QPoint, p2); + QFETCH(QPoint, delta); + const int threshold = qApp->styleHints()->startDragDistance(); + + QQuickView *view = createView(); + QScopedPointer<QQuickView> scope(view); + view->setSource(testFileUrl("draggablePinchArea.qml")); + view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view)); + QVERIFY(view->rootObject()); + QQuickPinchArea *pinchArea = view->rootObject()->findChild<QQuickPinchArea*>(); + QVERIFY(pinchArea); + QQuickItem *pinchAreaTarget = pinchArea->parentItem(); + QVERIFY(pinchAreaTarget); + QQuickItem *pinchAreaContainer = pinchAreaTarget->parentItem(); + QVERIFY(pinchAreaContainer); + pinchAreaContainer->setRotation(rotation); + + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(view, device); + // start pinch + pinchSequence.press(1, pinchArea->mapToScene(p1).toPoint(), view) + .press(2, pinchArea->mapToScene(p2).toPoint(), view).commit(); + QQuickTouchUtils::flush(view); + pinchSequence.move(1, pinchArea->mapToScene(p1 + QPoint(threshold, threshold)).toPoint(), view) + .move(2, pinchArea->mapToScene(p2 + QPoint(threshold, threshold)).toPoint(), view).commit(); + QQuickTouchUtils::flush(view); + pinchSequence.move(1, pinchArea->mapToScene(p1 + delta).toPoint(), view) + .move(2, pinchArea->mapToScene(p2 + delta).toPoint(), view).commit(); + QQuickTouchUtils::flush(view); + QCOMPARE(pinchArea->pinch()->active(), true); + QCOMPARE(pinchAreaTarget->position().toPoint(), delta - QPoint(threshold, threshold)); + + // release pinch + pinchSequence.release(1, p1, view).release(2, p2, view).commit(); + QQuickTouchUtils::flush(view); + QCOMPARE(pinchArea->pinch()->active(), false); +} + QQuickView *tst_QQuickPinchArea::createView() { QQuickView *window = new QQuickView(nullptr); |