aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-11-16 18:20:19 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2022-12-10 03:13:57 +0100
commit7867a683fcb938939fb2837a26ac8e1941e3fe08 (patch)
tree271faa101a68abdd55c5c88146ee8bc223a413a8 /tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
parentf064497bd5021e5d28266cabbb703d548f6961b0 (diff)
Add PinchHandler.scaleAxis, rotationAxis; hold values in axes
Pointer Handlers that manipulate target item properties should now use QQuickDragAxis consistently to: - enforce minimum and maximum values - hold the persistent and active values - make those available via properties - emit a new activeValueChanged(delta) signal when the value changes, so that it's possible to incrementally update a target item property in JS (onValueDelta: target.property += delta) In the pinchHandler.qml example, you can use the PinchHandler to adjust 4 properties of one Rectangle independently (it requires coordination). m_boundedActiveValue controls whether m_activeValue will be kept between minimum and maximum. For rotation, tst_QQuickPinchHandler::scaleNativeGesture() expects it to be, although that seems questionable now, and may be addressed later. [ChangeLog][QtQuick][Event Handlers] PinchHandler now has scaleAxis and rotationAxis grouped properties, alongside the existing xAxis and yAxis; and all of these now have activeValue and persistentValue properties. The activeValueChanged signal includes a delta value, giving the incremental change since the previous activeValue. The persistentValue is settable, in case some target item property can be adjusted in multiple ways: the handler's stored value can then be synced up with the item property value after each external change. These features are also added to DragHandler's xAxis and yAxis properties. Task-number: QTBUG-68108 Task-number: QTBUG-76380 Task-number: QTBUG-76379 Task-number: QTBUG-94168 Change-Id: I78a5b43e9ba580448ef05054b6c4bc71b1834dd6 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp')
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp141
1 files changed, 96 insertions, 45 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
index 3aba9f2581..28484b33a8 100644
--- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
@@ -79,96 +79,119 @@ void tst_QQuickPinchHandler::pinchProperties()
pinchHandler->setTarget(rootItem);
QCOMPARE(targetSpy.size(),1);
- // axis
- /*
- QCOMPARE(pinchHandler->axis(), QQuickPinch::XAndYAxis);
- QSignalSpy axisSpy(pinchHandler, SIGNAL(dragAxisChanged()));
- pinchHandler->setAxis(QQuickPinch::XAxis);
- QCOMPARE(pinchHandler->axis(), QQuickPinch::XAxis);
- QCOMPARE(axisSpy.count(),1);
- pinchHandler->setAxis(QQuickPinch::XAxis);
- QCOMPARE(axisSpy.count(),1);
+ // drag axes
+ QCOMPARE(pinchHandler->xAxis()->enabled(), true);
+ QCOMPARE(pinchHandler->yAxis()->enabled(), true);
+ QSignalSpy xEnabledSpy(pinchHandler->xAxis(), &QQuickDragAxis::enabledChanged);
+ QSignalSpy yEnabledSpy(pinchHandler->yAxis(), &QQuickDragAxis::enabledChanged);
+ QSignalSpy scaleEnabledSpy(pinchHandler->scaleAxis(), &QQuickDragAxis::enabledChanged);
+ QSignalSpy rotationEnabledSpy(pinchHandler->rotationAxis(), &QQuickDragAxis::enabledChanged);
+ pinchHandler->xAxis()->setEnabled(false);
+ QCOMPARE(xEnabledSpy.count(), 1);
+ pinchHandler->yAxis()->setEnabled(false);
+ QCOMPARE(yEnabledSpy.count(), 1);
+ pinchHandler->scaleAxis()->setEnabled(false);
+ QCOMPARE(scaleEnabledSpy.count(), 1);
+ pinchHandler->rotationAxis()->setEnabled(false);
+ QCOMPARE(rotationEnabledSpy.count(), 1);
// minimum and maximum drag properties
- QSignalSpy xminSpy(pinchHandler, SIGNAL(minimumXChanged()));
- QSignalSpy xmaxSpy(pinchHandler, SIGNAL(maximumXChanged()));
- QSignalSpy yminSpy(pinchHandler, SIGNAL(minimumYChanged()));
- QSignalSpy ymaxSpy(pinchHandler, SIGNAL(maximumYChanged()));
-
- QCOMPARE(pinchHandler->xmin(), 0.0);
- QCOMPARE(pinchHandler->xmax(), rootItem->width()-blackRect->width());
- QCOMPARE(pinchHandler->ymin(), 0.0);
- QCOMPARE(pinchHandler->ymax(), rootItem->height()-blackRect->height());
-
- pinchHandler->setXmin(10);
- pinchHandler->setXmax(10);
- pinchHandler->setYmin(10);
- pinchHandler->setYmax(10);
-
- QCOMPARE(pinchHandler->xmin(), 10.0);
- QCOMPARE(pinchHandler->xmax(), 10.0);
- QCOMPARE(pinchHandler->ymin(), 10.0);
- QCOMPARE(pinchHandler->ymax(), 10.0);
+ QSignalSpy xminSpy(pinchHandler->xAxis(), &QQuickDragAxis::minimumChanged);
+ QSignalSpy xmaxSpy(pinchHandler->xAxis(), &QQuickDragAxis::maximumChanged);
+ QSignalSpy yminSpy(pinchHandler->yAxis(), &QQuickDragAxis::minimumChanged);
+ QSignalSpy ymaxSpy(pinchHandler->yAxis(), &QQuickDragAxis::maximumChanged);
+
+ QCOMPARE(pinchHandler->xAxis()->minimum(), std::numeric_limits<qreal>::lowest());
+ QCOMPARE(pinchHandler->xAxis()->maximum(), 140);
+ QCOMPARE(pinchHandler->yAxis()->minimum(), std::numeric_limits<qreal>::lowest());
+ QCOMPARE(pinchHandler->yAxis()->maximum(), 170);
+
+ pinchHandler->xAxis()->setMinimum(10);
+ pinchHandler->xAxis()->setMaximum(10);
+ pinchHandler->yAxis()->setMinimum(10);
+ pinchHandler->yAxis()->setMaximum(10);
+
+ QCOMPARE(pinchHandler->xAxis()->minimum(), 10);
+ QCOMPARE(pinchHandler->xAxis()->maximum(), 10);
+ QCOMPARE(pinchHandler->yAxis()->minimum(), 10);
+ QCOMPARE(pinchHandler->yAxis()->maximum(), 10);
QCOMPARE(xminSpy.count(),1);
QCOMPARE(xmaxSpy.count(),1);
QCOMPARE(yminSpy.count(),1);
QCOMPARE(ymaxSpy.count(),1);
- pinchHandler->setXmin(10);
- pinchHandler->setXmax(10);
- pinchHandler->setYmin(10);
- pinchHandler->setYmax(10);
+ pinchHandler->xAxis()->setMinimum(10);
+ pinchHandler->xAxis()->setMaximum(10);
+ pinchHandler->yAxis()->setMinimum(10);
+ pinchHandler->yAxis()->setMaximum(10);
QCOMPARE(xminSpy.count(),1);
QCOMPARE(xmaxSpy.count(),1);
QCOMPARE(yminSpy.count(),1);
QCOMPARE(ymaxSpy.count(),1);
- */
// minimum and maximum scale properties
QSignalSpy scaleMinSpy(pinchHandler, SIGNAL(minimumScaleChanged()));
QSignalSpy scaleMaxSpy(pinchHandler, SIGNAL(maximumScaleChanged()));
+ QSignalSpy scaleAxisMinSpy(pinchHandler->scaleAxis(), &QQuickDragAxis::minimumChanged);
+ QSignalSpy scaleAxisMaxSpy(pinchHandler->scaleAxis(), &QQuickDragAxis::maximumChanged);
QCOMPARE(pinchHandler->minimumScale(), 0.5);
- QCOMPARE(pinchHandler->maximumScale(), 4.0);
+ QCOMPARE(pinchHandler->scaleAxis()->minimum(), 0.5);
+ QCOMPARE(pinchHandler->maximumScale(), 4);
+ QCOMPARE(pinchHandler->scaleAxis()->maximum(), 4);
pinchHandler->setMinimumScale(0.25);
pinchHandler->setMaximumScale(1.5);
QCOMPARE(pinchHandler->minimumScale(), 0.25);
+ QCOMPARE(pinchHandler->scaleAxis()->minimum(), 0.25);
QCOMPARE(pinchHandler->maximumScale(), 1.5);
+ QCOMPARE(pinchHandler->scaleAxis()->maximum(), 1.5);
QCOMPARE(scaleMinSpy.size(),1);
QCOMPARE(scaleMaxSpy.size(),1);
+ QCOMPARE(scaleAxisMinSpy.size(),1);
+ QCOMPARE(scaleAxisMaxSpy.size(),1);
pinchHandler->setMinimumScale(0.25);
pinchHandler->setMaximumScale(1.5);
QCOMPARE(scaleMinSpy.size(),1);
QCOMPARE(scaleMaxSpy.size(),1);
+ QCOMPARE(scaleAxisMinSpy.size(),1);
+ QCOMPARE(scaleAxisMaxSpy.size(),1);
// minimum and maximum rotation properties
QSignalSpy rotMinSpy(pinchHandler, SIGNAL(minimumRotationChanged()));
QSignalSpy rotMaxSpy(pinchHandler, SIGNAL(maximumRotationChanged()));
+ QSignalSpy rotAxisMinSpy(pinchHandler->rotationAxis(), &QQuickDragAxis::minimumChanged);
+ QSignalSpy rotAxisMaxSpy(pinchHandler->rotationAxis(), &QQuickDragAxis::maximumChanged);
- QCOMPARE(pinchHandler->minimumRotation(), 0.0);
- QCOMPARE(pinchHandler->maximumRotation(), 90.0);
+ QCOMPARE(pinchHandler->minimumRotation(), 0);
+ QCOMPARE(pinchHandler->rotationAxis()->minimum(), 0);
+ QCOMPARE(pinchHandler->maximumRotation(), 90);
+ QCOMPARE(pinchHandler->rotationAxis()->maximum(), 90);
- pinchHandler->setMinimumRotation(-90.0);
- pinchHandler->setMaximumRotation(45.0);
+ pinchHandler->setMinimumRotation(-90);
+ pinchHandler->setMaximumRotation(45);
- QCOMPARE(pinchHandler->minimumRotation(), -90.0);
- QCOMPARE(pinchHandler->maximumRotation(), 45.0);
+ QCOMPARE(pinchHandler->minimumRotation(), -90);
+ QCOMPARE(pinchHandler->maximumRotation(), 45);
QCOMPARE(rotMinSpy.size(),1);
QCOMPARE(rotMaxSpy.size(),1);
+ QCOMPARE(rotAxisMinSpy.size(),1);
+ QCOMPARE(rotAxisMaxSpy.size(),1);
- pinchHandler->setMinimumRotation(-90.0);
- pinchHandler->setMaximumRotation(45.0);
+ pinchHandler->setMinimumRotation(-90);
+ pinchHandler->setMaximumRotation(45);
QCOMPARE(rotMinSpy.size(),1);
QCOMPARE(rotMaxSpy.size(),1);
+ QCOMPARE(rotAxisMinSpy.size(),1);
+ QCOMPARE(rotAxisMaxSpy.size(),1);
}
QEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i)
@@ -202,6 +225,7 @@ void tst_QQuickPinchHandler::scale()
QQuickItem *blackRect = (hasTarget ? pinchHandler->target() : pinchHandler->parentItem());
QVERIFY(blackRect != nullptr);
QSignalSpy grabChangedSpy(pinchHandler, SIGNAL(grabChanged(QPointingDevice::GrabTransition, QEventPoint)));
+ if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
QPoint p0(80, 80);
QPoint p1(100, 100);
@@ -215,6 +239,7 @@ void tst_QQuickPinchHandler::scale()
// it is outside its bounds.
pinchSequence.stationary(0).press(1, p1, &window).commit();
QQuickTouchUtils::flush(&window);
+ if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
QCOMPARE(grabChangedSpy.size(), 1); // passive grab
QPoint pd(10, 10);
@@ -224,6 +249,7 @@ void tst_QQuickPinchHandler::scale()
pinchSequence.stationary(0).move(1, p1, &window).commit();
QQuickTouchUtils::flush(&window);
}
+ if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
QCOMPARE(pinchHandler->active(), true);
// grabs occur when the handler becomes active; at that time, QQuickHandlerPoint.sceneGrabPosition should be correct
QVERIFY(pinchHandler->firstPoint().sceneGrabPosition() != QPointF());
@@ -243,10 +269,14 @@ void tst_QQuickPinchHandler::scale()
if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
line.setP2(p1);
qreal expectedScale = line.length() / startLength;
+ qCDebug(lcPointerTests) << "pinchScale" << root->property("pinchScale").toReal()
+ << "expected" << expectedScale << "; target scale" << blackRect->scale();
QVERIFY(qFloatDistance(root->property("pinchScale").toReal(), expectedScale) < 10);
QVERIFY(qFloatDistance(blackRect->scale(), expectedScale) < 10);
QCOMPARE(pinchHandler->scale(), root->property("pinchScale").toReal());
QCOMPARE(pinchHandler->scale(), pinchHandler->activeScale()); // in sync for the first gesture
+ QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), pinchHandler->activeScale());
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), pinchHandler->activeScale());
QPointF expectedCentroid = p0 + (p1 - p0) / 2;
QCOMPARE(pinchHandler->centroid().scenePosition(), expectedCentroid);
}
@@ -257,6 +287,8 @@ void tst_QQuickPinchHandler::scale()
if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
// scale property is persistent after release
QCOMPARE(pinchHandler->scale(), lastScale);
+ QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), lastScale);
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 1);
// pinch a second time: scale picks up where we left off
p0 = QPoint(80, 80);
@@ -271,6 +303,8 @@ void tst_QQuickPinchHandler::scale()
if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
QCOMPARE(pinchHandler->active(), true);
QCOMPARE(pinchHandler->scale(), lastScale); // just activated, not scaling further yet
+ QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), lastScale);
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 1);
for (int i = 0; i < 2; ++i) {
lastScale = pinchHandler->scale();
p1 += pd;
@@ -280,9 +314,13 @@ void tst_QQuickPinchHandler::scale()
QCOMPARE_GT(pinchHandler->scale(), lastScale);
line.setP2(p1);
qreal expectedActiveScale = line.length() / startLength;
+ qCDebug(lcPointerTests) << i << "activeScale" << pinchHandler->activeScale()
+ << "expected" << expectedActiveScale << "; scale" << pinchHandler->scale();
QVERIFY(qFloatDistance(pinchHandler->activeScale(), expectedActiveScale) < 10);
QCOMPARE(pinchHandler->scale(), root->property("pinchScale").toReal());
+ QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), root->property("pinchScale").toReal());
QCOMPARE_NE(pinchHandler->scale(), pinchHandler->activeScale()); // not in sync anymore
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), pinchHandler->activeScale());
}
// scale beyond maximumScale
@@ -292,6 +330,7 @@ void tst_QQuickPinchHandler::scale()
if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
QCOMPARE(blackRect->scale(), qreal(4));
QCOMPARE(pinchHandler->scale(), qreal(4)); // limited by maximumScale
+ QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), 4);
pinchSequence.release(0, p0, &window).release(1, p1, &window).commit();
QQuickTouchUtils::flush(&window);
QCOMPARE(pinchHandler->active(), false);
@@ -347,8 +386,10 @@ void tst_QQuickPinchHandler::scaleThreeFingers()
qCDebug(lcPointerTests) << "pinch scale" << pinchHandler->scale() << "expected 1.173";
QVERIFY(withinBounds(1.163, pinchHandler->scale(), 1.183));
// should not rotate
- QCOMPARE(root->rotation(), 0.);
- QCOMPARE(pinchHandler->rotation(), 0.);
+ QCOMPARE(root->rotation(), 0);
+ QCOMPARE(pinchHandler->rotation(), 0);
+ QCOMPARE(pinchHandler->rotationAxis()->activeValue(), 0);
+ QCOMPARE(pinchHandler->rotationAxis()->persistentValue(), 0);
for (int i = 0; i < 5;++i) {
p0 += QPoint(-4, -4);
@@ -370,7 +411,9 @@ void tst_QQuickPinchHandler::scaleThreeFingers()
pinchSequence.move(0, p0,window).move(1, p1,window).move(2, p2,window).commit();
QQuickTouchUtils::flush(window);
- QCOMPARE(pinchHandler->scale(), 2.);
+ QCOMPARE(pinchHandler->scale(), 2);
+ QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), 2);
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 2);
pinchSequence.release(0, p0, window).release(1, p1, window).release(2, p2, window).commit();
QQuickTouchUtils::flush(window);
}
@@ -431,16 +474,22 @@ void tst_QQuickPinchHandler::scaleNativeGesture()
QVERIFY(qAbs(target->position().y() - expectedPos.y()) < 0.001);
QCOMPARE(pinchHandler->scale(), expectedScale);
QCOMPARE(pinchHandler->activeScale(), expectedScale);
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), expectedScale);
QCOMPARE(pinchHandler->translation(), QVector2D());
QCOMPARE(pinchHandler->rotation(), 0);
+ QCOMPARE(pinchHandler->rotationAxis()->persistentValue(), 0);
+ QCOMPARE(pinchHandler->rotationAxis()->activeValue(), 0);
QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad,
Qt::EndNativeGesture, pinchPos, pinchPos);
QTRY_COMPARE(pinchHandler->active(), false);
QCOMPARE(target->scale(), expectedScale);
QCOMPARE(pinchHandler->scale(), expectedScale);
QCOMPARE(pinchHandler->activeScale(), 1);
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 1);
QCOMPARE(pinchHandler->translation(), QVector2D());
QCOMPARE(pinchHandler->rotation(), 0);
+ QCOMPARE(pinchHandler->rotationAxis()->persistentValue(), 0);
+ QCOMPARE(pinchHandler->rotationAxis()->activeValue(), 0);
// second pinch at a different position: scale it back to original size again
// but remove the limits first, so that we can scale arbitrarily
@@ -459,12 +508,14 @@ void tst_QQuickPinchHandler::scaleNativeGesture()
QCOMPARE(pinchHandler->centroid().scenePosition().toPoint(), pinchPos.toPoint());
QCOMPARE(pinchHandler->scale(), 1);
QCOMPARE(pinchHandler->activeScale(), reverseScale);
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), reverseScale);
QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad,
Qt::EndNativeGesture, pinchPos, pinchPos);
QTRY_COMPARE(pinchHandler->active(), false);
QCOMPARE(target->scale(), 1);
QCOMPARE(pinchHandler->scale(), 1);
QCOMPARE(pinchHandler->activeScale(), 1);
+ QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 1);
}
void tst_QQuickPinchHandler::pan()