void QSmoothedAnimation::init() { if (velocity == 0) { stop(); return; } if (delayedStopTimer.isActive()) delayedStopTimer.stop(); initialValue = target.read().toReal(); lastTime = this->currentTime(); if (to == initialValue) { stop(); return; } bool hasReversed = trackVelocity != 0. && ((trackVelocity > 0) == ((initialValue - to) > 0)); if (hasReversed) { switch (reversingMode) { default: case QDeclarativeSmoothedAnimation::Eased: break; case QDeclarativeSmoothedAnimation::Sync: QDeclarativePropertyPrivate::write(target, to, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); stop(); return; case QDeclarativeSmoothedAnimation::Immediate: initialVelocity = 0; delayedStop(); break; } } trackVelocity = initialVelocity; invert = (to < initialValue); if (!recalc()) { QDeclarativePropertyPrivate::write(target, to, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); stop(); return; } }
qreal QSmoothedAnimation::easeFollow(qreal time_seconds) { qreal value; if (time_seconds < tp) { trackVelocity = vi + time_seconds * a; value = qreal(0.5) * a * time_seconds * time_seconds + vi * time_seconds; } else if (time_seconds < td) { time_seconds -= tp; trackVelocity = vp; value = sp + time_seconds * vp; } else if (time_seconds < tf) { time_seconds -= td; trackVelocity = vp - time_seconds * a; value = sd - qreal(0.5) * d * time_seconds * time_seconds + vp * time_seconds; } else { trackVelocity = 0; value = s; delayedStop(); } // to normalize 's' between [0..1], divide 'value' by 's' return value; }