@@ -83,6 +83,10 @@ private Q_SLOTS:
8383 void twoFingerTap();
8484 void movingDDA();
8585 void ignoreOldFinger();
86+ void rotated();
87+ void sceneDistance();
88+ void sceneDistance_data();
89+ void disabledWhileDragging();
8690
8791private:
8892 void passTime(qint64 timeSpan);
@@ -99,6 +103,14 @@ void tst_DirectionalDragArea::init()
99103{
100104 GestureTest::init();
101105
106+ // We shouldn't need the three lines below, but a compiz/unity7
107+ // regression means we don't pass the test without them because
108+ // the window doesn't have the proper size. Can be removed in the
109+ // future if the regression is fixed and tests pass again
110+ m_view->resize(m_view->rootObject()->width(), m_view->rootObject()->height());
111+ QTRY_COMPARE(m_view->width(), (int)m_view->rootObject()->width());
112+ QTRY_COMPARE(m_view->height(), (int)m_view->rootObject()->height());
113+
102114 fakeTimeSource.reset(new FakeTimeSource);
103115 fakeTimer = new FakeTimer(fakeTimeSource);
104116}
@@ -131,18 +143,10 @@ void tst_DirectionalDragArea::passTime(qint64 timeSpan)
131143}
132144
133145namespace {
134−QPointF calculateInitialTouchPos(DirectionalDragArea *edgeDragArea, QQuickView *view)
146+QPointF calculateInitialTouchPos(DirectionalDragArea *edgeDragArea)
135147{
136− switch (edgeDragArea->direction()) {
137− case Direction::Upwards:
138− return QPointF(view->width()/2.0f, view->height() - (edgeDragArea->height()/2.0f));
139− case Direction::Downwards:
140− return QPointF(view->width()/2.0f, edgeDragArea->height()/2.0f);
141− case Direction::Leftwards:
142− return QPointF(view->width() - (edgeDragArea->width()/2.0f), view->height()/2.0f);
143− default: // Direction::Rightwards:
144− return QPointF(edgeDragArea->width()/2.0f, view->height()/2.0f);
145− }
148+ QPointF localCenter(edgeDragArea->width() / 2., edgeDragArea->height() / 2.);
149+ return edgeDragArea->mapToScene(localCenter);
146150}
147151
148152QPointF calculateDirectionVector(DirectionalDragArea *edgeDragArea,
@@ -193,7 +197,7 @@ void tst_DirectionalDragArea::edgeDrag()
193197
194198 QSignalSpy draggingSpy(edgeDragArea, SIGNAL(draggingChanged(bool)));
195199
196− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
200+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
197201 QPointF touchPoint = initialTouchPos;
198202
199203 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*dragDistanceFactor;
@@ -300,7 +304,7 @@ void tst_DirectionalDragArea::dragWithShortDirectionChange()
300304 edgeDragArea->setRecognitionTimer(fakeTimer);
301305 edgeDragArea->setTimeSource(fakeTimeSource);
302306
303− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
307+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
304308 QPointF touchPoint = initialTouchPos;
305309
306310 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0;
@@ -360,7 +364,7 @@ void tst_DirectionalDragArea::minSpeed()
360364
361365 edgeDragArea->setMinSpeed(minSpeed);
362366
363− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
367+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
364368 QPointF touchPoint = initialTouchPos;
365369
366370 QPointF dragDirectionVector(1.0, 0.0);
@@ -408,7 +412,7 @@ void tst_DirectionalDragArea::recognitionTimerUsage()
408412
409413 int timeStepMs = 5; // some arbitrary small value.
410414
411− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
415+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
412416 QPointF touchPoint = initialTouchPos;
413417
414418 QPointF dragDirectionVector(1.0, 0.0);
@@ -452,7 +456,7 @@ void tst_DirectionalDragArea::maxSilenceTime()
452456 // Make sure this property is not disabled
453457 edgeDragArea->setMaxSilenceTime(100);
454458
455− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
459+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
456460 QPointF touchPoint = initialTouchPos;
457461
458462 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
@@ -620,7 +624,7 @@ void tst_DirectionalDragArea::movingDDA()
620624 edgeDragArea->setRecognitionTimer(fakeTimer);
621625 edgeDragArea->setTimeSource(fakeTimeSource);
622626
623− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
627+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
624628 QPointF touchPoint = initialTouchPos;
625629
626630 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
@@ -704,6 +708,147 @@ void tst_DirectionalDragArea::ignoreOldFinger()
704708 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
705709}
706710
711+/*
712+ A Rightwards DDA that is rotated 90 degrees clockwise should recognize gestures
713+ that are done downwards in scene coordinates. I.e. the gesture recognition direction
714+ should be in local coordinates, not scene coordinates.
715+ */
716+void tst_DirectionalDragArea::rotated()
717+{
718+ QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
719+ baseItem->setRotation(90.);
720+
721+ QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
722+ Q_ASSERT(rightwardsLauncher != 0);
723+
724+ DirectionalDragArea *edgeDragArea =
725+ rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
726+ Q_ASSERT(edgeDragArea != 0);
727+ edgeDragArea->setRecognitionTimer(fakeTimer);
728+ edgeDragArea->setTimeSource(fakeTimeSource);
729+
730+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
731+ QPointF touchPoint = initialTouchPos;
732+
733+ qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
734+ QPointF dragDirectionVector(0.0f, 1.0f);
735+
736+ qreal movementStepDistance = edgeDragArea->distanceThreshold() * 0.1f;
737+ QPointF touchMovement = dragDirectionVector * movementStepDistance;
738+ int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
739+ int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
740+
741+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
742+
743+ for (int i = 0; i < totalMovementSteps; ++i) {
744+ touchPoint += touchMovement;
745+ passTime(movementTimeStepMs);
746+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
747+ }
748+
749+ QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
750+
751+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
752+}
753+
754+void tst_DirectionalDragArea::sceneDistance()
755+{
756+ QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
757+ QFETCH(qreal, rotation);
758+ QFETCH(QPointF, dragDirectionVector);
759+ baseItem->setRotation(rotation);
760+
761+ QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
762+ Q_ASSERT(rightwardsLauncher != 0);
763+
764+ DirectionalDragArea *edgeDragArea =
765+ rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
766+ Q_ASSERT(edgeDragArea != 0);
767+ edgeDragArea->setRecognitionTimer(fakeTimer);
768+ edgeDragArea->setTimeSource(fakeTimeSource);
769+
770+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
771+ QPointF touchPoint = initialTouchPos;
772+
773+ qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
774+
775+ qreal movementStepDistance = edgeDragArea->distanceThreshold() * 0.1f;
776+ QPointF touchMovement = dragDirectionVector * movementStepDistance;
777+ int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
778+ int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
779+
780+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
781+
782+ for (int i = 0; i < totalMovementSteps; ++i) {
783+ touchPoint += touchMovement;
784+ passTime(movementTimeStepMs);
785+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
786+ }
787+
788+ qreal actualDragDistance = ((qreal)totalMovementSteps) * movementStepDistance;
789+
790+ // DirectionalDragArea::sceneDistance() must match the actual drag distance as the
791+ // drag was aligned with the gesture direction
792+ // NB: qFuzzyCompare(), used internally by QCOMPARE(), is broken.
793+ QVERIFY(qAbs(edgeDragArea->sceneDistance() - actualDragDistance) < 0.001);
794+
795+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
796+}
797+
798+void tst_DirectionalDragArea::sceneDistance_data()
799+{
800+ QTest::addColumn<qreal>("rotation");
801+ QTest::addColumn<QPointF>("dragDirectionVector");
802+
803+ QTest::newRow("not rotated") << 0. << QPointF(1., 0.);
804+ QTest::newRow("rotated by 90 degrees") << 90. << QPointF(0., 1.);
805+}
806+
807+/*
808+ Regression test for https://bugs.launchpad.net/unity8/+bug/1276122
809+
810+ The bug:
811+ If setting "enabled: false" while the DirectionalDragArea's (DDA) dragging
812+ property is true, the DDA stays in that state and doesn't recover any more.
813+*/
814+void tst_DirectionalDragArea::disabledWhileDragging()
815+{
816+ DirectionalDragArea *edgeDragArea =
817+ m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
818+ Q_ASSERT(edgeDragArea != 0);
819+ edgeDragArea->setRecognitionTimer(fakeTimer);
820+ edgeDragArea->setTimeSource(fakeTimeSource);
821+
822+ QPointF touchPoint = calculateInitialTouchPos(edgeDragArea);
823+
824+ qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
825+ QPointF dragDirectionVector(1., 0.); // horizontal positive
826+
827+ qreal movementStepDistance = edgeDragArea->distanceThreshold() * 0.1f;
828+ QPointF touchMovement = dragDirectionVector * movementStepDistance;
829+ int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
830+ int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
831+
832+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
833+
834+ for (int i = 0; i < totalMovementSteps; ++i) {
835+ touchPoint += touchMovement;
836+ passTime(movementTimeStepMs);
837+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
838+ }
839+
840+ QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
841+ QCOMPARE(edgeDragArea->dragging(), true);
842+
843+ // disable the dragArea while it's being dragged.
844+ edgeDragArea->setEnabled(false);
845+
846+ QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
847+ QCOMPARE(edgeDragArea->dragging(), false);
848+
849+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
850+}
851+
707852QTEST_MAIN(tst_DirectionalDragArea)
708853
709854#include "tst_DirectionalDragArea.moc"