Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickanimationcontroller.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtQml/qqmlinfo.h>
6#include <private/qqmlengine_p.h>
7
9
10
27
45
47{
50 Q_UNUSED(job);
51 const qreal newProgress = currentTime * 1.0 / animationInstance->duration();
52 if (progress != newProgress) {
53 progress = newProgress;
54 emit q->progressChanged();
55 }
56}
57
74
80
89{
91 return d->progress;
92}
93
95{
98
99 if (progress != d->progress) {
100 d->progress = progress;
101 updateProgress();
103 }
104}
105
117{
118 Q_D(const QQuickAnimationController);
119 return d->animation;
120}
121
123{
125
126 if (animation != d->animation) {
127 if (animation) {
129 qmlWarning(this) << "QQuickAnimationController::setAnimation: the animation is controlled by others, can't be used in AnimationController.";
130 return;
131 }
133 }
134
135 if (d->animation)
136 d->animation->setEnableUserControl();
137
138 d->animation = animation;
139 reload();
141 }
142}
143
151{
153 if (!d->finalized)
154 return;
155
156 if (!d->animation) {
157 d->animationInstance = nullptr;
158 } else {
159 QQuickStateActions actions;
161 QAbstractAnimationJob *oldInstance = d->animationInstance;
162 d->animationInstance = d->animation->transition(actions, properties, QQuickAbstractAnimation::Forward);
163 if (oldInstance && oldInstance != d->animationInstance)
164 delete oldInstance;
165 if (d->animationInstance) {
166 d->animationInstance->setLoopCount(1);
167 d->animationInstance->setDisableUserControl();
168 d->animationInstance->start();
169 d->animationInstance->pause();
170 updateProgress();
171 }
172 }
173}
174
175void QQuickAnimationController::updateProgress()
176{
178 if (!d->animationInstance)
179 return;
180
181 d->animationInstance->setDisableUserControl();
182 d->animationInstance->start();
183 QQmlAnimationTimer::instance()->unregisterAnimation(d->animationInstance);
184 d->animationInstance->setCurrentTime(d->progress * d->animationInstance->duration());
185}
186
188{
190 d->finalized = true;
191 reload();
192}
193
206{
208 if (!d->animationInstance)
209 return;
210
211 if (d->progress == 0)
212 return;
213
214 d->animationInstance->addAnimationChangeListener(d, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime);
215 d->animationInstance->setDirection(QAbstractAnimationJob::Backward);
216
217 //Disable and then enable user control to trigger the animation instance's state change
218 d->animationInstance->setDisableUserControl();
219 d->animationInstance->setEnableUserControl();
220 d->animationInstance->start();
221}
222
235{
237 if (!d->animationInstance)
238 return;
239
240 if (d->progress == 1)
241 return;
242
243 d->animationInstance->addAnimationChangeListener(d, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime);
244 d->animationInstance->setDirection(QAbstractAnimationJob::Forward);
245
246 //Disable and then enable user control to trigger the animation instance's state change
247 d->animationInstance->setDisableUserControl();
248 d->animationInstance->setEnableUserControl();
249 d->animationInstance->start();
250}
251
252
253
255
256
257#include "moc_qquickanimationcontroller_p.cpp"
void setLoopCount(int loopCount)
QAbstractAnimationJob::Direction direction() const
void removeAnimationChangeListener(QAnimationJobChangeListener *listener, QAbstractAnimationJob::ChangeTypes)
\inmodule QtCore
Definition qobject.h:103
static QQmlAnimationTimer * instance()
void animationFinished(QAbstractAnimationJob *job) override
void animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime) override
void setAnimation(QQuickAbstractAnimation *animation)
void completeToEnd()
\qmlmethod QtQuick::AnimationController::completeToEnd()
void completeToBeginning()
\qmlmethod QtQuick::AnimationController::completeToBeginning()
QQuickAnimationController(QObject *parent=nullptr)
\qmltype AnimationController \instantiates QQuickAnimationController \inqmlmodule QtQuick
QQuickAbstractAnimation * animation
void reload()
\qmlmethod QtQuick::AnimationController::reload()
void componentFinalized() override
The customization point provided by this interface.
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
static double currentTime()
QObject::connect nullptr
QPropertyAnimation animation
[0]