diff options
author | Ralf Engels <ralf.engels@nokia.com> | 2010-04-13 18:12:12 +0200 |
---|---|---|
committer | Ralf Engels <ralf.engels@nokia.com> | 2010-04-13 18:12:12 +0200 |
commit | 4010a59ca9e71f85b683f7b389dd60915f99fad1 (patch) | |
tree | b20e1464d125fcf8f7450397fbb04992bff4e0e2 | |
parent | c67b439d2cc7b49b79bf664204bf8ccc2a654951 (diff) |
Fix all remaining issues.
Pending:
scrollTo is still using a very high speed when scrolling just a small distance.
cleanup
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | qkineticscroller.cpp | 48 |
2 files changed, 32 insertions, 18 deletions
@@ -14,7 +14,7 @@ int main(int argc, char **argv) s->setWidget(lw); lw->show(); - s->scrollTo(QPointF(80,300)); + s->scrollTo(QPointF(80,3000)); return a.exec(); } diff --git a/qkineticscroller.cpp b/qkineticscroller.cpp index eb6d0e9..704205e 100644 --- a/qkineticscroller.cpp +++ b/qkineticscroller.cpp @@ -692,6 +692,7 @@ bool QKineticScrollerPrivate::moveWhileDragging(QKineticScroller::Input, const Q void QKineticScrollerPrivate::timerEventWhileDragging() { if (!dragDistance.isNull()) { + qDebug() << "timerEventWhileDragging" << dragDistance; setContentPositionHelper(-dragDistance); dragDistance = QPointF(0, 0); } @@ -759,11 +760,14 @@ void QKineticScrollerPrivate::timerEventWhileScrolling() QPointF deltaPos = newVelocity * deltaTime * pixelPerMeter; // -- move (convert from [m/s] to [pix/frame] - setContentPositionHelper(deltaPos); + if (!deltaPos.isNull()) + setContentPositionHelper(deltaPos); qWarning() << "DeltaPos: " << deltaPos << " - newVel: " << newVelocity << " - Time: " << time << " - PPM: " << pixelPerMeter; - if (newVelocity.isNull()) + if (newVelocity.isNull() || + (releaseVelocity.isNull() && !scrollToX && !scrollToY && !overshootX && !overshootY)) + // if (newVelocity.isNull()) setState(QKineticScroller::StateInactive); } @@ -782,14 +786,6 @@ void QKineticScrollerPrivate::setState(QKineticScroller::State newstate) qWarning() << "Switching to state " << stateName(newstate); - switch (state) { - case QKineticScroller::StateDragging: - break; - default: - break; - } - - switch (newstate) { case QKineticScroller::StateInactive: if (state == QKineticScroller::StateScrolling) { @@ -815,6 +811,7 @@ void QKineticScrollerPrivate::setState(QKineticScroller::State newstate) break; case QKineticScroller::StateDragging: + dragDistance = QPointF(0, 0); if (state == QKineticScroller::StatePressed) { if (!timerId) { @@ -823,6 +820,9 @@ void QKineticScrollerPrivate::setState(QKineticScroller::State newstate) qWarning() << "State change from " << stateName(state) << " to " << stateName(newstate) << ", but timer is already active."; } } + + overshootPosition /= overshootDragResistanceFactor; + break; case QKineticScroller::StateScrolling: @@ -836,7 +836,7 @@ void QKineticScrollerPrivate::setState(QKineticScroller::State newstate) overshootPosition *= overshootDragResistanceFactor; overshootStartTimeX = overshootStartTimeY = qreal(scrollAbsoluteTimer.elapsed()) / 1000 - M_PI / (overshootSpringConstantRoot * 2); - overshootVelocity = overshootPosition * overshootSpringConstantRoot; + overshootVelocity = overshootPosition / pixelPerMeter * overshootSpringConstantRoot; } break; @@ -950,9 +950,17 @@ void QKineticScroller::ensureVisible(const QPointF &pos, int xmargin, int ymargi } -/* - Decomposes the position into a scroll and an overshoot part. - Also keeps track of the current over-shooting value in overshootDist. +/*! \internal + Helps when setting the content position. + It will try to move the content by the requested delta but stop in case + when we are coming back from an overshoot or a scrollTo. + It will also indicate a new overshooting condition by the overshootX and oversthootY flags. + + In this cases it will reset the velocity variables and other flags. + + Also keeps track of the current over-shooting value in overshootPosition. + + \deltaPos is the amout of pixels the current content position should be moved */ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) { @@ -962,6 +970,8 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) QPointF newPos = oldPos + deltaPos; QPointF maxPos = q->maximumContentPosition(); + qDebug() << "setContentPositionHelper overshoot:"<<overshootPosition<<"delta:"<<deltaPos<<"old:" << oldPos << " new:" << newPos; + QPointF oldClampedPos; oldClampedPos.setX(qBound(qreal(0), oldPos.x(), maxPos.x())); oldClampedPos.setY(qBound(qreal(0), oldPos.y(), maxPos.y())); @@ -994,6 +1004,7 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) newClampedPos.setX((oldOvershootX < 0) ? 0 : maxPos.x()); realOvershootDistance.setX(0); releaseVelocity.setX(0); + overshootVelocity.setX(0); overshootX = false; } else if (newOvershootX) { @@ -1006,8 +1017,9 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) realOvershootDistance.setX(newOvershootX); } else if (scrollToX && qSign(oldScrollToDist.x()) != qSign(newScrollToDist.x())) { - scrollToX = false; newClampedPos.setX(scrollToPosition.x()); + releaseVelocity.setX(0); + scrollToX = false; } // -- y axis @@ -1015,6 +1027,7 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) newClampedPos.setY((oldOvershootY < 0) ? 0 : maxPos.y()); realOvershootDistance.setY(0); releaseVelocity.setY(0); + overshootVelocity.setY(0); overshootY = false; } else if (newOvershootY) { @@ -1027,10 +1040,12 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) realOvershootDistance.setY(newOvershootY); } else if (scrollToY && qSign(oldScrollToDist.y()) != qSign(newScrollToDist.y())) { - scrollToY = false; newClampedPos.setY(scrollToPosition.y()); + releaseVelocity.setY(0); + scrollToY = false; } + overshootPosition = realOvershootDistance; // -- finishing overshoot distance if (!realOvershootDistance.isNull()) { @@ -1046,7 +1061,6 @@ void QKineticScrollerPrivate::setContentPositionHelper(const QPointF &deltaPos) } q->setContentPosition(newClampedPos, realOvershootDistance); - overshootPosition = newPos - newClampedPos; qDebug() << "setContentPositionHelper" << newClampedPos << " overshoot:" << realOvershootDistance; } |