From 4010a59ca9e71f85b683f7b389dd60915f99fad1 Mon Sep 17 00:00:00 2001 From: Ralf Engels Date: Tue, 13 Apr 2010 18:12:12 +0200 Subject: Fix all remaining issues. Pending: scrollTo is still using a very high speed when scrolling just a small distance. cleanup --- main.cpp | 2 +- qkineticscroller.cpp | 48 +++++++++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/main.cpp b/main.cpp index a1b1155..4b243fc 100644 --- a/main.cpp +++ b/main.cpp @@ -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:"<setContentPosition(newClampedPos, realOvershootDistance); - overshootPosition = newPos - newClampedPos; qDebug() << "setContentPositionHelper" << newClampedPos << " overshoot:" << realOvershootDistance; } -- cgit v1.2.3