Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickanimatorjob_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Gunnar Sletta <gunnar@sletta.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QQUICKANIMATORJOB_P_H
7#define QQUICKANIMATORJOB_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <private/qabstractanimationjob_p.h>
21#include <private/qquickanimator_p.h>
22#include <private/qtquickglobal_p.h>
23
24#include <QtQuick/qquickitem.h>
25
26#include <QtCore/qeasingcurve.h>
27#include <QtCore/qpointer.h>
28
30
31class QQuickAnimator;
32class QQuickWindow;
33class QQuickItem;
34class QQuickAbstractAnimation;
35
36class QQuickAnimatorController;
37
38class QSGOpacityNode;
39
40class Q_QUICK_EXPORT QQuickAnimatorProxyJob : public QObject, public QAbstractAnimationJob
41{
42 Q_OBJECT
43
44public:
45 QQuickAnimatorProxyJob(QAbstractAnimationJob *job, QQuickAbstractAnimation *animation);
46 ~QQuickAnimatorProxyJob();
47
48 int duration() const override { return m_duration; }
49
50 const QSharedPointer<QAbstractAnimationJob> &job() const { return m_job; }
51
52protected:
53 void updateCurrentTime(int) override;
54 void updateLoopCount(int) override;
55 void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
56 void debugAnimation(QDebug d) const override;
57
58public Q_SLOTS:
59 void windowChanged(QQuickWindow *window);
60 void sceneGraphInitialized();
61
62private:
63 void syncBackCurrentValues();
64 void readyToAnimate();
65 void setWindow(QQuickWindow *window);
66 static QObject *findAnimationContext(QQuickAbstractAnimation *);
67
68 QPointer<QQuickAnimatorController> m_controller;
69 QSharedPointer<QAbstractAnimationJob> m_job;
70 int m_duration;
71
72 enum InternalState {
73 State_Starting, // Used when it should be running, but no we're still missing the controller.
74 State_Running,
75 State_Paused,
76 State_Stopped
77 };
78
79 InternalState m_internalState;
80};
81
82class Q_QUICK_EXPORT QQuickAnimatorJob : public QAbstractAnimationJob
83{
84public:
85 virtual void setTarget(QQuickItem *target);
86 QQuickItem *target() const { return m_target; }
87
88 void setFrom(qreal from) {
89 m_from = from;
90 boundValue();
91 }
92 qreal from() const { return m_from; }
93
94 void setTo(qreal to) {
95 m_to = to;
96 boundValue();
97 }
98 qreal to() const { return m_to; }
99
100 void setDuration(int duration) { m_duration = duration; }
101 int duration() const override { return m_duration; }
102
103 QEasingCurve easingCurve() const { return m_easing; }
104 void setEasingCurve(const QEasingCurve &curve) { m_easing = curve; }
105
106 // Initialize is called on the GUI thread just before it is started
107 // and taken over on the render thread.
108 virtual void initialize(QQuickAnimatorController *controller);
109
110 // Called on the render thread during SG shutdown.
111 virtual void invalidate() = 0;
112
113 // Called on the GUI thread after a complete render thread animation job
114 // has been completed to write back a given animator's result to the
115 // source item.
116 virtual void writeBack() = 0;
117
118 // Called before the SG sync on the render thread. The GUI thread is
119 // locked during this call.
120 virtual void preSync() { }
121
122 // Called after the SG sync on the render thread. The GUI thread is
123 // locked during this call.
124 virtual void postSync() { }
125
126 // Called after animations have ticked on the render thread. No locks are
127 // held at this time, so synchronization needs to be taken into account
128 // if applicable.
129 virtual void commit() { }
130
131 bool isTransform() const { return m_isTransform; }
132 bool isUniform() const { return m_isUniform; }
133
134 qreal value() const;
135
136 QQuickAnimatorController *controller() const { return m_controller; }
137
138protected:
139 QQuickAnimatorJob();
140 void debugAnimation(QDebug d) const override;
141
142 qreal progress(int time) const;
143 void boundValue();
144
145 QPointer<QQuickItem> m_target;
146 QQuickAnimatorController *m_controller;
147
148 qreal m_from;
149 qreal m_to;
150 qreal m_value;
151
152 QEasingCurve m_easing;
153
154 int m_duration;
155
156 uint m_isTransform : 1;
157 uint m_isUniform : 1;
158};
159
161{
162public:
163
164 struct Helper
165 {
167 : ref(1)
168 , node(nullptr)
169 , ox(0)
170 , oy(0)
171 , dx(0)
172 , dy(0)
173 , scale(1)
174 , rotation(0)
175 , wasSynced(false)
176 , wasChanged(false)
177 {
178 }
179
180 void sync();
181 void commit();
182
183 int ref;
184 QQuickItem *item;
186
187 // Origin
188 float ox;
189 float oy;
190
191 float dx;
192 float dy;
193 float scale;
194 float rotation;
195
198 };
199
201
202 void commit() override;
203 void preSync() override;
204
205 void setTarget(QQuickItem *item) override;
206
207protected:
209 void invalidate() override;
210
212};
213
214class Q_QUICK_EXPORT QQuickScaleAnimatorJob : public QQuickTransformAnimatorJob
215{
216public:
217 void updateCurrentTime(int time) override;
218 void writeBack() override;
219};
220
221class Q_QUICK_EXPORT QQuickXAnimatorJob : public QQuickTransformAnimatorJob
222{
223public:
224 void updateCurrentTime(int time) override;
225 void writeBack() override;
226};
227
228class Q_QUICK_EXPORT QQuickYAnimatorJob : public QQuickTransformAnimatorJob
229{
230public:
231 void updateCurrentTime(int time) override;
232 void writeBack() override;
233};
234
235class Q_QUICK_EXPORT QQuickRotationAnimatorJob : public QQuickTransformAnimatorJob
236{
237public:
238 QQuickRotationAnimatorJob();
239
240 void updateCurrentTime(int time) override;
241 void writeBack() override;
242
243 void setDirection(QQuickRotationAnimator::RotationDirection direction) { m_direction = direction; }
244 QQuickRotationAnimator::RotationDirection direction() const { return m_direction; }
245
246private:
247 QQuickRotationAnimator::RotationDirection m_direction;
248};
249
250class Q_QUICK_EXPORT QQuickOpacityAnimatorJob : public QQuickAnimatorJob
251{
252public:
253 QQuickOpacityAnimatorJob();
254
255 void invalidate() override;
256 void updateCurrentTime(int time) override;
257 void writeBack() override;
258 void postSync() override;
259
260private:
261 QSGOpacityNode *m_opacityNode;
262};
263
264#if QT_CONFIG(quick_shadereffect)
265class QQuickShaderEffect;
266
267class Q_QUICK_EXPORT QQuickUniformAnimatorJob : public QQuickAnimatorJob
268{
269public:
270 QQuickUniformAnimatorJob();
271
272 void setTarget(QQuickItem *target) override;
273
274 void setUniform(const QByteArray &uniform) { m_uniform = uniform; }
275 QByteArray uniform() const { return m_uniform; }
276
277 void updateCurrentTime(int time) override;
278 void writeBack() override;
279 void postSync() override;
280
281 void invalidate() override;
282
283private:
284 QByteArray m_uniform;
285 QPointer<QQuickShaderEffect> m_effect;
286};
287#endif
288
289QT_END_NAMESPACE
290
291#endif // QQUICKANIMATORJOB_P_H
virtual void debugAction(QDebug, int) const
virtual void doAction()=0
void debugAction(QDebug d, int indentLevel) const override
The QQmlScriptString class encapsulates a script and its context.
static qsizetype count_animation(QQmlListProperty< QQuickAbstractAnimation > *list)
QList< QQuickAbstractAnimation * > animations
void animationCurrentLoopChanged(QAbstractAnimationJob *job) override
static void replace_animation(QQmlListProperty< QQuickAbstractAnimation > *list, qsizetype index, QQuickAbstractAnimation *role)
static void removeLast_animation(QQmlListProperty< QQuickAbstractAnimation > *list)
static QQuickAbstractAnimation * at_animation(QQmlListProperty< QQuickAbstractAnimation > *list, qsizetype index)
static void clear_animation(QQmlListProperty< QQuickAbstractAnimation > *list)
virtual void debugUpdater(QDebug, int) const
virtual void setValue(qreal value)=0
QQmlNullableValue< QVariant > value
QAbstractAnimationAction * createAction()
QAnimationActionProxy< QQuickScriptActionPrivate, &QQuickScriptActionPrivate::execute, &QQuickScriptActionPrivate::debugAction > Proxy
void debugAction(QDebug d, int indentLevel) const
void setTarget(QQuickItem *item) override
QVariant _q_interpolateClockwiseRotation(qreal &f, qreal &t, qreal progress)
QVariant _q_interpolateShortestRotation(qreal &f, qreal &t, qreal progress)
\qmltype RotationAnimation \nativetype QQuickRotationAnimation \inqmlmodule QtQuick\inherits Property...
QVariant _q_interpolateCounterclockwiseRotation(qreal &f, qreal &t, qreal progress)
QQuickStateOperation::ActionList QQuickStateActions