diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-02-26 07:44:46 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-02-26 07:44:46 (GMT) |
commit | 8b3fad1f7ac9bef0119fffc67feb5bb153abc647 (patch) | |
tree | b37edad1db7882f5123968b2764bea67ada3eaf4 /src | |
parent | 076f623967c08a462fb80eb5ad5dd8b96ea48127 (diff) | |
parent | 7aa4532c4ab517ce5c57d4cf2ee95f71928659b4 (diff) | |
download | Qt-8b3fad1f7ac9bef0119fffc67feb5bb153abc647.zip Qt-8b3fad1f7ac9bef0119fffc67feb5bb153abc647.tar.gz Qt-8b3fad1f7ac9bef0119fffc67feb5bb153abc647.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-qml
Diffstat (limited to 'src')
5 files changed, 71 insertions, 48 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 623398f..3f4a9ce 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -128,7 +128,7 @@ QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) , interactive(true), deceleration(500), maxVelocity(2000), reportedVelocitySmoothing(100) - , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0), fixupDuration(200) + , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0), fixupDuration(600) , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) , flickDirection(QDeclarativeFlickable::AutoFlickDirection) { @@ -148,6 +148,23 @@ void QDeclarativeFlickablePrivate::init() QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(widthChange())); } +/* + Returns the amount to overshoot by given a velocity. + Will be roughly in range 0 - size/4 +*/ +qreal QDeclarativeFlickablePrivate::overShootDistance(qreal velocity, qreal size) +{ + Q_Q(QDeclarativeFlickable); + if (maxVelocity <= 0) + return 0.0; + + velocity = qAbs(velocity); + if (velocity > maxVelocity) + velocity = maxVelocity; + qreal dist = size / 4 * velocity / maxVelocity; + return dist; +} + void QDeclarativeFlickablePrivate::flickX(qreal velocity) { Q_Q(QDeclarativeFlickable); @@ -156,12 +173,12 @@ void QDeclarativeFlickablePrivate::flickX(qreal velocity) if (velocity > 0) { const qreal minX = q->minXExtent(); if (_moveX.value() < minX) - maxDistance = qAbs(minX -_moveX.value() + (overShoot?30:0)); + maxDistance = qAbs(minX -_moveX.value() + (overShoot?overShootDistance(velocity,q->width()):0)); flickTargetX = minX; } else { const qreal maxX = q->maxXExtent(); if (_moveX.value() > maxX) - maxDistance = qAbs(maxX - _moveX.value()) + (overShoot?30:0); + maxDistance = qAbs(maxX - _moveX.value()) + (overShoot?overShootDistance(velocity,q->width()):0); flickTargetX = maxX; } if (maxDistance > 0) { @@ -194,12 +211,12 @@ void QDeclarativeFlickablePrivate::flickY(qreal velocity) if (velocity > 0) { const qreal minY = q->minYExtent(); if (_moveY.value() < minY) - maxDistance = qAbs(minY -_moveY.value() + (overShoot?30:0)); + maxDistance = qAbs(minY -_moveY.value() + (overShoot?overShootDistance(velocity,q->height()):0)); flickTargetY = minY; } else { const qreal maxY = q->maxYExtent(); if (_moveY.value() > maxY) - maxDistance = qAbs(maxY - _moveY.value()) + (overShoot?30:0); + maxDistance = qAbs(maxY - _moveY.value()) + (overShoot?overShootDistance(velocity,q->height()):0); flickTargetY = maxY; } if (maxDistance > 0) { @@ -233,18 +250,24 @@ void QDeclarativeFlickablePrivate::fixupX() if (_moveX.value() > q->minXExtent() || (q->maxXExtent() > q->minXExtent())) { timeline.reset(_moveX); if (_moveX.value() != q->minXExtent()) { - if (fixupDuration) - timeline.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::InOutQuad), fixupDuration); - else - _moveY.setValue(q->minYExtent()); + if (fixupDuration) { + qreal dist = q->minXExtent() - _moveX; + timeline.move(_moveX, q->minXExtent() - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); + timeline.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); + } else { + _moveX.setValue(q->minXExtent()); + } } //emit flickingChanged(); } else if (_moveX.value() < q->maxXExtent()) { timeline.reset(_moveX); - if (fixupDuration) - timeline.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::InOutQuad), fixupDuration); - else - _moveY.setValue(q->maxYExtent()); + if (fixupDuration) { + qreal dist = q->maxXExtent() - _moveX; + timeline.move(_moveX, q->maxXExtent() - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); + timeline.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); + } else { + _moveX.setValue(q->maxXExtent()); + } //emit flickingChanged(); } else { flicked = false; @@ -272,18 +295,24 @@ void QDeclarativeFlickablePrivate::fixupY() if (_moveY.value() > q->minYExtent() || (q->maxYExtent() > q->minYExtent())) { timeline.reset(_moveY); if (_moveY.value() != q->minYExtent()) { - if (fixupDuration) - timeline.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::InOutQuad), fixupDuration); - else + if (fixupDuration) { + qreal dist = q->minYExtent() - _moveY; + timeline.move(_moveY, q->minYExtent() - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); + timeline.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); + } else { _moveY.setValue(q->minYExtent()); + } } //emit flickingChanged(); } else if (_moveY.value() < q->maxYExtent()) { timeline.reset(_moveY); - if (fixupDuration) - timeline.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::InOutQuad), fixupDuration); - else + if (fixupDuration) { + qreal dist = q->maxYExtent() - _moveY; + timeline.move(_moveY, q->maxYExtent() - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); + timeline.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); + } else { _moveY.setValue(q->maxYExtent()); + } //emit flickingChanged(); } else { flicked = false; @@ -993,7 +1022,7 @@ void QDeclarativeFlickable::setOverShoot(bool o) \qmlproperty int Flickable::contentWidth \qmlproperty int Flickable::contentHeight - The dimensions of the viewport (the surface controlled by Flickable). Typically this + The dimensions of the content (the surface controlled by Flickable). Typically this should be set to the combined size of the items placed in the Flickable. \code diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index dc3a8a2..1ff4f92 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -85,6 +85,8 @@ public: void setRoundedViewportX(qreal x); void setRoundedViewportY(qreal y); + qreal overShootDistance(qreal velocity, qreal size); + public: QDeclarativeItem *viewport; QDeclarativeTimeLineValueProxy<QDeclarativeFlickablePrivate> _moveX; diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 6421018..c496c97 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1073,7 +1073,7 @@ void QDeclarativeListViewPrivate::fixupY() qreal pos = currentItem->position() - highlightRangeStart; timeline.reset(_moveY); if (fixupDuration) - timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration); + timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); else _moveY.setValue(-pos); vTime = timeline.time(); @@ -1085,7 +1085,7 @@ void QDeclarativeListViewPrivate::fixupY() if (dist > 0) { timeline.reset(_moveY); if (fixupDuration) - timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration); + timeline.move(_moveY, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); else _moveY.setValue(-pos); vTime = timeline.time(); @@ -1155,7 +1155,7 @@ void QDeclarativeListViewPrivate::flickX(qreal velocity) if (FxListItem *item = firstVisibleItem()) maxDistance = qAbs(item->position() + _moveX.value()); } else if (_moveX.value() < minX) { - maxDistance = qAbs(minX -_moveX.value() + (overShoot?30:0)); + maxDistance = qAbs(minX -_moveX.value() + (overShoot?overShootDistance(velocity, q->width()):0)); } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) flickTargetX = minX; @@ -1164,7 +1164,7 @@ void QDeclarativeListViewPrivate::flickX(qreal velocity) if (FxListItem *item = nextVisibleItem()) maxDistance = qAbs(item->position() + _moveX.value()); } else if (_moveX.value() > maxX) { - maxDistance = qAbs(maxX - _moveX.value()) + (overShoot?30:0); + maxDistance = qAbs(maxX - _moveX.value()) + (overShoot?overShootDistance(velocity, q->width()):0); } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) flickTargetX = maxX; @@ -1196,7 +1196,7 @@ void QDeclarativeListViewPrivate::flickX(qreal velocity) overshootDist = 0.0; } else { flickTargetX = velocity > 0 ? minX : maxX; - overshootDist = overShoot ? 30 : 0; + overshootDist = overShoot ? overShootDistance(v, q->width()) : 0; } timeline.reset(_moveX); timeline.accel(_moveX, v, accel, maxDistance + overshootDist); @@ -1253,7 +1253,7 @@ void QDeclarativeListViewPrivate::flickY(qreal velocity) if (FxListItem *item = firstVisibleItem()) maxDistance = qAbs(item->position() + _moveY.value()); } else if (_moveY.value() < minY) { - maxDistance = qAbs(minY -_moveY.value() + (overShoot?30:0)); + maxDistance = qAbs(minY -_moveY.value() + (overShoot?overShootDistance(velocity, q->height()):0)); } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) flickTargetY = minY; @@ -1262,7 +1262,7 @@ void QDeclarativeListViewPrivate::flickY(qreal velocity) if (FxListItem *item = nextVisibleItem()) maxDistance = qAbs(item->position() + _moveY.value()); } else if (_moveY.value() > maxY) { - maxDistance = qAbs(maxY - _moveY.value()) + (overShoot?30:0); + maxDistance = qAbs(maxY - _moveY.value()) + (overShoot?overShootDistance(velocity, q->height()):0); } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) flickTargetY = maxY; @@ -1294,7 +1294,7 @@ void QDeclarativeListViewPrivate::flickY(qreal velocity) overshootDist = 0.0; } else { flickTargetY = velocity > 0 ? minY : maxY; - overshootDist = overShoot ? 30 : 0; + overshootDist = overShoot ? overShootDistance(v, q->height()) : 0; } timeline.reset(_moveY); timeline.accel(_moveY, v, accel, maxDistance + overshootDist); diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 328f0e4..181ef0a 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -1572,8 +1572,7 @@ QDeclarativeSequentialAnimation::QDeclarativeSequentialAnimation(QObject *parent QDeclarativeAnimationGroup(parent) { Q_D(QDeclarativeAnimationGroup); - d->ag = new QSequentialAnimationGroup; - QDeclarativeGraphics_setParent_noEvent(d->ag, this); + d->ag = new QSequentialAnimationGroup(this); } QDeclarativeSequentialAnimation::~QDeclarativeSequentialAnimation() @@ -1638,8 +1637,7 @@ QDeclarativeParallelAnimation::QDeclarativeParallelAnimation(QObject *parent) : QDeclarativeAnimationGroup(parent) { Q_D(QDeclarativeAnimationGroup); - d->ag = new QParallelAnimationGroup; - QDeclarativeGraphics_setParent_noEvent(d->ag, this); + d->ag = new QParallelAnimationGroup(this); } QDeclarativeParallelAnimation::~QDeclarativeParallelAnimation() @@ -1798,7 +1796,7 @@ QDeclarativePropertyAnimation::~QDeclarativePropertyAnimation() void QDeclarativePropertyAnimationPrivate::init() { Q_Q(QDeclarativePropertyAnimation); - va = new QDeclarativeBulkValueAnimator; + va = new QDeclarativeTimeLineValueAnimator; QDeclarativeGraphics_setParent_noEvent(va, q); } @@ -2214,7 +2212,7 @@ QAbstractAnimation *QDeclarativePropertyAnimation::qtAnimation() return d->va; } -struct PropertyUpdater : public QDeclarativeBulkValueUpdater +struct PropertyUpdater : public QDeclarativeTimeLineValue { QDeclarativeStateActions actions; int interpolatorType; //for Number/ColorAnimation @@ -2232,6 +2230,7 @@ struct PropertyUpdater : public QDeclarativeBulkValueUpdater wasDeleted = &deleted; if (reverse) //QVariantAnimation sends us 1->0 when reversed, but we are expecting 0->1 v = 1 - v; + QDeclarativeTimeLineValue::setValue(v); for (int ii = 0; ii < actions.count(); ++ii) { QDeclarativeAction &action = actions[ii]; diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index ae82a90..e582066 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -149,21 +149,14 @@ private: bool running; }; -class QDeclarativeBulkValueUpdater -{ -public: - virtual ~QDeclarativeBulkValueUpdater() {} - virtual void setValue(qreal value) = 0; -}; - -//animates QDeclarativeBulkValueUpdater (assumes start and end values will be reals or compatible) -class QDeclarativeBulkValueAnimator : public QVariantAnimation +//animates QDeclarativeTimeLineValue (assumes start and end values will be reals or compatible) +class QDeclarativeTimeLineValueAnimator : public QVariantAnimation { Q_OBJECT public: - QDeclarativeBulkValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} - ~QDeclarativeBulkValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } } - void setAnimValue(QDeclarativeBulkValueUpdater *value, DeletionPolicy p) + QDeclarativeTimeLineValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} + ~QDeclarativeTimeLineValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } } + void setAnimValue(QDeclarativeTimeLineValue *value, DeletionPolicy p) { if (state() == Running) stop(); @@ -200,7 +193,7 @@ protected: } private: - QDeclarativeBulkValueUpdater *animValue; + QDeclarativeTimeLineValue *animValue; bool *fromSourced; DeletionPolicy policy; }; @@ -359,7 +352,7 @@ public: int interpolatorType; QVariantAnimation::Interpolator interpolator; - QDeclarativeBulkValueAnimator *va; + QDeclarativeTimeLineValueAnimator *va; static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress); static void convertVariant(QVariant &variant, int type); |