on xenial help sign in
Added test for rotated DirectionalDragAreas
commitd90aba3904148b2e43f6f9db73bc91e714455dee authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateTue 11 Feb 2014, 18:21 (13 years ago) parenta738853
6 files changed+103−9
tests/plugins/Ubuntu/Gestures/DownwardsLauncher.qml+8−1 tests/plugins/Ubuntu/Gestures/LeftwardsLauncher.qml+7 tests/plugins/Ubuntu/Gestures/RightwardsLauncher.qml+7 tests/plugins/Ubuntu/Gestures/UpwardsLauncher.qml+7 tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+44 tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.qml+30−8
tests/plugins/Ubuntu/Gestures/DownwardsLauncher.qml+8−1
@@ -63,7 +63,7 @@ Item {
6363 dragAreaRect.opacity = 0.3
6464 launcher.y = Qt.binding(launcher.followDragArea)
6565 break;
66− defaut: // DirectionalDragArea.Recognized:
66+ default: // DirectionalDragArea.Recognized:
6767 dragAreaRect.color = "green"
6868 dragAreaRect.opacity = 0.5
6969 break;
@@ -76,4 +76,11 @@ Item {
7676 top: parent.top
7777 }
7878 }
79+
80+ Label {
81+ text: "Downwards"
82+ anchors.top: parent.top
83+ anchors.horizontalCenter: parent.horizontalCenter
84+ anchors.topMargin: units.gu(1)
85+ }
7986}
tests/plugins/Ubuntu/Gestures/LeftwardsLauncher.qml+7
@@ -79,4 +79,11 @@ Item {
7979 bottom: parent.bottom
8080 }
8181 }
82+
83+ Label {
84+ text: "Leftwards"
85+ anchors.right: parent.right
86+ anchors.verticalCenter: parent.verticalCenter
87+ anchors.rightMargin: units.gu(1)
88+ }
8289}
tests/plugins/Ubuntu/Gestures/RightwardsLauncher.qml+7
@@ -77,4 +77,11 @@ Item {
7777 bottom: parent.bottom
7878 }
7979 }
80+
81+ Label {
82+ text: "Rightwards"
83+ anchors.left: parent.left
84+ anchors.verticalCenter: parent.verticalCenter
85+ anchors.leftMargin: units.gu(1)
86+ }
8087}
tests/plugins/Ubuntu/Gestures/UpwardsLauncher.qml+7
@@ -79,4 +79,11 @@ Item {
7979 bottom: parent.bottom
8080 }
8181 }
82+
83+ Label {
84+ text: "Upwards"
85+ anchors.bottom: parent.bottom
86+ anchors.horizontalCenter: parent.horizontalCenter
87+ anchors.bottomMargin: units.gu(1)
88+ }
8289}
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+44
@@ -83,6 +83,7 @@ private Q_SLOTS:
8383 void twoFingerTap();
8484 void movingDDA();
8585 void ignoreOldFinger();
86+ void rotated();
8687
8788private:
8889 void passTime(qint64 timeSpan);
@@ -696,6 +697,49 @@ void tst_DirectionalDragArea::ignoreOldFinger()
696697 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
697698}
698699
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+
699743QTEST_MAIN(tst_DirectionalDragArea)
700744
701745#include "tst_DirectionalDragArea.moc"
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.qml+30−8
@@ -18,8 +18,8 @@ import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919
2020Rectangle {
21− width: units.gu(40)
22− height: units.gu(71)
21+ width: units.gu(60)
22+ height: units.gu(60)
2323 color: "white"
2424
2525 MouseArea {
@@ -33,14 +33,36 @@ Rectangle {
3333 }
3434 }
3535
36− // NB: Do not anchor it as we will move it programmatically from the test
37− RightwardsLauncher {
38− id: hpLauncher;
36+ Item {
37+ id: baseItem
38+ objectName: "baseItem"
3939 width: parent.width
4040 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 }
4152 }
4253
43− LeftwardsLauncher { id: hnLauncher; anchors.fill: parent }
44− DownwardsLauncher { id: vpLauncher; anchors.fill: parent }
45− UpwardsLauncher { id: vnLauncher; anchors.fill: parent }
54+ Button {
55+ anchors.bottom: parent.bottom
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+ }
4668}