diff options
author | Robert Griebl <rgriebl@trolltech.com> | 2010-04-01 18:00:23 +0200 |
---|---|---|
committer | Robert Griebl <rgriebl@trolltech.com> | 2010-04-01 18:00:23 +0200 |
commit | fb9250499bf31f52c5ce3082dc8f6fdc8c5ad622 (patch) | |
tree | a5f64069ec147606a47d5c2f01e4b7a2f0ece4ef | |
parent | f5cd7a76c3b73616afbd6d79bf5eff522ceb24c5 (diff) |
added overshoot resistance
-rw-r--r-- | qkineticscroller.cpp | 31 | ||||
-rw-r--r-- | qkineticscroller.h | 1 | ||||
-rw-r--r-- | qkineticscroller_p.h | 1 |
3 files changed, 28 insertions, 5 deletions
diff --git a/qkineticscroller.cpp b/qkineticscroller.cpp index 005abb8..46d1bc8 100644 --- a/qkineticscroller.cpp +++ b/qkineticscroller.cpp @@ -172,6 +172,7 @@ void QKineticScroller::resetScrollMetrics() metrics.insert(DragVelocitySmoothingFactor, qreal(0.15)); metrics.insert(FrictionCoefficent, qreal(0.85)); metrics.insert(OvershootSpringConstant, qreal(0.1)); + metrics.insert(OvershootDragResistanceFactor, qreal(1)); metrics.insert(OvershootMaximumDistance, QPointF(qreal(150), qreal(150))); metrics.insert(OvershootMaximumVelocity, qreal(2600)); metrics.insert(DragStartDistance, qreal(25)); @@ -188,8 +189,9 @@ void QKineticScroller::resetScrollMetrics() #else metrics.insert(DragVelocitySmoothingFactor, qreal(0.02)); metrics.insert(FrictionCoefficent, qreal(0.05)); - metrics.insert(OvershootSpringConstant, qreal(2.0)); - metrics.insert(OvershootMaximumDistance, QPointF(qreal(14.25 / 1000), qreal(14.25 / 1000))); + metrics.insert(OvershootSpringConstant, qreal(15.0)); + metrics.insert(OvershootDragResistanceFactor, qreal(0.5)); + metrics.insert(OvershootMaximumDistance, QPointF(0,0)); // QPointF(qreal(14.25 / 1000), qreal(14.25 / 1000))); metrics.insert(OvershootMaximumVelocity, qreal(247.0 / 1000)); metrics.insert(DragStartDistance, qreal(2.5 / 1000)); metrics.insert(DragStartDirectionErrorMargin, qreal(1.0 / 1000)); @@ -268,7 +270,7 @@ void QKineticScrollerPrivate::timerEvent(QTimerEvent *e) return; } } - + if (timerId) { qWarning() << "Unhandled timer event, while in state " << stateName(state); killTimer(timerId); @@ -361,6 +363,7 @@ QVariant QKineticScroller::scrollMetric(ScrollMetric metric) const case DragVelocitySmoothingFactor: return d->dragVelocitySmoothingFactor; case FrictionCoefficent: return d->frictionCoefficent; case OvershootSpringConstant: return d->overshootSpringConstant; + case OvershootDragResistanceFactor: return d->overshootDragResistanceFactor; case OvershootMaximumDistance: return d->overshootMaximumDistance; case DragStartDistance: return d->dragStartDistance; case DragStartDirectionErrorMargin: return d->dragStartDirectionErrorMargin; @@ -388,6 +391,7 @@ void QKineticScroller::setScrollMetric(ScrollMetric metric, const QVariant &valu case DragVelocitySmoothingFactor: d->dragVelocitySmoothingFactor = qBound(qreal(0), value.toReal(), qreal(1)); break; case FrictionCoefficent: d->frictionCoefficent = qBound(qreal(0), value.toReal(), qreal(1)); break; case OvershootSpringConstant: d->overshootSpringConstant = value.toReal(); break; + case OvershootDragResistanceFactor: d->overshootDragResistanceFactor = value.toReal(); break; case OvershootMaximumDistance: d->overshootMaximumDistance = value.toPointF(); break; case DragStartDistance: d->dragStartDistance = value.toReal(); break; case DragStartDirectionErrorMargin: d->dragStartDirectionErrorMargin = value.toReal(); break; @@ -704,7 +708,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time) // -- move (convert from [m/s] to [pix/frame] setContentPositionHelper(q->contentPosition() + overshootDistance + velocity * qreal(time) / 1000 * pixelPerMeter); - + // --- (de)accelerate overshooting axis using spring constant or friction // actually we would need to calculate a root and not just divide qreal forcePerFrame = overshootSpringConstant * qreal(time) / 1000; @@ -773,6 +777,15 @@ void QKineticScrollerPrivate::setState(QKineticScroller::State newstate) qWarning() << "Switching to state " << stateName(newstate); + switch (state) { + case QKineticScroller::StateDragging: + overshootDistance *= overshootDragResistanceFactor; + break; + default: + break; + } + + switch (newstate) { case QKineticScroller::StateInactive: if (state == QKineticScroller::StateScrolling) { @@ -936,7 +949,15 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &pos) } qKSDebug() << "setPosition raw: " << pos << ", clamped: " << clampedPos << ", overshoot: " << overshootDistance; - q->setContentPosition(clampedPos, overshootPolicy == QKineticScroller::OvershootAlwaysOff ? QPointF() : overshootDistance); + + QPointF realOvershootDistance; + if (overshootPolicy != QKineticScroller::OvershootAlwaysOff) { + realOvershootDistance = overshootDistance; + if (state == QKineticScroller::StateDragging) + realOvershootDistance *= overshootDragResistanceFactor; + } + + q->setContentPosition(clampedPos, realOvershootDistance); } diff --git a/qkineticscroller.h b/qkineticscroller.h index 8e9336c..3429d79 100644 --- a/qkineticscroller.h +++ b/qkineticscroller.h @@ -89,6 +89,7 @@ public: DragVelocitySmoothingFactor, // qreal [0..1/s] (complex calculation involving time) v = v_new* DASF + v_old * (1-DASF) FrictionCoefficent, // qreal [0..1] OvershootSpringConstant, // qreal [0..1] + OvershootDragResistanceFactor, // qreal [0..1] OvershootMaximumDistance, // QPointF([m], [m]) OvershootMaximumVelocity, // qreal [m/s] diff --git a/qkineticscroller_p.h b/qkineticscroller_p.h index d2012de..14188ce 100644 --- a/qkineticscroller_p.h +++ b/qkineticscroller_p.h @@ -94,6 +94,7 @@ public: qreal dragVelocitySmoothingFactor; qreal frictionCoefficent; qreal overshootSpringConstant; + qreal overshootDragResistanceFactor; QPointF overshootMaximumDistance; qreal overshootMaximumVelocity; qreal dragStartDistance; |