on xenial help sign in
Fix DirectionalDragArea::sceneDistance() when the DDA is rotated
8684344Daniel d'Andrada
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+16−9
@@ -246,13 +246,15 @@ qreal DirectionalDragArea::distance() const
246 }
246 }
247}
247}
248
248
249+void DirectionalDragArea::updateSceneDistance()
250+{
251+ QPointF totalMovement = m_previousScenePos - m_startScenePos;
252+ m_sceneDistance = projectOntoDirectionVector(totalMovement);
253+}
254+
249qreal DirectionalDragArea::sceneDistance() const
255qreal DirectionalDragArea::sceneDistance() const
250{
256{
251− if (Direction::isHorizontal(m_direction)) {
257+ return m_sceneDistance;
252− return m_previousScenePos.x() - m_startScenePos.x();
253− } else {
254− return m_previousScenePos.y() - m_startScenePos.y();
255− }
256}
258}
257
259
258qreal DirectionalDragArea::touchX() const
260qreal DirectionalDragArea::touchX() const
@@ -587,18 +589,23 @@ void DirectionalDragArea::setPreviousScenePos(const QPointF &point)
587 bool xChanged = m_previousScenePos.x() != point.x();
589 bool xChanged = m_previousScenePos.x() != point.x();
588 bool yChanged = m_previousScenePos.y() != point.y();
590 bool yChanged = m_previousScenePos.y() != point.y();
589
591
592+ if (!xChanged && !yChanged)
593+ return;
594+
595+ qreal oldSceneDistance = sceneDistance();
590 m_previousScenePos = point;
596 m_previousScenePos = point;
597+ updateSceneDistance();
598+
599+ if (oldSceneDistance != sceneDistance()) {
600+ Q_EMIT sceneDistanceChanged(sceneDistance());
601+ }
591
602
592 if (xChanged) {
603 if (xChanged) {
593 Q_EMIT touchSceneXChanged(point.x());
604 Q_EMIT touchSceneXChanged(point.x());
594− if (Direction::isHorizontal(m_direction))
595− Q_EMIT sceneDistanceChanged(sceneDistance());
596 }
605 }
597
606
598 if (yChanged) {
607 if (yChanged) {
599 Q_EMIT touchSceneYChanged(point.y());
608 Q_EMIT touchSceneYChanged(point.y());
600− if (Direction::isVertical(m_direction))
601− Q_EMIT sceneDistanceChanged(sceneDistance());
602 }
609 }
603}
610}
604
611
plugins/Ubuntu/Gestures/DirectionalDragArea.h+2
@@ -160,6 +160,7 @@ public:
160
160
161 qreal distance() const;
161 qreal distance() const;
162 qreal sceneDistance() const;
162 qreal sceneDistance() const;
163+ void updateSceneDistance();
163
164
164 qreal touchX() const;
165 qreal touchX() const;
165 qreal touchY() const;
166 qreal touchY() const;
@@ -242,6 +243,7 @@ private:
242 QPointF m_startScenePos;
243 QPointF m_startScenePos;
243 QPointF m_previousPos;
244 QPointF m_previousPos;
244 QPointF m_previousScenePos;
245 QPointF m_previousScenePos;
246+ qreal m_sceneDistance;
245 int m_touchId;
247 int m_touchId;
246
248
247 // A movement damper is used in some of the gesture recognition calculations
249 // A movement damper is used in some of the gesture recognition calculations