diff options
Diffstat (limited to 'src/declarative/util')
7 files changed, 63 insertions, 21 deletions
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 3c09747..ea3da25 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -2699,14 +2699,15 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, qreal scale = 1; qreal rotation = 0; - if (ok && transform.type() != QTransform::TxRotate) { + bool isRotate = (transform.type() == QTransform::TxRotate) || (transform.m11() < 0); + if (ok && !isRotate) { if (transform.m11() == transform.m22()) scale = transform.m11(); else { qmlInfo(this) << QDeclarativeParentAnimation::tr("Unable to preserve appearance under non-uniform scale"); ok = false; } - } else if (ok && transform.type() == QTransform::TxRotate) { + } else if (ok && isRotate) { if (transform.m11() == transform.m22()) scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12()); else { diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index d3cf9c8..cf2eada 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -1298,7 +1298,6 @@ void ModelNode::setObjectValue(const QScriptValue& valuemap) { } void ModelNode::setListValue(const QScriptValue& valuelist) { - QScriptValueIterator it(valuelist); values.clear(); int size = valuelist.property(QLatin1String("length")).toInt32(); for (int i=0; i<size; i++) { diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp index 498de6d..d9df169 100644 --- a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp +++ b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp @@ -232,7 +232,7 @@ bool QDeclarativeListModelWorkerAgent::event(QEvent *e) emit m_orig->itemsMoved(change.index, change.to, change.count); break; case Change::Changed: - emit m_orig->itemsMoved(change.index, change.to, change.count); + emit m_orig->itemsChanged(change.index, change.to, orig->m_roles.keys()); break; } } diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp index b2f02e6..ca83c52 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation.cpp +++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp @@ -214,22 +214,23 @@ void QSmoothedAnimation::init() } bool hasReversed = trackVelocity != 0. && - ((trackVelocity > 0) == ((initialValue - to) > 0)); + ((!invert) == ((initialValue - to) > 0)); if (hasReversed) { switch (reversingMode) { default: case QDeclarativeSmoothedAnimation::Eased: + initialVelocity = -trackVelocity; break; case QDeclarativeSmoothedAnimation::Sync: QDeclarativePropertyPrivate::write(target, to, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); + trackVelocity = 0; stop(); return; case QDeclarativeSmoothedAnimation::Immediate: initialVelocity = 0; - delayedStop(); break; } } @@ -311,6 +312,17 @@ QDeclarativeSmoothedAnimationPrivate::QDeclarativeSmoothedAnimationPrivate() QDeclarative_setParent_noEvent(anim, q); } +void QDeclarativeSmoothedAnimationPrivate::updateRunningAnimations() +{ + foreach(QSmoothedAnimation* ease, activeAnimations.values()){ + ease->maximumEasingTime = anim->maximumEasingTime; + ease->reversingMode = anim->reversingMode; + ease->velocity = anim->velocity; + ease->userDuration = anim->userDuration; + ease->init(); + } +} + QAbstractAnimation* QDeclarativeSmoothedAnimation::qtAnimation() { Q_D(QDeclarativeSmoothedAnimation); @@ -340,7 +352,6 @@ void QDeclarativeSmoothedAnimation::transition(QDeclarativeStateActions &actions ease = d->activeAnimations.value((*d->actions)[i].property); needsRestart = true; } - ease->target = (*d->actions)[i].property; ease->to = (*d->actions)[i].toValue.toReal(); @@ -394,6 +405,7 @@ void QDeclarativeSmoothedAnimation::setReversingMode(ReversingMode m) d->anim->reversingMode = m; emit reversingModeChanged(); + d->updateRunningAnimations(); } /*! @@ -402,6 +414,9 @@ void QDeclarativeSmoothedAnimation::setReversingMode(ReversingMode m) This property holds the animation duration, in msecs, used when tracking the source. Setting this to -1 (the default) disables the duration value. + + If the velocity value and the duration value are both enabled, then the animation will + use whichever gives the shorter duration. */ int QDeclarativeSmoothedAnimation::duration() const { @@ -414,7 +429,10 @@ void QDeclarativeSmoothedAnimation::setDuration(int duration) Q_D(QDeclarativeSmoothedAnimation); if (duration != -1) QDeclarativeNumberAnimation::setDuration(duration); + if(duration == d->anim->userDuration) + return; d->anim->userDuration = duration; + d->updateRunningAnimations(); } qreal QDeclarativeSmoothedAnimation::velocity() const @@ -431,6 +449,9 @@ qreal QDeclarativeSmoothedAnimation::velocity() const The default velocity of SmoothedAnimation is 200 units/second. Setting this to -1 disables the velocity value. + + If the velocity value and the duration value are both enabled, then the animation will + use whichever gives the shorter duration. */ void QDeclarativeSmoothedAnimation::setVelocity(qreal v) { @@ -440,12 +461,13 @@ void QDeclarativeSmoothedAnimation::setVelocity(qreal v) d->anim->velocity = v; emit velocityChanged(); + d->updateRunningAnimations(); } /*! \qmlproperty int SmoothedAnimation::maximumEasingTime - This property specifies the maximum time, in msecs, an "eases" during the follow should take. + This property specifies the maximum time, in msecs, any "eases" during the follow should take. Setting this property causes the velocity to "level out" after at a time. Setting a negative value reverts to the normal mode of easing over the entire animation duration. @@ -461,8 +483,11 @@ int QDeclarativeSmoothedAnimation::maximumEasingTime() const void QDeclarativeSmoothedAnimation::setMaximumEasingTime(int v) { Q_D(QDeclarativeSmoothedAnimation); + if(v == d->anim->maximumEasingTime) + return; d->anim->maximumEasingTime = v; emit maximumEasingTimeChanged(); + d->updateRunningAnimations(); } QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativesmoothedanimation_p_p.h b/src/declarative/util/qdeclarativesmoothedanimation_p_p.h index 8cdbea2..cb0f4c2 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation_p_p.h +++ b/src/declarative/util/qdeclarativesmoothedanimation_p_p.h @@ -123,6 +123,7 @@ class QDeclarativeSmoothedAnimationPrivate : public QDeclarativePropertyAnimatio Q_DECLARE_PUBLIC(QDeclarativeSmoothedAnimation) public: QDeclarativeSmoothedAnimationPrivate(); + void updateRunningAnimations(); QParallelAnimationGroup *wrapperGroup; QSmoothedAnimation *anim; diff --git a/src/declarative/util/qdeclarativespringanimation.cpp b/src/declarative/util/qdeclarativespringanimation.cpp index fce4097..e0fc45d 100644 --- a/src/declarative/util/qdeclarativespringanimation.cpp +++ b/src/declarative/util/qdeclarativespringanimation.cpp @@ -62,10 +62,12 @@ public: struct SpringAnimation { SpringAnimation() - : currentValue(0), to(0), velocity(0){} + : currentValue(0), to(0), velocity(0), start(0), duration(0) {} qreal currentValue; qreal to; qreal velocity; + int start; + int duration; }; QHash<QDeclarativeProperty, SpringAnimation> activeAnimations; @@ -135,7 +137,6 @@ void QDeclarativeSpringAnimationPrivate::tick(int time) bool QDeclarativeSpringAnimationPrivate::animate(const QDeclarativeProperty &property, SpringAnimation &animation, int elapsed) { - qreal srcVal = animation.to; bool stop = false; @@ -192,18 +193,14 @@ bool QDeclarativeSpringAnimationPrivate::animate(const QDeclarativeProperty &pro animation.currentValue += moveBy; if (haveModulus) animation.currentValue = fmod(animation.currentValue, modulus); - if (animation.currentValue > animation.to) { - animation.currentValue = animation.to; - stop = true; - } } else { animation.currentValue -= moveBy; if (haveModulus && animation.currentValue < 0.0) animation.currentValue = fmod(animation.currentValue, modulus) + modulus; - if (animation.currentValue < animation.to) { - animation.currentValue = animation.to; - stop = true; - } + } + if (lastTime - animation.start >= animation.duration) { + animation.currentValue = animation.to; + stop = true; } } @@ -222,8 +219,18 @@ void QDeclarativeSpringAnimationPrivate::updateMode() mode = Track; else if (spring > 0.) mode = Spring; - else + else { mode = Velocity; + QHash<QDeclarativeProperty, SpringAnimation>::iterator it; + for (it = activeAnimations.begin(); it != activeAnimations.end(); ++it) { + SpringAnimation &animation = *it; + animation.start = lastTime; + qreal dist = qAbs(animation.currentValue - animation.to); + if (haveModulus && dist > modulus / 2) + dist = modulus - fmod(dist, modulus); + animation.duration = dist / velocityms; + } + } } /*! @@ -378,6 +385,7 @@ void QDeclarativeSpringAnimation::setModulus(qreal modulus) if (d->modulus != modulus) { d->haveModulus = modulus != 0.0; d->modulus = modulus; + d->updateMode(); emit modulusChanged(); } } @@ -429,10 +437,17 @@ void QDeclarativeSpringAnimation::transition(QDeclarativeStateActions &actions, QDeclarativeSpringAnimationPrivate::SpringAnimation &animation = d->activeAnimations[property]; animation.to = d->actions->at(i).toValue.toReal(); + animation.start = d->lastTime; if (d->fromIsDefined) animation.currentValue = d->actions->at(i).fromValue.toReal(); else animation.currentValue = property.read().toReal(); + if (d->mode == QDeclarativeSpringAnimationPrivate::Velocity) { + qreal dist = qAbs(animation.currentValue - animation.to); + if (d->haveModulus && dist > d->modulus / 2) + dist = d->modulus - fmod(dist, d->modulus); + animation.duration = dist / d->velocityms; + } } } } diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 845b3da..a78fc54 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -98,14 +98,15 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q qreal scale = 1; qreal rotation = 0; - if (ok && transform.type() != QTransform::TxRotate) { + bool isRotate = (transform.type() == QTransform::TxRotate) || (transform.m11() < 0); + if (ok && !isRotate) { if (transform.m11() == transform.m22()) scale = transform.m11(); else { qmlInfo(q) << QDeclarativeParentChange::tr("Unable to preserve appearance under non-uniform scale"); ok = false; } - } else if (ok && transform.type() == QTransform::TxRotate) { + } else if (ok && isRotate) { if (transform.m11() == transform.m22()) scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12()); else { |