aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/pointerhandlers
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-01-02 21:00:33 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2019-01-28 12:54:05 +0000
commit63bbaf837976bae45fdd2766da0ed4cc808cc0ac (patch)
tree8cab3b95e6c479d2c4969f72c8b2a628210843e9 /tests/auto/quick/pointerhandlers
parent84b47be6c79761e274454d437b73a1ac2c6789c9 (diff)
PinchHandler: Avoid unwanted translations when axes are disabled
Fixes: QTBUG-72822 Change-Id: I2773ba14fcb24a47fe2ec04860b4aa305a051453 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/pointerhandlers')
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml10
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp80
2 files changed, 89 insertions, 1 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml b/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml
index 15775df1e7..3cabde5f59 100644
--- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml
+++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml
@@ -33,7 +33,7 @@ Rectangle {
property real scale: -1.0
property int activeCount : 0
property int deactiveCount : 0
- width: 240; height: 320
+ width: 320; height: 320
color: "white"
Rectangle {
id: blackRect
@@ -45,6 +45,14 @@ Rectangle {
height: 100
opacity: (whiteRect.width-blackRect.x+whiteRect.height-blackRect.y-199)/200
Text { color: "white"; text: "opacity: " + blackRect.opacity + "\nscale: " + blackRect.scale}
+ Rectangle {
+ color: "red"
+ width: 6; height: 6; radius: 3
+ visible: pincharea.active
+ x: pincharea.centroid.position.x - radius
+ y: pincharea.centroid.position.y - radius
+ }
+
PinchHandler {
id: pincharea
objectName: "pinchHandler"
diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
index 818863bf86..19fdae3b44 100644
--- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
@@ -37,6 +37,8 @@
#include "../../../shared/util.h"
#include "../../shared/viewtestutil.h"
+Q_LOGGING_CATEGORY(lcPointerTests, "qt.quick.pointer.tests")
+
class tst_QQuickPinchHandler: public QQmlDataTest
{
Q_OBJECT
@@ -49,6 +51,8 @@ private slots:
void scale();
void scaleThreeFingers();
void pan();
+ void dragAxesEnabled_data();
+ void dragAxesEnabled();
void retouch();
void cancel();
void transformedpinchHandler_data();
@@ -459,6 +463,82 @@ void tst_QQuickPinchHandler::pan()
QVERIFY(!root->property("pinchActive").toBool());
}
+void tst_QQuickPinchHandler::dragAxesEnabled_data()
+{
+ QTest::addColumn<bool>("xEnabled");
+ QTest::addColumn<bool>("yEnabled");
+
+ QTest::newRow("both enabled") << true << true;
+ QTest::newRow("x enabled") << true << false;
+ QTest::newRow("y enabled") << false << true;
+ QTest::newRow("both disabled") << false << false;
+}
+
+void tst_QQuickPinchHandler::dragAxesEnabled()
+{
+ QQuickView *window = createView();
+ QScopedPointer<QQuickView> scope(window);
+ window->setSource(testFileUrl("pinchproperties.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+ QVERIFY(window->rootObject() != nullptr);
+ QQuickItem *blackRect = window->rootObject()->findChild<QQuickItem*>("blackrect");
+ QVERIFY(blackRect != nullptr);
+ QQuickPinchHandler *pinchHandler = blackRect->findChild<QQuickPinchHandler*>();
+ QVERIFY(pinchHandler != nullptr);
+
+ QFETCH(bool, xEnabled);
+ QFETCH(bool, yEnabled);
+ const int dragThreshold = QGuiApplication::styleHints()->startDragDistance();
+ pinchHandler->xAxis()->setEnabled(xEnabled);
+ pinchHandler->yAxis()->setEnabled(yEnabled);
+ QPoint c = blackRect->mapToScene(blackRect->clipRect().center()).toPoint();
+ QPoint p0 = c - QPoint(0, dragThreshold);
+ QPoint p1 = c + QPoint(0, dragThreshold);
+ QPoint blackRectPos = blackRect->position().toPoint();
+
+ // press two points, one above the rectangle's center and one below
+ QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, device);
+ pinchSequence.press(0, p0, window).press(1, p1, window).commit();
+ QQuickTouchUtils::flush(window);
+
+ // expand the pinch vertically
+ p0 -= QPoint(0, dragThreshold);
+ p1 += QPoint(0, dragThreshold);
+ pinchSequence.move(0, p0, window).move(1, p1, window).commit();
+ for (int pi = 0; pi < 4; ++pi) {
+ p0 -= QPoint(0, dragThreshold);
+ p1 += QPoint(0, dragThreshold);
+ pinchSequence.move(0, p0, window).move(1, p1, window).commit();
+ QQuickTouchUtils::flush(window);
+ qCDebug(lcPointerTests) << pi << "active" << pinchHandler->active() << "pts" << p0 << p1
+ << "centroid" << pinchHandler->centroid().scenePosition()
+ << "rect pos" << blackRect->position() << "scale" << blackRect->scale();
+ }
+ QCOMPARE(pinchHandler->active(), true);
+ QVERIFY(blackRect->scale() >= 2.0);
+ // drag started, but we only did scaling without any translation
+ QCOMPARE(pinchHandler->centroid().scenePosition().toPoint(), c);
+ QCOMPARE(blackRect->position().toPoint().x(), blackRectPos.x());
+ QCOMPARE(blackRect->position().toPoint().y(), blackRectPos.y());
+
+ // drag diagonally
+ p0 += QPoint(150, 150);
+ p1 += QPoint(150, 150);
+ pinchSequence.move(0, p0, window).move(1, p1, window).commit();
+ QQuickTouchUtils::flush(window);
+ // the target should move if the xAxis is enabled, or stay in place if not
+ qCDebug(lcPointerTests) << "after diagonal drag: pts" << p0 << p1
+ << "centroid" << pinchHandler->centroid().scenePosition()
+ << "rect pos" << blackRect->position() << "scale" << blackRect->scale();
+ QCOMPARE(pinchHandler->centroid().scenePosition().toPoint(), QPoint(250, 250));
+ QCOMPARE(blackRect->position().toPoint().x(), xEnabled ? 140 : blackRectPos.x()); // because of xAxis.maximum
+ QCOMPARE(blackRect->position().toPoint().y(), yEnabled ? 170 : blackRectPos.y()); // because of yAxis.maximum
+
+ QTest::touchEvent(window, device).release(0, p0, window).release(1, p1, window);
+ QQuickTouchUtils::flush(window);
+}
+
// test pinchHandler, release one point, touch again to continue pinchHandler
void tst_QQuickPinchHandler::retouch()
{