on xenial help sign in
DirectionalDragArea: Reset status if disabled while dragging Fixes: 1276122
commit92f1da81b44b0f8a9decc9824fb8e94687a6d74d authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateFri 28 Feb 2014, 10:47 (13 years ago) parentd23d5ff7c8f6fb
3 files changed+56
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+9 plugins/Ubuntu/Gestures/DirectionalDragArea.h+1 tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+46
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+9
@@ -129,6 +129,8 @@ DirectionalDragArea::DirectionalDragArea(QQuickItem *parent)
129129 m_recognitionTimer->setInterval(60);
130130
131131 m_velocityCalculator = new AxisVelocityCalculator(this);
132+
133+ connect(this, &QQuickItem::enabledChanged, this, &DirectionalDragArea::onEnabledChanged);
132134}
133135
134136Direction::Type DirectionalDragArea::direction() const
@@ -528,6 +530,13 @@ void DirectionalDragArea::checkSpeed()
528530 m_numSamplesOnLastSpeedCheck = m_velocityCalculator->numSamples();
529531}
530532
533+void DirectionalDragArea::onEnabledChanged()
534+{
535+ if (!isEnabled() && m_status != WaitingForTouch) {
536+ setStatus(WaitingForTouch);
537+ }
538+}
539+
531540void DirectionalDragArea::setStatus(DirectionalDragArea::Status newStatus)
532541{
533542 if (newStatus == m_status)
plugins/Ubuntu/Gestures/DirectionalDragArea.h+1
@@ -218,6 +218,7 @@ protected:
218218
219219private Q_SLOTS:
220220 void checkSpeed();
221+ void onEnabledChanged();
221222
222223private:
223224 void touchEvent_absent(QTouchEvent *event);
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+46
@@ -86,6 +86,7 @@ private Q_SLOTS:
8686 void rotated();
8787 void sceneDistance();
8888 void sceneDistance_data();
89+ void disabledWhileDragging();
8990
9091private:
9192 void passTime(qint64 timeSpan);
@@ -795,6 +796,51 @@ void tst_DirectionalDragArea::sceneDistance_data()
795796 QTest::newRow("rotated by 90 degrees") << 90. << QPointF(0., 1.);
796797}
797798
799+/*
800+ Regression test for https://bugs.launchpad.net/unity8/+bug/1276122
801+
802+ The bug:
803+ If setting "enabled: false" while the DirectionalDragArea's (DDA) dragging
804+ property is true, the DDA stays in that state and doesn't recover any more.
805+*/
806+void tst_DirectionalDragArea::disabledWhileDragging()
807+{
808+ DirectionalDragArea *edgeDragArea =
809+ m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
810+ Q_ASSERT(edgeDragArea != 0);
811+ edgeDragArea->setRecognitionTimer(fakeTimer);
812+ edgeDragArea->setTimeSource(fakeTimeSource);
813+
814+ QPointF touchPoint = calculateInitialTouchPos(edgeDragArea);
815+
816+ qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
817+ QPointF dragDirectionVector(1., 0.); // horizontal positive
818+
819+ qreal movementStepDistance = edgeDragArea->distanceThreshold() * 0.1f;
820+ QPointF touchMovement = dragDirectionVector * movementStepDistance;
821+ int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
822+ int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
823+
824+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
825+
826+ for (int i = 0; i < totalMovementSteps; ++i) {
827+ touchPoint += touchMovement;
828+ passTime(movementTimeStepMs);
829+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
830+ }
831+
832+ QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
833+ QCOMPARE(edgeDragArea->dragging(), true);
834+
835+ // disable the dragArea while it's being dragged.
836+ edgeDragArea->setEnabled(false);
837+
838+ QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
839+ QCOMPARE(edgeDragArea->dragging(), false);
840+
841+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
842+}
843+
798844QTEST_MAIN(tst_DirectionalDragArea)
799845
800846#include "tst_DirectionalDragArea.moc"