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: 's avatarMartin Jones <martin.jones@nokia.com>
parent 80b56127
......@@ -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;
......@@ -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;
......@@ -974,28 +974,26 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
q->movementStarting();
}
if (!lastPos.isNull()) {
qint64 currentTimestamp = computeCurrentTime(event);
qreal elapsed = qreal(currentTimestamp - lastPosTime) / 1000.;
if (elapsed <= 0)
return;
lastPosTime = currentTimestamp;
QQuickMouseEventEx *extended = QQuickMouseEventEx::extended(event);
if (q->yflick() && !rejectY) {
if (extended && extended->capabilities().testFlag(QTouchDevice::Velocity)) {
vData.addVelocitySample(extended->velocity().y(), maxVelocity);
} else {
qreal dy = event->localPos().y()-lastPos.y();
vData.addVelocitySample(dy/elapsed, maxVelocity);
}
qint64 currentTimestamp = computeCurrentTime(event);
qreal elapsed = qreal(currentTimestamp - (lastPos.isNull() ? lastPressTime : lastPosTime)) / 1000.;
if (elapsed <= 0)
return;
lastPosTime = currentTimestamp;
QQuickMouseEventEx *extended = QQuickMouseEventEx::extended(event);
if (q->yflick() && !rejectY) {
if (extended && extended->capabilities().testFlag(QTouchDevice::Velocity)) {
vData.addVelocitySample(extended->velocity().y(), maxVelocity);
} else {
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();
hData.addVelocitySample(dx/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.isNull() ? pressPos.x() : lastPos.x());
hData.addVelocitySample(dx/elapsed, maxVelocity);
}
}
......
......@@ -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();
......@@ -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()));
......
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