on xenial help sign in
merge in lp:~unity-team/unity8/rotate-n7 which is not to productized
commitb3e6180ffb83d0a11dee8e65ded87a97830e1e5f authorKevin Gunn <kevin.gunn@canonical.com> dateThu 13 Feb 2014, 21:10 (13 years ago) parentf9fed9f710a8de
17 files changed+423−153
debian/unity8.install+1 plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+104−44 plugins/Ubuntu/Gestures/DirectionalDragArea.h+11−1 qml/Components/ApplicationManagerWrapper.qml+8 qml/Components/ApplicationScreenshot.qml+11−7 qml/Components/DragHandle.qml+2−1 qml/Panel/MenuContent.qml+1 qml/Shell.qml+23 tests/qmltests/Components/tst_DragHandle/TestButton.qml → qml/ShellOrientator.qml+13−17 src/main.cpp+11−1 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+108−17 tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.qml+30−8 tests/qmltests/Components/tst_DragHandle.qml+71−56
debian/unity8.install+1
@@ -10,6 +10,7 @@ usr/share/unity8/Launcher
1010usr/share/unity8/Notifications
1111usr/share/unity8/Panel
1212usr/share/unity8/Shell.qml
13+usr/share/unity8/ShellOrientator.qml
1314usr/share/unity8/SideStage
1415usr/share/unity8/graphics
1516data/unity8.conf usr/share/upstart/sessions/
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+104−44
@@ -114,6 +114,7 @@ DirectionalDragArea::DirectionalDragArea(QQuickItem *parent)
114114 , m_wideningAngle(0)
115115 , m_wideningFactor(0)
116116 , m_distanceThreshold(0)
117+ , m_distanceThresholdSquared(0.)
117118 , m_minSpeed(0)
118119 , m_maxSilenceTime(200)
119120 , m_silenceTime(0)
@@ -162,7 +163,14 @@ void DirectionalDragArea::setWideningAngle(qreal angle)
162163 return;
163164
164165 m_wideningAngle = angle;
165− m_wideningFactor = qTan(angle * M_PI / 180.0);
166+
167+ // wideningFactor = pow(cosine(angle), 2)
168+ {
169+ qreal angleRadians = angle * M_PI / 180.0;
170+ m_wideningFactor = qCos(angleRadians);
171+ m_wideningFactor = m_wideningFactor * m_wideningFactor;
172+ }
173+
166174 Q_EMIT wideningAngleChanged(angle);
167175}
168176
@@ -170,6 +178,7 @@ void DirectionalDragArea::setDistanceThreshold(qreal value)
170178{
171179 if (m_distanceThreshold != value) {
172180 m_distanceThreshold = value;
181+ m_distanceThresholdSquared = m_distanceThreshold * m_distanceThreshold;
173182 Q_EMIT distanceThresholdChanged(value);
174183 }
175184}
@@ -237,13 +246,15 @@ qreal DirectionalDragArea::distance() const
237246 }
238247}
239248
249+void DirectionalDragArea::updateSceneDistance()
250+{
251+ QPointF totalMovement = m_previousScenePos - m_startScenePos;
252+ m_sceneDistance = projectOntoDirectionVector(totalMovement);
253+}
254+
240255qreal DirectionalDragArea::sceneDistance() const
241256{
242− if (Direction::isHorizontal(m_direction)) {
243− return m_previousScenePos.x() - m_startScenePos.x();
244− } else {
245− return m_previousScenePos.y() - m_startScenePos.y();
246− }
257+ return m_sceneDistance;
247258}
248259
249260qreal DirectionalDragArea::touchX() const
@@ -335,12 +346,13 @@ void DirectionalDragArea::touchEvent_absent(QTouchEvent *event)
335346 m_startScenePos = newTouchPoint->scenePos();
336347 m_touchId = newTouchPoint->id();
337348 m_dampedScenePos.reset(m_startScenePos);
338− updateVelocityCalculator(m_startScenePos);
349+ m_velocityCalculator->setTrackedPosition(0.);
339350 m_velocityCalculator->reset();
340351 m_numSamplesOnLastSpeedCheck = 0;
341352 m_silenceTime = 0;
342353 setPreviousPos(m_startPos);
343354 setPreviousScenePos(m_startScenePos);
355+ updateSceneDirectionVector();
344356
345357 setStatus(Undecided);
346358}
@@ -441,44 +453,53 @@ const QTouchEvent::TouchPoint *DirectionalDragArea::fetchTargetTouchPoint(QTouch
441453
442454bool DirectionalDragArea::pointInsideAllowedArea() const
443455{
444− qreal dX = m_dampedScenePos.x() - m_startScenePos.x();
445− qreal dY = m_dampedScenePos.y() - m_startScenePos.y();
456+ // NB: Using squared values to avoid computing the square root to find
457+ // the length totalMovement
446458
447− switch (m_direction) {
448− case Direction::Upwards:
449− return dY <= 0 && qFabs(dX) <= qFabs(dY) * m_wideningFactor;
450− case Direction::Downwards:
451− return dY >= 0 && qFabs(dX) <= dY * m_wideningFactor;
452− case Direction::Leftwards:
453− return dX <= 0 && qFabs(dY) <= qFabs(dX) * m_wideningFactor;
454− default: // Direction::Rightwards:
455− return dX >= 0 && qFabs(dY) <= dX * m_wideningFactor;
459+ QPointF totalMovement(m_dampedScenePos.x() - m_startScenePos.x(),
460+ m_dampedScenePos.y() - m_startScenePos.y());
461+
462+ qreal squaredTotalMovSize = totalMovement.x() * totalMovement.x() +
463+ totalMovement.y() * totalMovement.y();
464+
465+ if (squaredTotalMovSize == 0.) {
466+ // didn't move
467+ return true;
456468 }
469+
470+ qreal projectedMovement = projectOntoDirectionVector(totalMovement);
471+
472+
473+ qreal cosineAngleSquared = (projectedMovement * projectedMovement) / squaredTotalMovSize;
474+
475+ // Same as:
476+ // angle_between_movement_vector_and_gesture_direction_vector <= widening_angle
477+ return cosineAngleSquared >= m_wideningFactor;
457478}
458479
459480bool DirectionalDragArea::movingInRightDirection() const
460481{
461− switch (m_direction) {
462− case Direction::Upwards:
463− return m_dampedScenePos.y() <= m_previousDampedScenePos.y();
464− case Direction::Downwards:
465− return m_dampedScenePos.y() >= m_previousDampedScenePos.y();
466− case Direction::Leftwards:
467− return m_dampedScenePos.x() <= m_previousDampedScenePos.x();
468− default: // Direction::Rightwards:
469− return m_dampedScenePos.x() >= m_previousDampedScenePos.x();
470− }
482+ QPointF movementVector(m_dampedScenePos.x() - m_previousDampedScenePos.x(),
483+ m_dampedScenePos.y() - m_previousDampedScenePos.y());
484+
485+ qreal scalarProjection = projectOntoDirectionVector(movementVector);
486+
487+ return scalarProjection >= 0.;
471488}
472489
473490bool DirectionalDragArea::movedFarEnough(const QPointF &point) const
474491{
475− if (m_distanceThreshold > 0) {
476− if (Direction::isHorizontal(m_direction))
477− return qFabs(point.x() - m_startScenePos.x()) > m_distanceThreshold;
478− else
479− return qFabs(point.y() - m_startScenePos.y()) > m_distanceThreshold;
480− } else {
492+ if (m_distanceThreshold <= 0.) {
493+ // distance threshold check is disabled
481494 return true;
495+ } else {
496+ QPointF totalMovement(point.x() - m_startScenePos.x(),
497+ point.y() - m_startScenePos.y());
498+
499+ qreal squaredTotalMovSize = totalMovement.x() * totalMovement.x() +
500+ totalMovement.y() * totalMovement.y();
501+
502+ return squaredTotalMovSize > m_distanceThresholdSquared;
482503 }
483504}
484505
@@ -568,28 +589,33 @@ void DirectionalDragArea::setPreviousScenePos(const QPointF &point)
568589 bool xChanged = m_previousScenePos.x() != point.x();
569590 bool yChanged = m_previousScenePos.y() != point.y();
570591
592+ if (!xChanged && !yChanged)
593+ return;
594+
595+ qreal oldSceneDistance = sceneDistance();
571596 m_previousScenePos = point;
597+ updateSceneDistance();
598+
599+ if (oldSceneDistance != sceneDistance()) {
600+ Q_EMIT sceneDistanceChanged(sceneDistance());
601+ }
572602
573603 if (xChanged) {
574604 Q_EMIT touchSceneXChanged(point.x());
575− if (Direction::isHorizontal(m_direction))
576− Q_EMIT sceneDistanceChanged(sceneDistance());
577605 }
578606
579607 if (yChanged) {
580608 Q_EMIT touchSceneYChanged(point.y());
581− if (Direction::isVertical(m_direction))
582− Q_EMIT sceneDistanceChanged(sceneDistance());
583609 }
584610}
585611
586−void DirectionalDragArea::updateVelocityCalculator(const QPointF &point)
612+void DirectionalDragArea::updateVelocityCalculator(const QPointF &scenePos)
587613{
588− if (Direction::isHorizontal(m_direction)) {
589− m_velocityCalculator->setTrackedPosition(point.x());
590− } else {
591− m_velocityCalculator->setTrackedPosition(point.y());
592− }
614+ QPointF totalSceneMovement = scenePos - m_startScenePos;
615+
616+ qreal scalarProjection = projectOntoDirectionVector(totalSceneMovement);
617+
618+ m_velocityCalculator->setTrackedPosition(scalarProjection);
593619}
594620
595621bool DirectionalDragArea::isWithinTouchCompositionWindow()
@@ -693,5 +719,39 @@ qint64 DirectionalDragArea::ActiveTouchesInfo::mostRecentStartTime()
693719 return highestStartTime;
694720}
695721
722+void DirectionalDragArea::updateSceneDirectionVector()
723+{
724+ QPointF localOrigin(0., 0.);
725+ QPointF localDirection;
726+ switch (m_direction) {
727+ case Direction::Upwards:
728+ localDirection.rx() = 0.;
729+ localDirection.ry() = -1.;
730+ break;
731+ case Direction::Downwards:
732+ localDirection.rx() = 0.;
733+ localDirection.ry() = 1;
734+ break;
735+ case Direction::Leftwards:
736+ localDirection.rx() = -1.;
737+ localDirection.ry() = 0.;
738+ break;
739+ default: // Direction::Rightwards:
740+ localDirection.rx() = 1.;
741+ localDirection.ry() = 0.;
742+ break;
743+ }
744+ QPointF sceneOrigin = mapToScene(localOrigin);
745+ QPointF sceneDirection = mapToScene(localDirection);
746+ m_sceneDirectionVector = sceneDirection - sceneOrigin;
747+}
748+
749+qreal DirectionalDragArea::projectOntoDirectionVector(const QPointF &sceneVector) const
750+{
751+ // same as dot product as m_sceneDirectionVector is a unit vector
752+ return sceneVector.x() * m_sceneDirectionVector.x() +
753+ sceneVector.y() * m_sceneDirectionVector.y();
754+}
755+
696756// Because we are defining a new QObject-based class (RecognitionTimer) here.
697757#include "DirectionalDragArea.moc"
plugins/Ubuntu/Gestures/DirectionalDragArea.h+11−1
@@ -160,6 +160,7 @@ public:
160160
161161 qreal distance() const;
162162 qreal sceneDistance() const;
163+ void updateSceneDistance();
163164
164165 qreal touchX() const;
165166 qreal touchY() const;
@@ -231,6 +232,10 @@ private:
231232 void setPreviousScenePos(const QPointF &point);
232233 void updateVelocityCalculator(const QPointF &point);
233234 bool isWithinTouchCompositionWindow();
235+ void updateSceneDirectionVector();
236+ // returns the scalar projection between the given vector (in scene coordinates)
237+ // and m_sceneDirectionVector
238+ qreal projectOntoDirectionVector(const QPointF &sceneVector) const;
234239
235240 Status m_status;
236241
@@ -238,6 +243,7 @@ private:
238243 QPointF m_startScenePos;
239244 QPointF m_previousPos;
240245 QPointF m_previousScenePos;
246+ qreal m_sceneDistance;
241247 int m_touchId;
242248
243249 // A movement damper is used in some of the gesture recognition calculations
@@ -245,10 +251,14 @@ private:
245251 DampedPointF m_dampedScenePos;
246252 QPointF m_previousDampedScenePos;
247253
254+ // Unit vector in scene coordinates describing the direction of the gesture recognition
255+ QPointF m_sceneDirectionVector;
256+
248257 Direction::Type m_direction;
249258 qreal m_wideningAngle; // in degrees
250− qreal m_wideningFactor; // it's tan(degreesToRadian(m_wideningAngle))
259+ qreal m_wideningFactor; // it's pow(cosine(m_wideningAngle), 2)
251260 qreal m_distanceThreshold;
261+ qreal m_distanceThresholdSquared; // it's pow(m_distanceThreshold, 2)
252262 qreal m_minSpeed;
253263 int m_maxSilenceTime; // in milliseconds
254264 int m_silenceTime; // in milliseconds
qml/Components/ApplicationManagerWrapper.qml+8
@@ -166,4 +166,12 @@ Item {
166166 }
167167 return desktopFile.substring(left+1, right);
168168 }
169+
170+ function setMainStageAppRect(item) {
171+ ApplicationManager.setMainStageAppRect(item);
172+ }
173+
174+ function setSideStageAppRect(item) {
175+ ApplicationManager.setSideStageAppRect(item);
176+ }
169177}
qml/Components/ApplicationScreenshot.qml+11−7
@@ -15,6 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18+import QtQuick.Window 2.0
1819import Ubuntu.Components 0.1
1920import Unity.Application 0.1
2021
@@ -50,12 +51,15 @@ Item {
5051 visible: applicationScreenshot.withBackground
5152 }
5253
53− ApplicationImage {
54− id: applicationImage
55− objectName: "screenshot image"
56− width: applicationScreenshot.application ? parent.width : 0
57− height: applicationScreenshot.application ? parent.height : 0
58− visible: applicationScreenshot.application != null && ready
59− source: ApplicationManager.findApplication((application) ? application.appId : "")
54+ OrientationHelper {
55+ orientationAngle: Screen.angleBetween(Screen.primaryOrientation, nativeOrientation) // compensate for Shell rotation
56+ transitionEnabled: false
57+ ApplicationImage {
58+ id: applicationImage
59+ objectName: "screenshot image"
60+ anchors.fill: parent
61+ visible: applicationScreenshot.application != null && ready
62+ source: ApplicationManager.findApplication((application) ? application.appId : "")
63+ }
6064 }
6165}
qml/Components/DragHandle.qml+2−1
@@ -167,7 +167,8 @@ EdgeDragArea {
167167 EdgeDragEvaluator {
168168 objectName: "edgeDragEvaluator"
169169 id: dragEvaluator
170− trackedPosition: sceneDistance
170+ // Effectively convert distance into the drag position projected onto the gesture direction axis
171+ trackedPosition: Direction.isPositive(dragArea.direction) ? sceneDistance : -sceneDistance
171172 maxDragDistance: maxTotalDragDistance
172173 direction: dragArea.direction
173174 }
qml/Panel/MenuContent.qml+1
@@ -26,6 +26,7 @@ import "../Components"
2626MainView {
2727 id: content
2828
29+ nativeOrientationAngle: 0 // stop contents being re-rotated when shell in landscape
2930 property QtObject indicatorsModel: null
3031 property bool __contentActive: false
3132 readonly property int currentMenuIndex: tabs.selectedTabIndex
qml/Shell.qml+23
@@ -77,6 +77,9 @@ FocusScope {
7777 // FIXME: if application focused before shell starts, shell draws on top of it only.
7878 // We should detect already running applications on shell start and bring them to the front.
7979 applicationManager.unfocusCurrentApplication();
80+
81+ applicationManager.setMainStageAppRect(mainStageAppRect);
82+ applicationManager.setSideStageAppRect(sideStageAppRect);
8083 }
8184
8285 readonly property bool applicationFocused: !!applicationManager.mainStageFocusedApplication
@@ -348,6 +351,26 @@ FocusScope {
348351 orientation: Qt.Horizontal
349352 }
350353
354+ // Defines the rectangle occupied by an application on the main or side stage.
355+ // Used only to inform the ApplicationManager. Can be removed when the proper
356+ // architecture is in place (unity8 as mir compositor).
357+ Item {
358+ id: mainStageAppRect
359+ x: mainStage.x
360+ y: mainStage.y + mainStage.normalApplicationY
361+ width: mainStage.width
362+ height: mainStage.height
363+ visible: false; enabled: false
364+ }
365+ Item {
366+ id: sideStageAppRect
367+ x: sideStageRevealer.openedValue
368+ y: sideStage.y + sideStage.normalApplicationY
369+ width: sideStage.width
370+ height: sideStage.height
371+ visible: false; enabled: false
372+ }
373+
351374 DragHandle {
352375 id: stagesDragHandle
353376
tests/qmltests/Components/tst_DragHandle/TestButton.qml → qml/ShellOrientator.qmlrenamed+13−17
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -15,27 +15,23 @@
1515 */
1616
1717import QtQuick 2.0
18+import QtQuick.Window 2.0
1819import Ubuntu.Components 0.1
20+import Ubuntu.Gestures 0.1
1921
20−Rectangle {
21− id: rect
22− width: childrenRect.width
23− height: childrenRect.height
22+Item {
23+ id: orientator
2424
25− property alias text: textComponent.text
25+ // this is only here to select the width / height of the window if not running fullscreen
26+ property bool tablet: false
27+ width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
28+ height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
2629
27− signal clicked
28−
29− color: "yellow"
30− Text {
31− id: textComponent
32− font.pixelSize: units.gu(2)
33− text: root.stretch ? "stretch" : "move"
34− MouseArea {
30+ OrientationHelper {
31+ orientationAngle: Screen.angleBetween(nativeOrientation, Screen.primaryOrientation)
32+ transitionEnabled: false
33+ Shell {
3534 anchors.fill: parent
36− onClicked: {
37− rect.clicked()
38− }
3935 }
4036 }
4137}
src/main.cpp+11−1
@@ -92,6 +92,16 @@ int startShell(int argc, const char** argv, void* server)
9292 view->setFlags(Qt::FramelessWindowHint);
9393 }
9494
95+ const QByteArray orientation = qgetenv("NATIVE_ORIENTATION");
96+ Qt::ScreenOrientation orientationAngle = Qt::PortraitOrientation;
97+ if (orientation == "landscape") {
98+ orientationAngle = Qt::LandscapeOrientation;
99+ } else if (!orientation.isEmpty() && orientation != "portrait") {
100+ qDebug() << "Unknown NATIVE_ORIENTATION setting, ignoring";
101+ }
102+
103+ view->rootContext()->setContextProperty("nativeOrientation", orientationAngle);
104+
95105 // You will need this if you want to interact with touch-only components using a mouse
96106 // Needed only when manually testing on a desktop.
97107 MouseTouchAdaptor *mouseTouchAdaptor = 0;
@@ -109,7 +119,7 @@ int startShell(int argc, const char** argv, void* server)
109119 nativeInterface->setProperty("ubuntuSessionType", 1);
110120 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
111121
112− QUrl source(::qmlDirectory()+"Shell.qml");
122+ QUrl source(::qmlDirectory()+"ShellOrientator.qml");
113123 prependImportPaths(view->engine(), ::overrideImportPaths());
114124 appendImportPaths(view->engine(), ::fallbackImportPaths());
115125
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+108−17
@@ -83,6 +83,9 @@ private Q_SLOTS:
8383 void twoFingerTap();
8484 void movingDDA();
8585 void ignoreOldFinger();
86+ void rotated();
87+ void sceneDistance();
88+ void sceneDistance_data();
8689
8790private:
8891 void passTime(qint64 timeSpan);
@@ -131,18 +134,10 @@ void tst_DirectionalDragArea::passTime(qint64 timeSpan)
131134}
132135
133136namespace {
134−QPointF calculateInitialTouchPos(DirectionalDragArea *edgeDragArea, QQuickView *view)
137+QPointF calculateInitialTouchPos(DirectionalDragArea *edgeDragArea)
135138{
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− }
139+ QPointF localCenter(edgeDragArea->width() / 2., edgeDragArea->height() / 2.);
140+ return edgeDragArea->mapToScene(localCenter);
146141}
147142
148143QPointF calculateDirectionVector(DirectionalDragArea *edgeDragArea,
@@ -193,7 +188,7 @@ void tst_DirectionalDragArea::edgeDrag()
193188
194189 QSignalSpy draggingSpy(edgeDragArea, SIGNAL(draggingChanged(bool)));
195190
196− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
191+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
197192 QPointF touchPoint = initialTouchPos;
198193
199194 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*dragDistanceFactor;
@@ -300,7 +295,7 @@ void tst_DirectionalDragArea::dragWithShortDirectionChange()
300295 edgeDragArea->setRecognitionTimer(fakeTimer);
301296 edgeDragArea->setTimeSource(fakeTimeSource);
302297
303− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
298+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
304299 QPointF touchPoint = initialTouchPos;
305300
306301 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0;
@@ -360,7 +355,7 @@ void tst_DirectionalDragArea::minSpeed()
360355
361356 edgeDragArea->setMinSpeed(minSpeed);
362357
363− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
358+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
364359 QPointF touchPoint = initialTouchPos;
365360
366361 QPointF dragDirectionVector(1.0, 0.0);
@@ -408,7 +403,7 @@ void tst_DirectionalDragArea::recognitionTimerUsage()
408403
409404 int timeStepMs = 5; // some arbitrary small value.
410405
411− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
406+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
412407 QPointF touchPoint = initialTouchPos;
413408
414409 QPointF dragDirectionVector(1.0, 0.0);
@@ -452,7 +447,7 @@ void tst_DirectionalDragArea::maxSilenceTime()
452447 // Make sure this property is not disabled
453448 edgeDragArea->setMaxSilenceTime(100);
454449
455− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
450+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
456451 QPointF touchPoint = initialTouchPos;
457452
458453 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
@@ -620,7 +615,7 @@ void tst_DirectionalDragArea::movingDDA()
620615 edgeDragArea->setRecognitionTimer(fakeTimer);
621616 edgeDragArea->setTimeSource(fakeTimeSource);
622617
623− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
618+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
624619 QPointF touchPoint = initialTouchPos;
625620
626621 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
@@ -704,6 +699,102 @@ void tst_DirectionalDragArea::ignoreOldFinger()
704699 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
705700}
706701
702+/*
703+ A Rightwards DDA that is rotated 90 degrees clockwise should recognize gestures
704+ that are done downwards in scene coordinates. I.e. the gesture recognition direction
705+ should be in local coordinates, not scene coordinates.
706+ */
707+void tst_DirectionalDragArea::rotated()
708+{
709+ QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
710+ baseItem->setRotation(90.);
711+
712+ QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
713+ Q_ASSERT(rightwardsLauncher != 0);
714+
715+ DirectionalDragArea *edgeDragArea =
716+ rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
717+ Q_ASSERT(edgeDragArea != 0);
718+ edgeDragArea->setRecognitionTimer(fakeTimer);
719+ edgeDragArea->setTimeSource(fakeTimeSource);
720+
721+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
722+ QPointF touchPoint = initialTouchPos;
723+
724+ qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
725+ QPointF dragDirectionVector(0.0f, 1.0f);
726+
727+ qreal movementStepDistance = edgeDragArea->distanceThreshold() * 0.1f;
728+ QPointF touchMovement = dragDirectionVector * movementStepDistance;
729+ int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
730+ int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
731+
732+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
733+
734+ for (int i = 0; i < totalMovementSteps; ++i) {
735+ touchPoint += touchMovement;
736+ passTime(movementTimeStepMs);
737+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
738+ }
739+
740+ QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
741+
742+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
743+}
744+
745+void tst_DirectionalDragArea::sceneDistance()
746+{
747+ QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
748+ QFETCH(qreal, rotation);
749+ QFETCH(QPointF, dragDirectionVector);
750+ baseItem->setRotation(rotation);
751+
752+ QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
753+ Q_ASSERT(rightwardsLauncher != 0);
754+
755+ DirectionalDragArea *edgeDragArea =
756+ rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
757+ Q_ASSERT(edgeDragArea != 0);
758+ edgeDragArea->setRecognitionTimer(fakeTimer);
759+ edgeDragArea->setTimeSource(fakeTimeSource);
760+
761+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
762+ QPointF touchPoint = initialTouchPos;
763+
764+ qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
765+
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;
770+
771+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
772+
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());
777+ }
778+
779+ qreal actualDragDistance = ((qreal)totalMovementSteps) * movementStepDistance;
780+
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);
785+
786+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
787+}
788+
789+void tst_DirectionalDragArea::sceneDistance_data()
790+{
791+ QTest::addColumn<qreal>("rotation");
792+ QTest::addColumn<QPointF>("dragDirectionVector");
793+
794+ QTest::newRow("not rotated") << 0. << QPointF(1., 0.);
795+ QTest::newRow("rotated by 90 degrees") << 90. << QPointF(0., 1.);
796+}
797+
707798QTEST_MAIN(tst_DirectionalDragArea)
708799
709800#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}
tests/qmltests/Components/tst_DragHandle.qml+71−56
@@ -29,62 +29,67 @@ import Ubuntu.Gestures 0.1
2929 */
3030Item {
3131 id: root
32− width: 700
33− height: 500
32+ width: units.gu(70)
33+ height: units.gu(70)
3434
3535 property var dragHandle
3636
3737 property bool stretch: false
3838 property real hintDisplacement: 0
3939
40− VerticalShowable {
41− onDragHandleRecognizedGesture: { root.dragHandle = dragHandle }
42− stretch: root.stretch
43− hintDisplacement: root.hintDisplacement
44− }
45−
46− HorizontalShowable {
47− onDragHandleRecognizedGesture: { root.dragHandle = dragHandle }
48− stretch: root.stretch
49− hintDisplacement: root.hintDisplacement
50− }
40+ Item {
41+ id: baseItem
42+ anchors.fill: parent
5143
52− // Visually mark drag threshold
53− Rectangle {
54− color: "black"
55− width: 2
56− height: parent.height
44+ VerticalShowable {
45+ onDragHandleRecognizedGesture: { root.dragHandle = dragHandle }
46+ stretch: root.stretch
47+ hintDisplacement: root.hintDisplacement
48+ }
5749
58− visible: dragHandle !== undefined && Direction.isHorizontal(dragHandle.direction)
50+ HorizontalShowable {
51+ onDragHandleRecognizedGesture: { root.dragHandle = dragHandle }
52+ stretch: root.stretch
53+ hintDisplacement: root.hintDisplacement
54+ }
5955
60− x: {
61− if (dragHandle) {
62− if (dragHandle.direction === Direction.Rightwards) {
63− dragHandle.edgeDragEvaluator.dragThreshold;
56+ // Visually mark drag threshold
57+ Rectangle {
58+ color: "black"
59+ width: 2
60+ height: parent.height
61+
62+ visible: dragHandle !== undefined && Direction.isHorizontal(dragHandle.direction)
63+
64+ x: {
65+ if (dragHandle) {
66+ if (dragHandle.direction === Direction.Rightwards) {
67+ dragHandle.edgeDragEvaluator.dragThreshold;
68+ } else {
69+ parent.width - dragHandle.edgeDragEvaluator.dragThreshold;
70+ }
6471 } else {
65− parent.width - dragHandle.edgeDragEvaluator.dragThreshold;
72+ 0
6673 }
67− } else {
68− 0
6974 }
7075 }
71− }
72− Rectangle {
73− color: "black";
74− height: 2
75− width: parent.width
76−
77− visible: dragHandle !== undefined && Direction.isVertical(dragHandle.direction)
78−
79− y: {
80− if (dragHandle) {
81− if (dragHandle.direction === Direction.Downwards) {
82− dragHandle.edgeDragEvaluator.dragThreshold;
76+ Rectangle {
77+ color: "black";
78+ height: 2
79+ width: parent.width
80+
81+ visible: dragHandle !== undefined && Direction.isVertical(dragHandle.direction)
82+
83+ y: {
84+ if (dragHandle) {
85+ if (dragHandle.direction === Direction.Downwards) {
86+ dragHandle.edgeDragEvaluator.dragThreshold;
87+ } else {
88+ parent.height - dragHandle.edgeDragEvaluator.dragThreshold;
89+ }
8390 } else {
84− parent.height - dragHandle.edgeDragEvaluator.dragThreshold;
91+ 0
8592 }
86− } else {
87− 0
8893 }
8994 }
9095 }
@@ -119,27 +124,37 @@ Item {
119124 }
120125 }
121126
122− TestButton {
123− id: stretchButton
127+ Row {
124128 anchors.bottom: parent.bottom
125129 anchors.left: parent.left
126130 anchors.margins: units.gu(1)
131+ spacing: units.gu(1)
127132
128− text: root.stretch ? "stretch" : "move"
129− onClicked: { root.stretch = !root.stretch; }
130− }
133+ Button {
134+ id: stretchButton
135+ text: root.stretch ? "stretch" : "move"
136+ onClicked: { root.stretch = !root.stretch; }
137+ }
131138
132− TestButton {
133− anchors.bottom: parent.bottom
134− anchors.left: stretchButton.right
135− anchors.margins: units.gu(1)
139+ Button {
140+ text: root.hintDisplacement > 0 ? "hint" : "no hint"
141+ onClicked: {
142+ if (root.hintDisplacement > 0) {
143+ root.hintDisplacement = 0;
144+ } else {
145+ root.hintDisplacement = units.gu(6);
146+ }
147+ }
148+ }
136149
137− text: root.hintDisplacement > 0 ? "hint" : "no hint"
138− onClicked: {
139− if (root.hintDisplacement > 0) {
140− root.hintDisplacement = 0;
141− } else {
142− root.hintDisplacement = units.gu(6);
150+ Button {
151+ text: "rotation: " + baseItem.rotation
152+ onClicked: {
153+ if (baseItem.rotation === 0.0) {
154+ baseItem.rotation = 90.0
155+ } else {
156+ baseItem.rotation = 0.0
157+ }
143158 }
144159 }
145160 }