summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Griebl <rgriebl@trolltech.com>2010-03-30 18:52:04 +0200
committerRobert Griebl <rgriebl@trolltech.com>2010-03-30 18:52:04 +0200
commit74df29aa6dd91e9640d87d313e3948134bb67259 (patch)
tree5928fd71325d4523de64484e44657b2c78a3eebe
parent2c7d7a4efec6f44494e3315fdd6c36d41100bcb0 (diff)
make it compile again
-rw-r--r--qkineticscroller.cpp110
-rw-r--r--qkineticscroller.h2
-rw-r--r--qkineticscroller_p.h8
3 files changed, 67 insertions, 53 deletions
diff --git a/qkineticscroller.cpp b/qkineticscroller.cpp
index f987291..b3f5351 100644
--- a/qkineticscroller.cpp
+++ b/qkineticscroller.cpp
@@ -267,6 +267,10 @@ QVariant QKineticScroller::scrollMetric(ScrollMetric metric) const
case MaximumClickThroughVelocity: return d->maximumClickThroughVelocity;
case AxisLockThreshold: return d->axisLockThreshold;
case FramesPerSecond: return d->framesPerSecond;
+ case OvershootMaximumVelocity: return d->overshootMaximumVelocity;
+ case FastSwipeMaximumTime: return d->fastSwipeMaximumTime;
+ case FastSwipeMinimumVelocity: return d->fastSwipeMinimumVelocity;
+ case FastSwipeBaseVelocity: return d->fastSwipeBaseVelocity;
}
return QVariant();
}
@@ -290,24 +294,28 @@ void QKineticScroller::setScrollMetric(ScrollMetric metric, const QVariant &valu
case MaximumClickThroughVelocity: d->maximumClickThroughVelocity = value.toReal(); break;
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 FastSwipeMinimumVelocity: d->fastSwipeMinimumVelocity = value.toReal(); break;
+ case FastSwipeBaseVelocity: d->fastSwipeBaseVelocity = value.toReal(); break;
}
}
-void QKineticScrollerPrivate::updateVelocity(const QPointF &dPixel, int dTime)
+void QKineticScrollerPrivate::updateVelocity(const QPointF &deltaPixel, qint64 deltaTime)
{
- qKSDebug() << "updateVelocity(dP = " << dPixel << ", dT = " << dTime << ") -- velocity: " << velocity;
+ qKSDebug() << "updateVelocity(dP = " << deltaPixel << ", dT = " << deltaTime << ") -- velocity: " << velocity;
QPointF newv = velocity;
// faster than 25 pix / ms seems bogus (that's a screen height in ~20 ms)
- if ((dPixel / qreal(dTime)).manhattanLength() < 25) {
- QPointF rawv = - dPixel / qreal(dTime) * qreal(1000);
+ if ((deltaPixel / qreal(deltaTime)).manhattanLength() < 25) {
+ QPointF rawv = - deltaPixel / qreal(deltaTime) * qreal(1000);
newv = velocity * (qreal(1) - dragVelocitySmoothingFactor) + rawv * dragVelocitySmoothingFactor;
}
- newv.setX(dPixel.x() ? qBound(-maximumVelocity, newv.x(), maximumVelocity) : velocity.x());
- newv.setY(dPixel.y() ? qBound(-maximumVelocity, newv.y(), maximumVelocity) : velocity.y());
+ newv.setX(deltaPixel.x() ? qBound(-maximumVelocity, newv.x(), maximumVelocity) : velocity.x());
+ newv.setY(deltaPixel.y() ? qBound(-maximumVelocity, newv.y(), maximumVelocity) : velocity.y());
velocity = newv;
}
@@ -369,34 +377,29 @@ void QKineticScrollerPrivate::handleDrag(const QPointF &position, qint64 timesta
}
-bool operator<=(const QPointF &p, qreal f)
+inline bool operator<=(const QPointF &p, qreal f)
{
return (qAbs(p.x()) <= f) && (qAbs(p.y()) <= f);
}
-bool operator<(const QPointF &p, qreal f)
+inline bool operator<(const QPointF &p, qreal f)
{
return (qAbs(p.x()) < f) && (qAbs(p.y()) < f);
}
-bool operator>=(const QPointF &p, qreal f)
+inline bool operator>=(const QPointF &p, qreal f)
{
return (qAbs(p.x()) >= f) || (qAbs(p.y()) >= f);
}
-bool operator>(const QPointF &p, qreal f)
+inline bool operator>(const QPointF &p, qreal f)
{
return (qAbs(p.x()) > f) || (qAbs(p.y()) > f);
}
-QPointF qAbs(const QPointF &p)
+inline QPointF qAbs(const QPointF &p)
{
return QPointF(qAbs(p.x()), qAbs(p.y()));
}
-QPointF qSign(const QPointF &p)
-{
- return QPointF(p.x() < 0 ? -1 : p.x() > 0 ? 1 : 0,
- p.y() < 0 ? -1 : p.y() > 0 ? 1 : 0);
-}
@@ -414,7 +417,7 @@ bool QKineticScrollerPrivate::pressWhileInactive(QKineticScroller::Input, const
return false;
}
-bool QKineticScrollerPrivate::releaseWhilePressed(QKineticScroller::Input, const QPointF &position, qint64 timestamp)
+bool QKineticScrollerPrivate::releaseWhilePressed(QKineticScroller::Input, const QPointF &, qint64)
{
setState(QKineticScroller::StateInactive);
return false;
@@ -469,7 +472,7 @@ bool QKineticScrollerPrivate::moveWhileDragging(QKineticScroller::Input, const Q
return true;
}
-void QKineticScrollerPrivate::timerEventWhileDragging(qint64 timestamp)
+void QKineticScrollerPrivate::timerEventWhileDragging(qint64)
{
Q_Q(QKineticScroller);
@@ -479,7 +482,7 @@ void QKineticScrollerPrivate::timerEventWhileDragging(qint64 timestamp)
}
}
-bool QKineticScrollerPrivate::releaseWhileDragging(QKineticScroller::Input, const QPointF &position, qint64 timestamp)
+bool QKineticScrollerPrivate::releaseWhileDragging(QKineticScroller::Input, const QPointF &, qint64 timestamp)
{
Q_Q(QKineticScroller);
@@ -488,26 +491,33 @@ bool QKineticScrollerPrivate::releaseWhileDragging(QKineticScroller::Input, cons
QPointF fastSwipeVelocity = QPoint(0, 0);
QSizeF size = q->viewportSize();
if (size.width())
- fastSwipeVelocity.setX(qMin(int(q->maximumVelocity()), maxPos.x() / size.width() * fastSwipeBaseVelocity));
+ fastSwipeVelocity.setX(qMin(maximumVelocity, maxPos.x() / size.width() * fastSwipeBaseVelocity));
if (size.height())
- fastSwipeVelocity.setY(qMin(int(q->maximumVelocity()), maxPos.y() / size.height() * fastSwipeBaseVelocity));
+ fastSwipeVelocity.setY(qMin(maximumVelocity, maxPos.y() / size.height() * fastSwipeBaseVelocity));
- if (fastSwipeMaximumTime
- && (timestamp - pressTimestamp) < fastSwipeMaximumTime
- && oldVelocity > fastSwipeMinimumVelocity) {
+ if (fastSwipeMaximumTime &&
+ ((timestamp - pressTimestamp) < fastSwipeMaximumTime) &&
+ (oldVelocity > fastSwipeMinimumVelocity)) {
// more than one fast swipe in a row: add fastSwipeVelocity
- velocity = qAbs(oldVelocity) + fastSwipeVelocity * qSign(velocity);
+ int signX = 0, signY = 0;
+ if (velocity.x())
+ signX = (velocity.x() > 0) == (oldVelocity.x() > 0) ? 1 : -1;
+ if (velocity.y())
+ signY = (velocity.y() > 0) == (oldVelocity.y() > 0) ? 1 : -1;
+
+ velocity.setX(signX * (oldVelocity.x() + (oldVelocity.x() > 0 ? fastSwipeVelocity.x() : -fastSwipeVelocity.x())));
+ velocity.setY(signY * (oldVelocity.y() + (oldVelocity.y() > 0 ? fastSwipeVelocity.y() : -fastSwipeVelocity.y())));
} else if (velocity >= minimumVelocity) {
// if we have a fast swipe, accelerate it to the fastSwipe velocity
if ((qAbs(velocity.x()) > maximumNonAcceleratedVelocity) &&
- (fastSwipeVelocity.x() > maximumNonAcceleratedVelocity)) {
+ (fastSwipeVelocity.x() > maximumNonAcceleratedVelocity)) {
velocity.setX(velocity.x() > 0 ? fastSwipeVelocity.x() : -fastSwipeVelocity.x());
}
if ((qAbs(velocity.y()) > maximumNonAcceleratedVelocity) &&
- (fastSwipeVelocity.y() > maximumNonAcceleratedVelocity)) {
+ (fastSwipeVelocity.y() > maximumNonAcceleratedVelocity)) {
velocity.setY(velocity.y() > 0 ? fastSwipeVelocity.y() : -fastSwipeVelocity.y());
}
@@ -553,7 +563,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time)
// -- x coordinate
if (overshootDistance.x()) {
velocity.rx() += forcePerFrame * overshootDistance.x();
- velocity.setX( qBound(-overshootMaximumVelocity, velocity.x(), overshootMaximumVelocity));
+ velocity.setX(qBound(-overshootMaximumVelocity, velocity.x(), overshootMaximumVelocity));
} else if (scrollToX) {
if (qAbs(velocity.x()) >= qreal(30))
@@ -561,7 +571,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time)
// - target reached?
qreal dist = scrollToPosition.x() - q->contentPosition().x();
- if ((velocity.x() > 0.0 && dist <= 0.0) || (velocity.x() < 0.0 && dist >= 0.0) ) {
+ if ((velocity.x() > 0.0 && dist <= 0.0) || (velocity.x() < 0.0 && dist >= 0.0)) {
velocity.setX(0.0);
scrollToX = false;
}
@@ -573,7 +583,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time)
// -- y coordinate
if (overshootDistance.y()) {
velocity.ry() += forcePerFrame * overshootDistance.y();
- velocity.setY( qBound(-overshootMaximumVelocity, velocity.y(), overshootMaximumVelocity));
+ velocity.setY(qBound(-overshootMaximumVelocity, velocity.y(), overshootMaximumVelocity));
} else if (scrollToY) {
if (qAbs(velocity.y()) >= qreal(30))
@@ -581,7 +591,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time)
// - target reached?
qreal dist = scrollToPosition.y() - q->contentPosition().y();
- if ((velocity.y() > 0.0 && dist <= 0.0) || (velocity.y() < 0.0 && dist >= 0.0) ) {
+ if ((velocity.y() > 0.0 && dist <= 0.0) || (velocity.y() < 0.0 && dist >= 0.0)) {
velocity.setY(0.0);
scrollToY = false;
}
@@ -594,7 +604,7 @@ void QKineticScrollerPrivate::timerEventWhileScrolling(qint64 time)
setState(QKineticScroller::StateInactive);
}
-bool QKineticScrollerPrivate::pressWhileScrolling(QKineticScroller::Input, const QPointF &position, qint64 timestamp)
+bool QKineticScrollerPrivate::pressWhileScrolling(QKineticScroller::Input, const QPointF &, qint64)
{
oldVelocity = velocity;
@@ -609,35 +619,35 @@ void QKineticScrollerPrivate::setState(QKineticScroller::State newstate)
if (state == newstate)
return;
- switch (state) {
- case QKineticScroller::StatePressed:
- if (newstate == QKineticScroller::StateDragging) {
- if (!timerId) {
- timerId = startTimer(1000 / framesPerSecond);
- } else {
- qWarning() << "State change from " << stateName(state) << " to " << stateName(newstate) << ", but timer is already activate.";
- }
- }
- break;
- case QKineticScroller::StateScrolling:
- if (newstate == QKineticScroller::StateInactive) {
+ switch (newstate) {
+ case QKineticScroller::StateInactive:
+ if (state == QKineticScroller::StateScrolling) {
if (timerId) {
killTimer(timerId);
timerId = 0;
} else {
- qWarning() << "State change from " << stateName(state) << " to " << stateName(newstate) << ", but timer is not activate.";
+ qWarning() << "State change from " << stateName(state) << " to " << stateName(newstate) << ", but timer is not active.";
}
}
+ velocity = QPointF(0, 0);
break;
- }
- switch (newstate) {
- case QKineticScroller::StateInactive:
case QKineticScroller::StatePressed:
velocity = QPointF(0, 0);
break;
+
case QKineticScroller::StateDragging:
dragDistance = QPointF(0, 0);
+ if (state == QKineticScroller::StatePressed) {
+ if (!timerId) {
+ timerId = startTimer(1000 / framesPerSecond);
+ } else {
+ qWarning() << "State change from " << stateName(state) << " to " << stateName(newstate) << ", but timer is already active.";
+ }
+ }
+ break;
+
+ case QKineticScroller::StateScrolling:
break;
}
@@ -673,9 +683,9 @@ void QKineticScroller::scrollTo(const QPointF &pos, int scrollTime)
// -- calc the distance we will move with a starting velocity of 1.0
qreal dist = qreal(0);
qreal curVel = qreal(1);
- for (int i = 0; i<steps; i++) {
+ for (int i = 0; i < steps; i++) {
dist += curVel;
- curVel *= d->frictionCoefficient;
+ curVel *= d->frictionCoefficent;
}
// --- start the scrolling
diff --git a/qkineticscroller.h b/qkineticscroller.h
index ada0a29..21d68e4 100644
--- a/qkineticscroller.h
+++ b/qkineticscroller.h
@@ -112,7 +112,7 @@ public:
FastSwipeMaximumTime, // [s]
FastSwipeMinimumVelocity, // [m/s]
- FastSwipeAccelerationFactor, // [m/s^2]
+ FastSwipeBaseVelocity, // [m/s]
};
QVariant scrollMetric(ScrollMetric metric) const;
diff --git a/qkineticscroller_p.h b/qkineticscroller_p.h
index 9046962..c7214dd 100644
--- a/qkineticscroller_p.h
+++ b/qkineticscroller_p.h
@@ -79,10 +79,11 @@ public:
bool pressWhileScrolling(QKineticScroller::Input input, const QPointF &position, qint64 timestamp);
void timerEvent(QTimerEvent *);
- void timerEventWhileDragging(qint64 timestamp);
- void timerEventWhileScrolling(qint64 timestamp);
+ void timerEventWhileDragging(qint64 deltaTime);
+ void timerEventWhileScrolling(qint64 deltaTime);
void handleDrag(const QPointF &position, qint64 timestamp);
+ void updateVelocity(const QPointF &deltaPixel, qint64 deltaTime);
void setContentPositionHelper(const QPointF &position);
static const char *stateName(QKineticScroller::State state);
@@ -106,6 +107,9 @@ public:
qreal maximumClickThroughVelocity;
qreal axisLockThreshold;
int framesPerSecond;
+ qreal fastSwipeBaseVelocity;
+ qreal fastSwipeMinimumVelocity;
+ int fastSwipeMaximumTime;
QKineticScroller::OvershootPolicy overshootPolicy;