on xenial help sign in
Added test for rotated DirectionalDragAreas
d90aba3Daniel d'Andrada
tests/plugins/Ubuntu/Gestures/DownwardsLauncher.qml+8−1
@@ -63,7 +63,7 @@ Item {
63 dragAreaRect.opacity = 0.3
63 dragAreaRect.opacity = 0.3
64 launcher.y = Qt.binding(launcher.followDragArea)
64 launcher.y = Qt.binding(launcher.followDragArea)
65 break;
65 break;
66− defaut: // DirectionalDragArea.Recognized:
66+ default: // DirectionalDragArea.Recognized:
67 dragAreaRect.color = "green"
67 dragAreaRect.color = "green"
68 dragAreaRect.opacity = 0.5
68 dragAreaRect.opacity = 0.5
69 break;
69 break;
@@ -76,4 +76,11 @@ Item {
76 top: parent.top
76 top: parent.top
77 }
77 }
78 }
78 }
79+
80+ Label {
81+ text: "Downwards"
82+ anchors.top: parent.top
83+ anchors.horizontalCenter: parent.horizontalCenter
84+ anchors.topMargin: units.gu(1)
85+ }
79}
86}
tests/plugins/Ubuntu/Gestures/LeftwardsLauncher.qml+7
@@ -79,4 +79,11 @@ Item {
79 bottom: parent.bottom
79 bottom: parent.bottom
80 }
80 }
81 }
81 }
82+
83+ Label {
84+ text: "Leftwards"
85+ anchors.right: parent.right
86+ anchors.verticalCenter: parent.verticalCenter
87+ anchors.rightMargin: units.gu(1)
88+ }
82}
89}
tests/plugins/Ubuntu/Gestures/RightwardsLauncher.qml+7
@@ -77,4 +77,11 @@ Item {
77 bottom: parent.bottom
77 bottom: parent.bottom
78 }
78 }
79 }
79 }
80+
81+ Label {
82+ text: "Rightwards"
83+ anchors.left: parent.left
84+ anchors.verticalCenter: parent.verticalCenter
85+ anchors.leftMargin: units.gu(1)
86+ }
80}
87}
tests/plugins/Ubuntu/Gestures/UpwardsLauncher.qml+7
@@ -79,4 +79,11 @@ Item {
79 bottom: parent.bottom
79 bottom: parent.bottom
80 }
80 }
81 }
81 }
82+
83+ Label {
84+ text: "Upwards"
85+ anchors.bottom: parent.bottom
86+ anchors.horizontalCenter: parent.horizontalCenter
87+ anchors.bottomMargin: units.gu(1)
88+ }
82}
89}
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+44
@@ -83,6 +83,7 @@ private Q_SLOTS:
83 void twoFingerTap();
83 void twoFingerTap();
84 void movingDDA();
84 void movingDDA();
85 void ignoreOldFinger();
85 void ignoreOldFinger();
86+ void rotated();
86
87
87private:
88private:
88 void passTime(qint64 timeSpan);
89 void passTime(qint64 timeSpan);
@@ -696,6 +697,49 @@ void tst_DirectionalDragArea::ignoreOldFinger()
696 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
697 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
697}
698}
698
699
700+/*
701+ A Rightwards DDA that is rotated 90 degrees clockwise should recognize gestures
702+ that are done downwards in scene coordinates. I.e. the gesture recognition direction
703+ should be in local coordinates, not scene coordinates.
704+ */
705+void tst_DirectionalDragArea::rotated()
706+{
707+ QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
708+ baseItem->setRotation(90.);
709+
710+ QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
711+ Q_ASSERT(rightwardsLauncher != 0);
712+
713+ DirectionalDragArea *edgeDragArea =
714+ rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
715+ Q_ASSERT(edgeDragArea != 0);
716+ edgeDragArea->setRecognitionTimer(fakeTimer);
717+ edgeDragArea->setTimeSource(fakeTimeSource);
718+
719+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
720+ QPointF touchPoint = initialTouchPos;
721+
722+ qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
723+ QPointF dragDirectionVector(0.0f, 1.0f);
724+
725+ qreal movementStepDistance = edgeDragArea->distanceThreshold() * 0.1f;
726+ QPointF touchMovement = dragDirectionVector * movementStepDistance;
727+ int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
728+ int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
729+
730+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
731+
732+ for (int i = 0; i < totalMovementSteps; ++i) {
733+ touchPoint += touchMovement;
734+ passTime(movementTimeStepMs);
735+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
736+ }
737+
738+ QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
739+
740+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
741+}
742+
699QTEST_MAIN(tst_DirectionalDragArea)
743QTEST_MAIN(tst_DirectionalDragArea)
700
744
701#include "tst_DirectionalDragArea.moc"
745#include "tst_DirectionalDragArea.moc"
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.qml+30−8
@@ -18,8 +18,8 @@ import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19
19
20Rectangle {
20Rectangle {
21− width: units.gu(40)
21+ width: units.gu(60)
22− height: units.gu(71)
22+ height: units.gu(60)
23 color: "white"
23 color: "white"
24
24
25 MouseArea {
25 MouseArea {
@@ -33,14 +33,36 @@ Rectangle {
33 }
33 }
34 }
34 }
35
35
36− // NB: Do not anchor it as we will move it programmatically from the test
36+ Item {
37− RightwardsLauncher {
37+ id: baseItem
38− id: hpLauncher;
38+ objectName: "baseItem"
39 width: parent.width
39 width: parent.width
40 height: parent.height
40 height: parent.height
41+
42+ // NB: Do not anchor it as we will move it programmatically from the test
43+ RightwardsLauncher {
44+ id: hpLauncher;
45+ width: parent.width
46+ height: parent.height
47+ }
48+
49+ LeftwardsLauncher { id: hnLauncher; anchors.fill: parent }
50+ DownwardsLauncher { id: vpLauncher; anchors.fill: parent }
51+ UpwardsLauncher { id: vnLauncher; anchors.fill: parent }
41 }
52 }
42
53
43− LeftwardsLauncher { id: hnLauncher; anchors.fill: parent }
54+ Button {
44− DownwardsLauncher { id: vpLauncher; anchors.fill: parent }
55+ anchors.bottom: parent.bottom
45− UpwardsLauncher { id: vnLauncher; anchors.fill: parent }
56+ anchors.left: parent.left
57+ anchors.margins: units.gu(1)
58+
59+ text: "rotation: " + baseItem.rotation
60+ onClicked: {
61+ if (baseItem.rotation === 0.0) {
62+ baseItem.rotation = 90.0
63+ } else {
64+ baseItem.rotation = 0.0
65+ }
66+ }
67+ }
46}
68}