@@ -84,6 +84,8 @@ private Q_SLOTS:
84 void movingDDA();
84 void movingDDA();
85 void ignoreOldFinger();
85 void ignoreOldFinger();
86 void rotated();
86 void rotated();
87+ void sceneDistance();
88+ void sceneDistance_data();
89 void passTime(qint64 timeSpan);
91 void passTime(qint64 timeSpan);
@@ -740,6 +742,59 @@ void tst_DirectionalDragArea::rotated()
740 QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
742 QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
745+void tst_DirectionalDragArea::sceneDistance()
747+ QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
748+ QFETCH(qreal, rotation);
749+ QFETCH(QPointF, dragDirectionVector);
750+ baseItem->setRotation(rotation);
752+ QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
753+ Q_ASSERT(rightwardsLauncher != 0);
755+ DirectionalDragArea *edgeDragArea =
756+ rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
757+ Q_ASSERT(edgeDragArea != 0);
758+ edgeDragArea->setRecognitionTimer(fakeTimer);
759+ edgeDragArea->setTimeSource(fakeTimeSource);
761+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
762+ QPointF touchPoint = initialTouchPos;
764+ qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
766+ qreal movementStepDistance = edgeDragArea->distanceThreshold() * 0.1f;
767+ QPointF touchMovement = dragDirectionVector * movementStepDistance;
768+ int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
769+ int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
771+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
773+ for (int i = 0; i < totalMovementSteps; ++i) {
774+ touchPoint += touchMovement;
775+ passTime(movementTimeStepMs);
776+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
779+ qreal actualDragDistance = ((qreal)totalMovementSteps) * movementStepDistance;
781+ // DirectionalDragArea::sceneDistance() must match the actual drag distance as the
782+ // drag was aligned with the gesture direction
783+ // NB: qFuzzyCompare(), used internally by QCOMPARE(), is broken.
784+ QVERIFY(qAbs(edgeDragArea->sceneDistance() - actualDragDistance) < 0.001);
786+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
789+void tst_DirectionalDragArea::sceneDistance_data()
791+ QTest::addColumn<qreal>("rotation");
792+ QTest::addColumn<QPointF>("dragDirectionVector");
794+ QTest::newRow("not rotated") << 0. << QPointF(1., 0.);
795+ QTest::newRow("rotated by 90 degrees") << 90. << QPointF(0., 1.);
743QTEST_MAIN(tst_DirectionalDragArea)
798QTEST_MAIN(tst_DirectionalDragArea)
745#include "tst_DirectionalDragArea.moc"
800#include "tst_DirectionalDragArea.moc"