Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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: Martin Jones <martin.jones@nokia.com>
  • Loading branch information
Laszlo Agocs authored and Qt by Nokia committed Mar 21, 2012
1 parent 80b5612 commit 1312f4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/quick/items/qquickflickable.cpp
Expand Up @@ -887,11 +887,11 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
bool stealY = stealMouse;
bool stealX = stealMouse;

qint64 elapsed = computeCurrentTime(event) - lastPressTime;
qint64 elapsedSincePress = computeCurrentTime(event) - lastPressTime;

if (q->yflick()) {
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)
vData.dragStartOffset = dy;
qreal newY = dy + vData.pressPos - vData.dragStartOffset;
Expand Down Expand Up @@ -924,7 +924,7 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)

if (q->xflick()) {
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)
hData.dragStartOffset = dx;
qreal newX = dx + hData.pressPos - hData.dragStartOffset;
Expand Down Expand Up @@ -974,9 +974,8 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
q->movementStarting();
}

if (!lastPos.isNull()) {
qint64 currentTimestamp = computeCurrentTime(event);
qreal elapsed = qreal(currentTimestamp - lastPosTime) / 1000.;
qreal elapsed = qreal(currentTimestamp - (lastPos.isNull() ? lastPressTime : lastPosTime)) / 1000.;
if (elapsed <= 0)
return;
lastPosTime = currentTimestamp;
Expand All @@ -985,19 +984,18 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
if (extended && extended->capabilities().testFlag(QTouchDevice::Velocity)) {
vData.addVelocitySample(extended->velocity().y(), maxVelocity);
} else {
qreal dy = event->localPos().y()-lastPos.y();
qreal dy = event->localPos().y() - (lastPos.isNull() ? pressPos.y() : lastPos.y());
vData.addVelocitySample(dy/elapsed, maxVelocity);
}
}
if (q->xflick() && !rejectX) {
if (extended && extended->capabilities().testFlag(QTouchDevice::Velocity)) {
hData.addVelocitySample(extended->velocity().x(), maxVelocity);
} else {
qreal dx = event->localPos().x()-lastPos.x();
qreal dx = event->localPos().x() - (lastPos.isNull() ? pressPos.x() : lastPos.x());
hData.addVelocitySample(dx/elapsed, maxVelocity);
}
}
}

lastPos = event->localPos();
}
Expand Down
15 changes: 14 additions & 1 deletion tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
Expand Up @@ -441,6 +441,19 @@ void tst_qquickflickable::movingAndDragging()
// wait for any motion to end
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
vDragSpy.clear();
hDragSpy.clear();
Expand Down Expand Up @@ -493,7 +506,7 @@ void tst_qquickflickable::movingAndDragging()
vMoveSpy.clear();
hMoveSpy.clear();
moveSpy.clear();
QSignalSpy vFlickSpy(flickable, SIGNAL(flickingVerticallyChanged()));
vFlickSpy.clear();
QSignalSpy hFlickSpy(flickable, SIGNAL(flickingHorizontallyChanged()));
QSignalSpy flickSpy(flickable, SIGNAL(flickingChanged()));

Expand Down

0 comments on commit 1312f4d

Please sign in to comment.