diff options
author | Robert Griebl <rgriebl@trolltech.com> | 2010-04-01 14:55:38 +0200 |
---|---|---|
committer | Robert Griebl <rgriebl@trolltech.com> | 2010-04-01 14:55:38 +0200 |
commit | 8eac27d4c572d1f23ad067ed8fa398488e24733b (patch) | |
tree | 81e8a2479b4917f6365c2dbef9b44a2ad9e023a4 | |
parent | 8510c889269c61e5afd008ad68cd7d1632bee786 (diff) |
another round of dpi fixes
-rw-r--r-- | qkineticscroller.cpp | 48 | ||||
-rw-r--r-- | qkineticscroller.h | 2 | ||||
-rw-r--r-- | qkineticscroller_p.h | 2 |
3 files changed, 27 insertions, 25 deletions
diff --git a/qkineticscroller.cpp b/qkineticscroller.cpp index d20b2c2..ec46f08 100644 --- a/qkineticscroller.cpp +++ b/qkineticscroller.cpp @@ -190,16 +190,16 @@ void QKineticScroller::resetScrollMetrics() metrics.insert(FrictionCoefficent, qreal(0.95)); metrics.insert(OvershootSpringConstant, qreal(0.1)); metrics.insert(OvershootMaximumDistance, qreal(14.25 / 1000)); - metrics.insert(OvershootMaximumVelocity, qreal(247 / 1000)); - metrics.insert(DragStartDistance, qreal(25)); //TODO - metrics.insert(DragStartDirectionErrorMargin, qreal(10)); //TODO - metrics.insert(MaximumVelocity, qreal(6650 / 1000)); - metrics.insert(MinimumVelocity, qreal(19 / 1000)); - metrics.insert(MaximumNonAcceleratedVelocity, qreal(532 / 1000)); + metrics.insert(OvershootMaximumVelocity, qreal(247.0 / 1000)); + metrics.insert(DragStartDistance, qreal(2.5 / 1000)); + metrics.insert(DragStartDirectionErrorMargin, qreal(1.0 / 1000)); + metrics.insert(MaximumVelocity, qreal(6650.0 / 1000)); + metrics.insert(MinimumVelocity, qreal(19.0 / 1000)); + metrics.insert(MaximumNonAcceleratedVelocity, qreal(532.0 / 1000)); metrics.insert(MaximumClickThroughVelocity, qreal(66.5 / 1000)); metrics.insert(AxisLockThreshold, qreal(0)); metrics.insert(FastSwipeBaseVelocity, qreal(51.3 / 1000)); - metrics.insert(FastSwipeMinimumVelocity, qreal(76 / 1000)); + metrics.insert(FastSwipeMinimumVelocity, qreal(76.0 / 1000)); metrics.insert(FastSwipeMaximumTime, qreal(0.125)); metrics.insert(FramesPerSecond, qreal(60)); #endif @@ -395,7 +395,7 @@ void QKineticScroller::setScrollMetric(ScrollMetric metric, const QVariant &valu case AxisLockThreshold: d->axisLockThreshold = qBound(qreal(0), value.toReal(), qreal(1)); break; case FramesPerSecond: d->framesPerSecond = qBound(1, value.toInt(), 100); break; case OvershootMaximumVelocity: d->overshootMaximumVelocity = value.toReal(); break; - case FastSwipeMaximumTime: d->fastSwipeMaximumTime = value.toInt(); break; + case FastSwipeMaximumTime: d->fastSwipeMaximumTime = value.toReal(); break; case FastSwipeMinimumVelocity: d->fastSwipeMinimumVelocity = value.toReal(); break; case FastSwipeBaseVelocity: d->fastSwipeBaseVelocity = value.toReal(); break; case ScrollMetricCount: break; @@ -436,11 +436,12 @@ void QKineticScrollerPrivate::updateVelocity(const QPointF &deltaPixelRaw, qint6 qKSDebug() << "updateVelocity(dP = " << deltaPixelRaw << " [pix], dT = " << deltaTime << " [ms]) -- velocity: " << velocity << "[m/s]"; QPointF deltaPixel = deltaPixelRaw; - // faster than 25 pix / ms seems bogus (that's a screen height in ~20 ms) - if ((deltaPixelRaw / qreal(deltaTime)).manhattanLength() > 25) //TODO: convert to mm - deltaPixel = deltaPixelRaw * qreal(25) / (deltaPixelRaw / qreal(deltaTime)).manhattanLength(); - QPointF newv = -deltaPixel / qreal(deltaTime) * qreal(1000) / pixelPerMeter; + // faster than 2.5mm/ms seems bogus (that would be a screen height in ~20 ms) + if (((deltaPixelRaw / qreal(deltaTime)).manhattanLength() / pixelPerMeter * 1000) > qreal(2.5)) + deltaPixel = deltaPixelRaw * qreal(2.5) * pixelPerMeter / 1000 / (deltaPixelRaw / qreal(deltaTime)).manhattanLength(); + + QPointF newv = -deltaPixel / qreal(deltaTime) * 1000 / pixelPerMeter; newv = newv * dragVelocitySmoothingFactor + velocity * (qreal(1) - dragVelocitySmoothingFactor); if (deltaPixel.x()) @@ -558,10 +559,11 @@ bool QKineticScrollerPrivate::moveWhilePressed(QKineticScroller::Input, const QP QPointF deltaPixel = position - pressPosition; - bool moveStarted = (deltaPixel.manhattanLength() > dragStartDistance); + bool moveStarted = ((deltaPixel.manhattanLength() / pixelPerMeter) > dragStartDistance); if (moveStarted) { qreal deltaXtoY = qAbs(pressPosition.x() - position.x()) - qAbs(pressPosition.y() - position.y()); + deltaXtoY /= pixelPerMeter; QPointF maxPos = q->maximumContentPosition(); bool canScrollX = (maxPos.x() > 0); @@ -625,7 +627,7 @@ bool QKineticScrollerPrivate::releaseWhileDragging(QKineticScroller::Input, cons fastSwipeVelocity.setY(qMin(maximumVelocity, maxPos.y() / size.height() * fastSwipeBaseVelocity)); if (fastSwipeMaximumTime && - ((timestamp - pressTimestamp) < fastSwipeMaximumTime) && + ((timestamp - pressTimestamp) < qint64(fastSwipeMaximumTime * 1000)) && (oldVelocity > fastSwipeMinimumVelocity)) { // more than one fast swipe in a row: add fastSwipeVelocity @@ -667,7 +669,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time) // --- handle overshooting and stop if the coordinate is going back inside the normal area if (!overshootDistance.isNull()) { // calculate the new overshoot distance (convert from [m/s] to [pixel/frame] - QPointF newOvershootDistance = overshootDistance + velocity * qreal(time) / qreal(1000) * pixelPerMeter; + QPointF newOvershootDistance = overshootDistance + velocity * qreal(time) / 1000 * pixelPerMeter; // -- check if we going back. Then stop if (overshootDistance.x() && ((overshootDistance.x() > 0) != (newOvershootDistance.x() > 0))) { @@ -683,11 +685,11 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time) } // -- move (convert from [m/s] to [pix/frame] - setContentPositionHelper(q->contentPosition() - overshootDistance + velocity * qreal(time) / qreal(1000) * pixelPerMeter); + setContentPositionHelper(q->contentPosition() - overshootDistance + velocity * qreal(time) / 1000 * pixelPerMeter); // --- (de)accelerate overshooting axis using spring constant or friction - qreal forcePerFrame = overshootSpringConstant * qreal(time) / qreal(1000); - qreal frictionPerFrame = (qreal(1) - ((qreal(1) - frictionCoefficent) * qreal(time) / qreal(1000))); + qreal forcePerFrame = overshootSpringConstant * qreal(time) / 1000; + qreal frictionPerFrame = (qreal(1) - ((qreal(1) - frictionCoefficent) * qreal(time) / 1000)); qWarning() << "frictionPerFrame: " << frictionPerFrame; @@ -697,7 +699,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time) velocity.setX(qBound(-overshootMaximumVelocity, velocity.x(), overshootMaximumVelocity)); } else if (scrollToX) { - if (qAbs(velocity.x()) >= (qreal(30) / pixelPerMeter)) + if (qAbs(velocity.x()) >= qreal(3.0 / 1000 /* 3mm/s */)) velocity.rx() *= frictionPerFrame; // - target reached? @@ -717,7 +719,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time) velocity.setY(qBound(-overshootMaximumVelocity, velocity.y(), overshootMaximumVelocity)); } else if (scrollToY) { - if (qAbs(velocity.y()) >= (qreal(30) / pixelPerMeter)) + if (qAbs(velocity.y()) >= qreal(3.0 / 1000 /* 3mm/s */)) velocity.ry() *= frictionPerFrame; // - target reached? @@ -731,7 +733,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time) velocity.ry() *= frictionPerFrame; } - if (overshootDistance.isNull() && velocity <= (qreal(20) / pixelPerMeter) && !scrollToX && !scrollToY) + if (overshootDistance.isNull() && (velocity <= qreal(2.0 / 1000 /* 2mm/s */)) && !scrollToX && !scrollToY) setState(QKineticScroller::StateInactive); } @@ -813,7 +815,7 @@ void QKineticScroller::scrollTo(const QPointF &pos, int scrollTime) // --- calculate the initial velocity to get to the point // -- calc the number of steps we have: - int steps = scrollTime * d->framesPerSecond / qreal(1000); + int steps = scrollTime * d->framesPerSecond / 1000; // -- calc the distance we will move with a starting velocity of 1.0 qreal dist = qreal(0); @@ -827,7 +829,7 @@ void QKineticScroller::scrollTo(const QPointF &pos, int scrollTime) d->scrollToPosition = pos; d->scrollToX = true; d->scrollToY = true; - d->velocity = (pos - contentPosition()) / dist / d->framesPerSecond * qreal(1000) / d->pixelPerMeter; + d->velocity = (pos - contentPosition()) / dist / d->framesPerSecond * 1000 / d->pixelPerMeter; d->setState(QKineticScroller::StateScrolling); } diff --git a/qkineticscroller.h b/qkineticscroller.h index 16f8214..34fb175 100644 --- a/qkineticscroller.h +++ b/qkineticscroller.h @@ -104,7 +104,7 @@ public: FramesPerSecond, // int [frames/s] - FastSwipeMaximumTime, // int [s] + FastSwipeMaximumTime, // qreal [s] FastSwipeMinimumVelocity, // qreal [m/s] FastSwipeBaseVelocity, // qreal [m/s] diff --git a/qkineticscroller_p.h b/qkineticscroller_p.h index 2c0bede..d2012de 100644 --- a/qkineticscroller_p.h +++ b/qkineticscroller_p.h @@ -105,7 +105,7 @@ public: qreal axisLockThreshold; qreal fastSwipeBaseVelocity; qreal fastSwipeMinimumVelocity; - int fastSwipeMaximumTime; + qreal fastSwipeMaximumTime; int framesPerSecond; // state |