diff options
| author | Ralf Engels <ralf.engels@nokia.com> | 2010-04-16 13:51:27 +0200 |
|---|---|---|
| committer | Ralf Engels <ralf.engels@nokia.com> | 2010-04-16 13:51:27 +0200 |
| commit | 730bb4fba2248cc37dfe05cd6450dc2752e845ba (patch) | |
| tree | 2b57b94ac2de5accb91635056262adfea8801375 | |
| parent | 7b29d03406d8338f4f1a6c86d052d88238b7c44c (diff) | |
Fix going into overshoot with overshootMaximumDistance
| -rw-r--r-- | qkineticscroller.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/qkineticscroller.cpp b/qkineticscroller.cpp index 387db04..cace269 100644 --- a/qkineticscroller.cpp +++ b/qkineticscroller.cpp @@ -292,8 +292,6 @@ const char *QKineticScrollerPrivate::inputName(QKineticScroller::Input input) void QKineticScrollerPrivate::timerEvent(QTimerEvent *e) { - Q_Q(QKineticScroller); - if (e->timerId() != timerId) { QObject::timerEvent(e); return; @@ -315,8 +313,6 @@ void QKineticScrollerPrivate::timerEvent(QTimerEvent *e) if (state == te->state) { (this->*te->handler)(); - if (debugHook) - debugHook(debugHookUser, releaseVelocity, q->contentPosition(), overshootPosition); return; } } @@ -542,7 +538,10 @@ QPointF QKineticScrollerPrivate::calculateVelocity(qreal time) // -- x coordinate if (overshootX) { - velocity.setX(overshootVelocity.x() * qCos(overshootSpringConstantRoot * (time - overshootStartTimeX))); + if (overshootSpringConstantRoot * (time-overshootStartTimeX) < M_PI) // prevent swinging around + velocity.setX(overshootVelocity.x() * qCos(overshootSpringConstantRoot * (time - overshootStartTimeX))); + else + velocity.setX(-overshootVelocity.x()); } else { qreal newVelocity = decelerate(releaseVelocity.x(), time); @@ -561,7 +560,10 @@ QPointF QKineticScrollerPrivate::calculateVelocity(qreal time) // -- y coordinate if (overshootY) { - velocity.setY(overshootVelocity.y() * qCos(overshootSpringConstantRoot * (time - overshootStartTimeY))); + if (overshootSpringConstantRoot * (time-overshootStartTimeY) < M_PI) // prevent swinging around + velocity.setY(overshootVelocity.y() * qCos(overshootSpringConstantRoot * (time - overshootStartTimeY))); + else + velocity.setY(-overshootVelocity.y()); } else { qreal newVelocity = decelerate(releaseVelocity.y(), time); @@ -1069,6 +1071,16 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) if (!oldOvershootX) { overshootStartTimeX = qreal(scrollAbsoluteTimer.elapsed()) / 1000; overshootVelocity.setX(calculateVelocity(overshootStartTimeX).x()); + + // restrict the overshoot to overshootMaximumDistance + qreal maxOvershootVelocity = overshootMaximumDistance.x() * overshootSpringConstantRoot; + if (overshootMaximumDistance.x() && qAbs(overshootVelocity.x()) > maxOvershootVelocity) + overshootVelocity.setX(maxOvershootVelocity * qSign(newOvershootX)); + + // -- prevent going into overshoot too far + if (state != QKineticScroller::StateDragging && overshootDragResistanceFactor) + newOvershootX = qSign(newOvershootX) * qreal(0.0001); + scrollToX = false; overshootX = true; } @@ -1092,6 +1104,16 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) if (!oldOvershootY) { overshootStartTimeY = qreal(scrollAbsoluteTimer.elapsed()) / 1000; overshootVelocity.setY(calculateVelocity(overshootStartTimeY).y()); + + // -- restrict the overshoot to overshootMaximumDistance + qreal maxOvershootVelocity = overshootMaximumDistance.y() * overshootSpringConstantRoot; + if (overshootMaximumDistance.y() && (qAbs(overshootVelocity.y()) > maxOvershootVelocity)) + overshootVelocity.setY(maxOvershootVelocity * qSign(newOvershootY)); + + // -- prevent going into overshoot too far + if (state != QKineticScroller::StateDragging && overshootDragResistanceFactor) + newOvershootY = qSign(newOvershootY) * qreal(0.0001); + scrollToY = false; overshootY = true; } @@ -1115,6 +1137,9 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) q->setContentPosition(newClampedPos, realOvershootDistance); + if (debugHook) + debugHook(debugHookUser, calculateVelocity(qreal(scrollAbsoluteTimer.elapsed()) / 1000), newClampedPos, realOvershootDistance); + qDebug() << "setContentPositionHelper" << newClampedPos << " overshoot:" << realOvershootDistance << "Overshoot: "<<overshootX<<","<<overshootY<<"ScrollTo:"<<scrollToX<<","<<scrollToY; } |
