Commit 1312f4d1 authored by Laszlo Agocs's avatar Laszlo Agocs Committed by Qt by Nokia

Allow flick on press-move-release in Flickable.

Right now it needs at least a press-move-move-release to start a flick
which is not ideal for touchscreens because a quick, short flick may
result in reporting only a single move.

Change-Id: I9bf2b4fea23b0eea9d9d00f0e79ce34f4d964bea
Reviewed-by: default avatarMartin Jones <martin.jones@nokia.com>
parent 80b56127
...@@ -887,11 +887,11 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event) ...@@ -887,11 +887,11 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
bool stealY = stealMouse; bool stealY = stealMouse;
bool stealX = stealMouse; bool stealX = stealMouse;
qint64 elapsed = computeCurrentTime(event) - lastPressTime; qint64 elapsedSincePress = computeCurrentTime(event) - lastPressTime;
if (q->yflick()) { if (q->yflick()) {
qreal dy = event->localPos().y() - pressPos.y(); qreal dy = event->localPos().y() - pressPos.y();
if (qAbs(dy) > qApp->styleHints()->startDragDistance() || elapsed > 200) { if (qAbs(dy) > qApp->styleHints()->startDragDistance() || elapsedSincePress > 200) {
if (!vMoved) if (!vMoved)
vData.dragStartOffset = dy; vData.dragStartOffset = dy;
qreal newY = dy + vData.pressPos - vData.dragStartOffset; qreal newY = dy + vData.pressPos - vData.dragStartOffset;
...@@ -924,7 +924,7 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event) ...@@ -924,7 +924,7 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
if (q->xflick()) { if (q->xflick()) {
qreal dx = event->localPos().x() - pressPos.x(); qreal dx = event->localPos().x() - pressPos.x();
if (qAbs(dx) > qApp->styleHints()->startDragDistance() || elapsed > 200) { if (qAbs(dx) > qApp->styleHints()->startDragDistance() || elapsedSincePress > 200) {
if (!hMoved) if (!hMoved)
hData.dragStartOffset = dx; hData.dragStartOffset = dx;
qreal newX = dx + hData.pressPos - hData.dragStartOffset; qreal newX = dx + hData.pressPos - hData.dragStartOffset;
...@@ -974,9 +974,8 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event) ...@@ -974,9 +974,8 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
q->movementStarting(); q->movementStarting();
} }
if (!lastPos.isNull()) {
qint64 currentTimestamp = computeCurrentTime(event); qint64 currentTimestamp = computeCurrentTime(event);
qreal elapsed = qreal(currentTimestamp - lastPosTime) / 1000.; qreal elapsed = qreal(currentTimestamp - (lastPos.isNull() ? lastPressTime : lastPosTime)) / 1000.;
if (elapsed <= 0) if (elapsed <= 0)
return; return;
lastPosTime = currentTimestamp; lastPosTime = currentTimestamp;
...@@ -985,7 +984,7 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event) ...@@ -985,7 +984,7 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
if (extended && extended->capabilities().testFlag(QTouchDevice::Velocity)) { if (extended && extended->capabilities().testFlag(QTouchDevice::Velocity)) {
vData.addVelocitySample(extended->velocity().y(), maxVelocity); vData.addVelocitySample(extended->velocity().y(), maxVelocity);
} else { } else {
qreal dy = event->localPos().y()-lastPos.y(); qreal dy = event->localPos().y() - (lastPos.isNull() ? pressPos.y() : lastPos.y());
vData.addVelocitySample(dy/elapsed, maxVelocity); vData.addVelocitySample(dy/elapsed, maxVelocity);
} }
} }
...@@ -993,11 +992,10 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event) ...@@ -993,11 +992,10 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
if (extended && extended->capabilities().testFlag(QTouchDevice::Velocity)) { if (extended && extended->capabilities().testFlag(QTouchDevice::Velocity)) {
hData.addVelocitySample(extended->velocity().x(), maxVelocity); hData.addVelocitySample(extended->velocity().x(), maxVelocity);
} else { } else {
qreal dx = event->localPos().x()-lastPos.x(); qreal dx = event->localPos().x() - (lastPos.isNull() ? pressPos.x() : lastPos.x());
hData.addVelocitySample(dx/elapsed, maxVelocity); hData.addVelocitySample(dx/elapsed, maxVelocity);
} }
} }
}
lastPos = event->localPos(); lastPos = event->localPos();
} }
......
...@@ -441,6 +441,19 @@ void tst_qquickflickable::movingAndDragging() ...@@ -441,6 +441,19 @@ void tst_qquickflickable::movingAndDragging()
// wait for any motion to end // wait for any motion to end
QTRY_VERIFY(flickable->isMoving() == false); QTRY_VERIFY(flickable->isMoving() == false);
// Vertical with a quick press-move-release: should cause a flick in release.
QSignalSpy vFlickSpy(flickable, SIGNAL(flickingVerticallyChanged()));
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50, 90));
QTest::qWait(10);
QTest::mouseMove(canvas, QPoint(50, 40));
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50, 40));
QCOMPARE(vFlickSpy.count(), 1);
// wait for any motion to end
QTRY_VERIFY(flickable->isMoving() == false);
//Horizontal //Horizontal
vDragSpy.clear(); vDragSpy.clear();
hDragSpy.clear(); hDragSpy.clear();
...@@ -493,7 +506,7 @@ void tst_qquickflickable::movingAndDragging() ...@@ -493,7 +506,7 @@ void tst_qquickflickable::movingAndDragging()
vMoveSpy.clear(); vMoveSpy.clear();
hMoveSpy.clear(); hMoveSpy.clear();
moveSpy.clear(); moveSpy.clear();
QSignalSpy vFlickSpy(flickable, SIGNAL(flickingVerticallyChanged())); vFlickSpy.clear();
QSignalSpy hFlickSpy(flickable, SIGNAL(flickingHorizontallyChanged())); QSignalSpy hFlickSpy(flickable, SIGNAL(flickingHorizontallyChanged()));
QSignalSpy flickSpy(flickable, SIGNAL(flickingChanged())); QSignalSpy flickSpy(flickable, SIGNAL(flickingChanged()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment