on xenial help sign in
DirectionalDragArea: add touchSceneX, touchSceneY, and sceneDistance properties.

Approved by Albert Astals Cid, PS Jenkins bot.

commit1ecc4df766b2a8428c12e162074f53eafe6500af authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateFri 28 Jun 2013, 16:10 (13 years ago) parent3cdae145861498
3 files changed+127−3
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+48−2 plugins/Ubuntu/Gestures/DirectionalDragArea.h+19−1 tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+60
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+48−2
@@ -155,6 +155,15 @@ qreal DirectionalDragArea::distance() const
155155 }
156156}
157157
158+qreal DirectionalDragArea::sceneDistance() const
159+{
160+ if (Direction::isHorizontal(m_direction)) {
161+ return m_previousScenePos.x() - m_startScenePos.x();
162+ } else {
163+ return m_previousScenePos.y() - m_startScenePos.y();
164+ }
165+}
166+
158167qreal DirectionalDragArea::touchX() const
159168{
160169 return m_previousPos.x();
@@ -165,6 +174,16 @@ qreal DirectionalDragArea::touchY() const
165174 return m_previousPos.y();
166175}
167176
177+qreal DirectionalDragArea::touchSceneX() const
178+{
179+ return m_previousScenePos.x();
180+}
181+
182+qreal DirectionalDragArea::touchSceneY() const
183+{
184+ return m_previousScenePos.y();
185+}
186+
168187void DirectionalDragArea::touchEvent(QTouchEvent *event)
169188{
170189 if (!isEnabled() || !isVisible()) {
@@ -192,14 +211,17 @@ void DirectionalDragArea::touchEvent_absent(QTouchEvent *event)
192211{
193212 if ((event->touchPointStates() && (Qt::TouchPointPressed || Qt::TouchPointMoved))
194213 && event->touchPoints().count() == 1) {
195− m_startPos = event->touchPoints()[0].pos();
196− m_touchId = event->touchPoints()[0].id();
214+ const QTouchEvent::TouchPoint &touchPoint = event->touchPoints()[0];
215+ m_startPos = touchPoint.pos();
216+ m_startScenePos = touchPoint.scenePos();
217+ m_touchId = touchPoint.id();
197218 m_dampedPos.reset(m_startPos);
198219 updateVelocityCalculator(m_startPos);
199220 m_velocityCalculator->reset();
200221 m_numSamplesOnLastSpeedCheck = 0;
201222 m_silenceTime = 0;
202223 setPreviousPos(m_startPos);
224+ setPreviousScenePos(m_startScenePos);
203225
204226 if (m_distanceThreshold > 0)
205227 setStatus(Undecided);
@@ -242,6 +264,7 @@ void DirectionalDragArea::touchEvent_undecided(QTouchEvent *event)
242264 }
243265
244266 setPreviousPos(touchPos);
267+ setPreviousScenePos(touchPoint->scenePos());
245268
246269 if (movedFarEnough(touchPos)) {
247270 setStatus(Recognized);
@@ -253,6 +276,7 @@ void DirectionalDragArea::touchEvent_recognized(QTouchEvent *event)
253276 const QTouchEvent::TouchPoint *touchPoint = fetchTargetTouchPoint(event);
254277
255278 setPreviousPos(touchPoint->pos());
279+ setPreviousScenePos(touchPoint->scenePos());
256280
257281 if (touchPoint->state() == Qt::TouchPointReleased) {
258282 setStatus(WaitingForTouch);
@@ -398,6 +422,28 @@ void DirectionalDragArea::setPreviousPos(QPointF point)
398422 }
399423}
400424
425+void DirectionalDragArea::setPreviousScenePos(QPointF point)
426+{
427+ Q_ASSERT(m_status != Rejected);
428+
429+ bool xChanged = m_previousScenePos.x() != point.x();
430+ bool yChanged = m_previousScenePos.y() != point.y();
431+
432+ m_previousScenePos = point;
433+
434+ if (xChanged) {
435+ Q_EMIT touchSceneXChanged(point.x());
436+ if (Direction::isHorizontal(m_direction))
437+ Q_EMIT sceneDistanceChanged(sceneDistance());
438+ }
439+
440+ if (yChanged) {
441+ Q_EMIT touchSceneYChanged(point.y());
442+ if (Direction::isVertical(m_direction))
443+ Q_EMIT sceneDistanceChanged(sceneDistance());
444+ }
445+}
446+
401447void DirectionalDragArea::updateVelocityCalculator(QPointF point)
402448{
403449 if (Direction::isHorizontal(m_direction)) {
plugins/Ubuntu/Gestures/DirectionalDragArea.h+19−1
@@ -60,10 +60,18 @@ class UBUNTUGESTURES_EXPORT DirectionalDragArea : public QQuickItem {
6060 // DirectionalDragArea's direction.
6161 Q_PROPERTY(qreal distance READ distance NOTIFY distanceChanged)
6262
63− // Position of the touch point performing the drag.
63+ // The distance travelled by the finger along the axis specified by
64+ // DirectionalDragArea's direction in scene coordinates
65+ Q_PROPERTY(qreal sceneDistance READ sceneDistance NOTIFY sceneDistanceChanged)
66+
67+ // Position of the touch point performing the drag relative to this item.
6468 Q_PROPERTY(qreal touchX READ touchX NOTIFY touchXChanged)
6569 Q_PROPERTY(qreal touchY READ touchY NOTIFY touchYChanged)
6670
71+ // Position of the touch point performing the drag, in scene's coordinate system
72+ Q_PROPERTY(qreal touchSceneX READ touchSceneX NOTIFY touchSceneXChanged)
73+ Q_PROPERTY(qreal touchSceneY READ touchSceneY NOTIFY touchSceneYChanged)
74+
6775 // The current status of the directional drag gesture area.
6876 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
6977
@@ -146,10 +154,14 @@ public:
146154 Status status() const { return m_status; }
147155
148156 qreal distance() const;
157+ qreal sceneDistance() const;
149158
150159 qreal touchX() const;
151160 qreal touchY() const;
152161
162+ qreal touchSceneX() const;
163+ qreal touchSceneY() const;
164+
153165 bool dragging() const { return (m_status == Undecided) || (m_status == Recognized); }
154166
155167 qreal maxDeviation() const { return m_dampedPos.maxDelta(); }
@@ -180,6 +192,7 @@ Q_SIGNALS:
180192 void statusChanged(Status value);
181193 void draggingChanged(bool value);
182194 void distanceChanged(qreal value);
195+ void sceneDistanceChanged(qreal value);
183196 void maxDeviationChanged(qreal value);
184197 void wideningAngleChanged(qreal value);
185198 void distanceThresholdChanged(qreal value);
@@ -187,6 +200,8 @@ Q_SIGNALS:
187200 void maxSilenceTimeChanged(int value);
188201 void touchXChanged(qreal value);
189202 void touchYChanged(qreal value);
203+ void touchSceneXChanged(qreal value);
204+ void touchSceneYChanged(qreal value);
190205
191206protected:
192207 virtual void touchEvent(QTouchEvent *event);
@@ -205,12 +220,15 @@ private:
205220 const QTouchEvent::TouchPoint *fetchTargetTouchPoint(QTouchEvent *event);
206221 void setStatus(Status newStatus);
207222 void setPreviousPos(QPointF point);
223+ void setPreviousScenePos(QPointF point);
208224 void updateVelocityCalculator(QPointF point);
209225
210226 Status m_status;
211227
212228 QPointF m_startPos;
229+ QPointF m_startScenePos;
213230 QPointF m_previousPos;
231+ QPointF m_previousScenePos;
214232 int m_touchId;
215233
216234 // A movement damper is used in some of the gesture recognition calculations
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+60
@@ -65,6 +65,8 @@ private Q_SLOTS:
6565 void minSpeed_data();
6666 void recognitionTimerUsage();
6767 void maxSilenceTime();
68+ void sceneXAndX();
69+ void sceneYAndY();
6870
6971private:
7072 QQuickView *createView();
@@ -454,6 +456,64 @@ void tst_DirectionalDragArea::maxSilenceTime()
454456 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Rejected);
455457}
456458
459+/*
460+ Checks that it informs the X coordinate of the touch point in local and scene coordinates
461+ correctly.
462+ */
463+void tst_DirectionalDragArea::sceneXAndX()
464+{
465+ DirectionalDragArea *edgeDragArea =
466+ view->rootObject()->findChild<DirectionalDragArea*>("hnDragArea");
467+ QVERIFY(edgeDragArea != 0);
468+ edgeDragArea->setRecognitionTimer(fakeTimer);
469+ edgeDragArea->setTimeSource(fakeTimeSource);
470+
471+ QPointF touchScenePos(view->width() - (edgeDragArea->width()/2.0f), view->height()/2.0f);
472+
473+ fakeTimeSource->m_msecsSinceReference = 0;
474+ QTest::touchEvent(view, device).press(0, touchScenePos.toPoint());
475+
476+ QSignalSpy touchXSpy(edgeDragArea, SIGNAL(touchXChanged(qreal)));
477+ QSignalSpy touchSceneXSpy(edgeDragArea, SIGNAL(touchSceneXChanged(qreal)));
478+
479+ touchScenePos.rx() = view->width() / 2;
480+ QTest::touchEvent(view, device).move(0, touchScenePos.toPoint());
481+
482+ QCOMPARE(touchXSpy.count(), 1);
483+ QCOMPARE(touchSceneXSpy.count(), 1);
484+ QCOMPARE(edgeDragArea->touchX(), touchScenePos.x() - edgeDragArea->x());
485+ QCOMPARE(edgeDragArea->touchSceneX(), touchScenePos.x());
486+}
487+
488+/*
489+ Checks that it informs the Y coordinate of the touch point in local and scene coordinates
490+ correctly.
491+ */
492+void tst_DirectionalDragArea::sceneYAndY()
493+{
494+ DirectionalDragArea *edgeDragArea =
495+ view->rootObject()->findChild<DirectionalDragArea*>("vnDragArea");
496+ QVERIFY(edgeDragArea != 0);
497+ edgeDragArea->setRecognitionTimer(fakeTimer);
498+ edgeDragArea->setTimeSource(fakeTimeSource);
499+
500+ QPointF touchScenePos(view->width()/2.0f, view->height() - (edgeDragArea->height()/2.0f));
501+
502+ fakeTimeSource->m_msecsSinceReference = 0;
503+ QTest::touchEvent(view, device).press(0, touchScenePos.toPoint());
504+
505+ QSignalSpy touchYSpy(edgeDragArea, SIGNAL(touchYChanged(qreal)));
506+ QSignalSpy touchSceneYSpy(edgeDragArea, SIGNAL(touchSceneYChanged(qreal)));
507+
508+ touchScenePos.ry() = view->height() / 2;
509+ QTest::touchEvent(view, device).move(0, touchScenePos.toPoint());
510+
511+ QCOMPARE(touchYSpy.count(), 1);
512+ QCOMPARE(touchSceneYSpy.count(), 1);
513+ QCOMPARE(edgeDragArea->touchY(), touchScenePos.y() - edgeDragArea->y());
514+ QCOMPARE(edgeDragArea->touchSceneY(), touchScenePos.y());
515+}
516+
457517QTEST_MAIN(tst_DirectionalDragArea)
458518
459519#include "tst_DirectionalDragArea.moc"