aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-09-13 12:50:48 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-16 02:15:03 +0200
commite79c448e28c67cb6acd63e8b4bac6c7b08c1f897 (patch)
treefddd6c707e744849f73f4aca4cb14b70a17fcd10 /src
parent8c175bee55f1e0e0bb27cbf72911fedf370c26c6 (diff)
Velocities reported by Flickable in onFlickStarted can be 0
Change 55cfbdb7c64068ae68f7baaceb8acfb96cb0c07e manually applied from Qt 4.7 Ensure the smoothed velocity is set at the start of the flick. Ensure that the smoothed velocity animation isn't restarted unless there is new valid data. Change-Id: Ia77249be9980aba268a1bfa0ea3f69c49fa09e5e Reviewed-by: Bea Lam Reviewed-on: http://codereview.qt-project.org/4712 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/items/qsgflickable.cpp30
-rw-r--r--src/qtquick1/graphicsitems/qdeclarativeflickable.cpp30
2 files changed, 42 insertions, 18 deletions
diff --git a/src/declarative/items/qsgflickable.cpp b/src/declarative/items/qsgflickable.cpp
index ce8afa1f4c..36d7db217c 100644
--- a/src/declarative/items/qsgflickable.cpp
+++ b/src/declarative/items/qsgflickable.cpp
@@ -962,18 +962,24 @@ void QSGFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event)
qreal velocity = vData.velocity;
if (vData.atBeginning || vData.atEnd)
velocity /= 2;
- if (qAbs(velocity) > MinimumFlickVelocity && qAbs(event->localPos().y() - pressPos.y()) > FlickThreshold)
+ if (q->yflick() && qAbs(velocity) > MinimumFlickVelocity && qAbs(event->localPos().y() - pressPos.y()) > FlickThreshold) {
+ velocityTimeline.reset(vData.smoothVelocity);
+ vData.smoothVelocity.setValue(-velocity);
flickY(velocity);
- else
+ } else {
fixupY();
+ }
velocity = hData.velocity;
if (hData.atBeginning || hData.atEnd)
velocity /= 2;
- if (qAbs(velocity) > MinimumFlickVelocity && qAbs(event->localPos().x() - pressPos.x()) > FlickThreshold)
+ if (q->xflick() && qAbs(velocity) > MinimumFlickVelocity && qAbs(event->localPos().x() - pressPos.x()) > FlickThreshold) {
+ velocityTimeline.reset(hData.smoothVelocity);
+ hData.smoothVelocity.setValue(-velocity);
flickX(velocity);
- else
+ } else {
fixupX();
+ }
if (!timeline.isActive())
q->movementEnding();
@@ -1156,19 +1162,25 @@ void QSGFlickable::viewportMoved()
qreal prevX = d->lastFlickablePosition.x();
qreal prevY = d->lastFlickablePosition.y();
- d->velocityTimeline.clear();
if (d->pressed || d->calcVelocity) {
int elapsed = QSGItemPrivate::restart(d->velocityTime);
if (elapsed > 0) {
qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / elapsed;
+ if (qAbs(horizontalVelocity) > 0) {
+ d->velocityTimeline.reset(d->hData.smoothVelocity);
+ d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing);
+ d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ }
qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / elapsed;
- d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ if (qAbs(verticalVelocity) > 0) {
+ d->velocityTimeline.reset(d->vData.smoothVelocity);
+ d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing);
+ d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ }
}
} else {
if (d->timeline.time() > d->vTime) {
+ d->velocityTimeline.clear();
qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / (d->timeline.time() - d->vTime);
qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / (d->timeline.time() - d->vTime);
d->hData.smoothVelocity.setValue(horizontalVelocity);
diff --git a/src/qtquick1/graphicsitems/qdeclarativeflickable.cpp b/src/qtquick1/graphicsitems/qdeclarativeflickable.cpp
index f145312334..6fa92b3bfa 100644
--- a/src/qtquick1/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/qtquick1/graphicsitems/qdeclarativeflickable.cpp
@@ -913,18 +913,24 @@ void QDeclarative1FlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseE
qreal velocity = vData.velocity;
if (vData.atBeginning || vData.atEnd)
velocity /= 2;
- if (qAbs(velocity) > MinimumFlickVelocity && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold)
+ if (q->yflick() && qAbs(velocity) > MinimumFlickVelocity && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) {
+ velocityTimeline.reset(vData.smoothVelocity);
+ vData.smoothVelocity.setValue(-velocity);
flickY(velocity);
- else
+ } else {
fixupY();
+ }
velocity = hData.velocity;
if (hData.atBeginning || hData.atEnd)
velocity /= 2;
- if (qAbs(velocity) > MinimumFlickVelocity && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold)
+ if (q->xflick() && qAbs(velocity) > MinimumFlickVelocity && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) {
+ velocityTimeline.reset(hData.smoothVelocity);
+ hData.smoothVelocity.setValue(-velocity);
flickX(velocity);
- else
+ } else {
fixupX();
+ }
if (!timeline.isActive())
q->movementEnding();
@@ -1124,19 +1130,25 @@ void QDeclarative1Flickable::viewportMoved()
qreal prevX = d->lastFlickablePosition.x();
qreal prevY = d->lastFlickablePosition.y();
- d->velocityTimeline.clear();
if (d->pressed || d->calcVelocity) {
int elapsed = QDeclarativeItemPrivate::restart(d->velocityTime);
if (elapsed > 0) {
qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / elapsed;
+ if (qAbs(horizontalVelocity) > 0) {
+ d->velocityTimeline.reset(d->hData.smoothVelocity);
+ d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing);
+ d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ }
qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / elapsed;
- d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ if (qAbs(verticalVelocity) > 0) {
+ d->velocityTimeline.reset(d->vData.smoothVelocity);
+ d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing);
+ d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ }
}
} else {
if (d->timeline.time() > d->vTime) {
+ d->velocityTimeline.clear();
qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / (d->timeline.time() - d->vTime);
qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / (d->timeline.time() - d->vTime);
d->hData.smoothVelocity.setValue(horizontalVelocity);