From 9f629961ad9f569eb1d31b5698a0779f104e65aa Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 16 Sep 2009 15:30:23 +1000 Subject: Make flicking a bit more resistant to spurrious input. --- src/declarative/fx/qfxflickable.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 1e6ad5a..c4d593c 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -587,8 +587,8 @@ void QFxFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) stealMouse = false; pressed = true; timeline.clear(); - velocityX = -1; - velocityY = -1; + velocityX = 0; + velocityY = 0; lastPos = QPoint(); lastPosTime.start(); pressPos = event->pos(); @@ -654,12 +654,16 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) elapsed = 1; if (q->yflick()) { qreal diff = event->pos().y() - lastPos.y(); - velocityY = diff / elapsed; + // average to reduce the effect of spurious moves + velocityY += diff / elapsed; + velocityY /= 2; } if (q->xflick()) { qreal diff = event->pos().x() - lastPos.x(); - velocityX = diff / elapsed; + // average to reduce the effect of spurious moves + velocityX += diff / elapsed; + velocityX /= 2; } } @@ -681,6 +685,12 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *even if (lastPosTime.isNull()) return; + if (lastPosTime.elapsed() > 100) { + // if we drag then pause before release we should not cause a flick. + velocityX = 0.0; + velocityY = 0.0; + } + vTime = timeline.time(); if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) flickY(velocityY); -- cgit v0.12