on xenial help sign in
DragHandle: Never restart hinting animation while still pressed Fixes: 1269022
e9862c7Daniel d'Andrada
qml/Components/DragHandle.qml+7−7
@@ -97,7 +97,7 @@ EdgeDragArea {
97 // Private stuff
97 // Private stuff
98 QtObject {
98 QtObject {
99 id: d
99 id: d
100− property var previousStatus: undefined
100+ property var previousStatus: DirectionalDragArea.WaitingForTouch
101 property real startValue
101 property real startValue
102 property real minValue: Direction.isPositive(direction) ? startValue
102 property real minValue: Direction.isPositive(direction) ? startValue
103 : startValue - maxTotalDragDistance
103 : startValue - maxTotalDragDistance
@@ -193,14 +193,14 @@ EdgeDragArea {
193 d.rollbackDrag();
193 d.rollbackDrag();
194 }
194 }
195 } else /* Undecided || Recognized */ {
195 } else /* Undecided || Recognized */ {
196− if (d.previousStatus === DirectionalDragArea.WaitingForTouch ||
196+ if (d.previousStatus === DirectionalDragArea.WaitingForTouch) {
197− d.previousStatus === undefined) {
198 dragEvaluator.reset();
197 dragEvaluator.reset();
199 d.startValue = parent[d.targetProp];
198 d.startValue = parent[d.targetProp];
200− }
199+
201− if (hintDisplacement > 0) {
200+ if (hintDisplacement > 0) {
202− hintingAnimation.targetValue = d.startValue;
201+ hintingAnimation.targetValue = d.startValue;
203− hintingAnimation.start();
202+ hintingAnimation.start();
203+ }
204 }
204 }
205 }
205 }
206
206
tests/qmltests/Components/tst_DragHandle.cpp+65−10
@@ -62,9 +62,13 @@ private Q_SLOTS:
62 void stretch_horizontal();
62 void stretch_horizontal();
63 void stretch_vertical();
63 void stretch_vertical();
64 void hintingAnimation();
64 void hintingAnimation();
65+ void hintingAnimation_dontRestartAfterFinishedAndStillPressed();
66+
65
67
66private:
68private:
67 void flickAndHold(DirectionalDragArea *dragHandle, qreal distance);
69 void flickAndHold(DirectionalDragArea *dragHandle, qreal distance);
70+ void drag(QPointF &touchPoint, const QPointF& direction, qreal distance,
71+ int numSteps, qint64 timeMs = 500);
68 DirectionalDragArea *fetchAndSetupDragHandle(const char *objectName);
72 DirectionalDragArea *fetchAndSetupDragHandle(const char *objectName);
69 qreal fetchDragThreshold(DirectionalDragArea *dragHandle);
73 qreal fetchDragThreshold(DirectionalDragArea *dragHandle);
70 void tryCompare(std::function<qreal ()> actualFunc, qreal expectedValue);
74 void tryCompare(std::function<qreal ()> actualFunc, qreal expectedValue);
@@ -161,25 +165,29 @@ void tst_DragHandle::flickAndHold(DirectionalDragArea *dragHandle,
161 QPointF initialTouchPos = dragHandle->mapToScene(
165 QPointF initialTouchPos = dragHandle->mapToScene(
162 QPointF(dragHandle->width() / 2.0, dragHandle->height() / 2.0));
166 QPointF(dragHandle->width() / 2.0, dragHandle->height() / 2.0));
163 QPointF touchPoint = initialTouchPos;
167 QPointF touchPoint = initialTouchPos;
164− int numSteps = 10;
165− qint64 flickTimeMs = 500;
166− qint64 timeStep = flickTimeMs / numSteps;
167
168
169+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
170+
171+ int numSteps = 10;
168 QPointF dragDirectionVector = calculateDirectionVector(dragHandle);
172 QPointF dragDirectionVector = calculateDirectionVector(dragHandle);
169− QPointF touchMovement = dragDirectionVector * (distance / (qreal)numSteps);
173+ drag(touchPoint, dragDirectionVector, distance, numSteps);
170
174
175+ // Wait for quite a bit before finally releasing to make a very low flick/release
176+ // speed.
177+ m_fakeTimeSource->m_msecsSinceReference += 5000;
171− QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
178+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
179+}
172
180
181+void tst_DragHandle::drag(QPointF &touchPoint, const QPointF& direction, qreal distance,
182+ int numSteps, qint64 timeMs)
183+{
184+ qint64 timeStep = timeMs / numSteps;
185+ QPointF touchMovement = direction * (distance / (qreal)numSteps);
173 for (int i = 0; i < numSteps; ++i) {
186 for (int i = 0; i < numSteps; ++i) {
174 touchPoint += touchMovement;
187 touchPoint += touchMovement;
175 m_fakeTimeSource->m_msecsSinceReference += timeStep;
188 m_fakeTimeSource->m_msecsSinceReference += timeStep;
176 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
189 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
177 }
190 }
178−
179− // Wait for quite a bit before finally releasing to make a very low flick/release
180− // speed.
181− m_fakeTimeSource->m_msecsSinceReference += 5000;
182− QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
183}
191}
184
192
185DirectionalDragArea *tst_DragHandle::fetchAndSetupDragHandle(const char *objectName)
193DirectionalDragArea *tst_DragHandle::fetchAndSetupDragHandle(const char *objectName)
@@ -389,6 +397,53 @@ void tst_DragHandle::hintingAnimation()
389 QCOMPARE(parentItem->property("shown").toBool(), false);
397 QCOMPARE(parentItem->property("shown").toBool(), false);
390}
398}
391
399
400+/*
401+ Regression test for LP#1269022: https://bugs.launchpad.net/unity8/+bug/1269022
402+
403+ 1) Click on handle.
404+ 2) wait for hint portion to appear
405+ 3) slowly drag handle, only a few pixels
406+
407+ Expected outcome:
408+ Nothing happens
409+
410+ Actual outcome:
411+ Handle will momentarily move back to zero position, then back down to the
412+ hint displacement location.
413+ */
414+void tst_DragHandle::hintingAnimation_dontRestartAfterFinishedAndStillPressed()
415+{
416+ DirectionalDragArea *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
417+ QQuickItem *parentItem = dragHandle->parentItem();
418+ qreal hintDisplacement = 100.0;
419+
420+ // enable hinting animations
421+ m_view->rootObject()->setProperty("hintDisplacement", QVariant(hintDisplacement));
422+ m_view->rootObject()->setProperty("stretch", QVariant(true));
423+
424+ QCOMPARE(parentItem->height(), 0.0);
425+
426+ QPointF initialTouchPos = dragHandle->mapToScene(
427+ QPointF(dragHandle->width() / 2.0, dragHandle->height() / 2.0));
428+ QPointF touchPoint = initialTouchPos;
429+
430+ // Pressing causes the Showable to be stretched by hintDisplacement pixels
431+ const int touchId = 0;
432+ QTest::touchEvent(m_view, m_device).press(touchId, touchPoint.toPoint());
433+ tryCompare([&](){ return parentItem->height(); }, hintDisplacement);
434+
435+
436+ QSignalSpy parentHeightChangedSpy(parentItem, SIGNAL(heightChanged()));
437+
438+ drag(touchPoint, QPointF(0.0, -1.0) /*dragDirectionVector*/, 15 /*distance*/, 3 /*numSteps*/);
439+
440+ // Give some time for animations to run, if any
441+ QTest::qWait(300);
442+
443+ // parentItem height shouldn't have changed at all
444+ QVERIFY(parentHeightChangedSpy.isEmpty());
445+}
446+
392QTEST_MAIN(tst_DragHandle)
447QTEST_MAIN(tst_DragHandle)
393
448
394#include "tst_DragHandle.moc"
449#include "tst_DragHandle.moc"