41QSmoothedAnimation::QSmoothedAnimation(QQuickSmoothedAnimationPrivate *priv)
42 : QAbstractAnimationJob(), to(0), velocity(200), userDuration(-1), maximumEasingTime(-1),
43 reversingMode(QQuickSmoothedAnimation::Eased), initialVelocity(0),
44 trackVelocity(0), initialValue(0), invert(
false), finalDuration(-1), lastTime(0),
45 skipUpdate(
false), delayedStopTimer(
new QSmoothedAnimationTimer(
this)), animationTemplate(priv)
48 delayedStopTimer->setSingleShot(
true);
51QSmoothedAnimation::~QSmoothedAnimation()
53 delete delayedStopTimer;
54 if (animationTemplate) {
55 if (target.object()) {
56 auto it = animationTemplate->activeAnimations.constFind(target);
57 if (it != animationTemplate->activeAnimations.cend() && it.value() ==
this)
58 animationTemplate->activeAnimations.erase(it);
61 for (
auto it = animationTemplate->activeAnimations.cbegin(); it != animationTemplate->activeAnimations.cend(); ++it) {
62 if (it.value() ==
this) {
63 animationTemplate->activeAnimations.erase(it);
205void QSmoothedAnimation::updateCurrentTime(
int t)
212 if (!isRunning() && !isPaused())
215 qreal time_seconds = qreal(t - lastTime) / 1000.;
217 qreal value = easeFollow(time_seconds);
218 value *= (invert? -1.0: 1.0);
219 QQmlPropertyPrivate::write(target, initialValue + value,
220 QQmlPropertyData::BypassInterceptor
221 | QQmlPropertyData::DontRemoveBinding);
224void QSmoothedAnimation::init()
231 if (delayedStopTimer->isActive())
232 delayedStopTimer->stop();
234 initialValue = target.read().toReal();
235 lastTime =
this->currentTime();
237 if (to == initialValue) {
242 bool hasReversed = trackVelocity != 0. &&
243 ((!invert) == ((initialValue - to) > 0));
246 switch (reversingMode) {
248 case QQuickSmoothedAnimation::Eased:
249 initialVelocity = -trackVelocity;
251 case QQuickSmoothedAnimation::Sync:
252 QQmlPropertyPrivate::write(target, to,
253 QQmlPropertyData::BypassInterceptor
254 | QQmlPropertyData::DontRemoveBinding);
258 case QQuickSmoothedAnimation::Immediate:
264 trackVelocity = initialVelocity;
266 invert = (to < initialValue);
269 QQmlPropertyPrivate::write(target, to,
270 QQmlPropertyData::BypassInterceptor
271 | QQmlPropertyData::DontRemoveBinding);
362QAbstractAnimationJob* QQuickSmoothedAnimation::transition(QQuickStateActions &actions,
363 QQmlProperties &modified,
364 TransitionDirection direction,
365 QObject *defaultTarget)
368 Q_D(QQuickSmoothedAnimation);
370 const QQuickStateActions dataActions = QQuickPropertyAnimation::createTransitionActions(actions, modified, defaultTarget);
372 QContinuingAnimationGroupJob *wrapperGroup =
new QContinuingAnimationGroupJob();
374 if (!dataActions.isEmpty()) {
375 QSet<QAbstractAnimationJob*> anims;
376 for (
int i = 0; i < dataActions.size(); i++) {
377 QSmoothedAnimation *ease;
379 if (!d->activeAnimations.contains(dataActions[i].property)) {
380 ease =
new QSmoothedAnimation(d);
381 d->activeAnimations.insert(dataActions[i].property, ease);
382 ease->target = dataActions[i].property;
385 ease = d->activeAnimations.value(dataActions[i].property);
388 wrapperGroup->appendAnimation(initInstance(ease));
390 ease->to = dataActions[i].toValue.toReal();
393 ease->maximumEasingTime = d->anim->maximumEasingTime;
394 ease->reversingMode = d->anim->reversingMode;
395 ease->velocity = d->anim->velocity;
396 ease->userDuration = d->anim->userDuration;
398 ease->initialVelocity = ease->trackVelocity;
401 ease->prepareForRestart();
405 const auto copy = d->activeAnimations;
406 for (QSmoothedAnimation *ease : copy) {
407 if (!anims.contains(ease)) {
408 ease->clearTemplate();
409 d->activeAnimations.remove(ease->target);
436void QQuickSmoothedAnimation::setReversingMode(ReversingMode m)
438 Q_D(QQuickSmoothedAnimation);
439 if (d->anim->reversingMode == m)
442 d->anim->reversingMode = m;
443 emit reversingModeChanged();
444 d->updateRunningAnimations();
463void QQuickSmoothedAnimation::setDuration(
int duration)
465 Q_D(QQuickSmoothedAnimation);
467 QQuickNumberAnimation::setDuration(duration);
468 if(duration == d->anim->userDuration)
470 d->anim->userDuration = duration;
471 d->updateRunningAnimations();
519void QQuickSmoothedAnimation::setMaximumEasingTime(
int v)
521 Q_D(QQuickSmoothedAnimation);
522 if(v == d->anim->maximumEasingTime)
524 d->anim->maximumEasingTime = v;
525 emit maximumEasingTimeChanged();
526 d->updateRunningAnimations();