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 friend class tst_Animators;
64
65 void syncBackCurrentValues();
66 void readyToAnimate();
67 void setWindow(QQuickWindow *window);
68 static QObject *findAnimationContext(QQuickAbstractAnimation *);
69
70 QPointer<QQuickAnimatorController> m_controller;
71 QSharedPointer<QAbstractAnimationJob> m_job;
72 int m_duration;
73
74 enum InternalState {
75 State_Starting, // Used when it should be running, but no we're still missing the controller.
76 State_Running,
77 State_Paused,
78 State_Stopped
79 };
80
81 InternalState m_internalState;
82};
83
84class Q_QUICK_EXPORT QQuickAnimatorJob : public QAbstractAnimationJob
85{
86public:
87 virtual void setTarget(QQuickItem *target);
88 QQuickItem *target() const { return m_target; }
89
90 void setFrom(qreal from) {
91 m_from = from;
92 boundValue();
93 }
94 qreal from() const { return m_from; }
95
96 void setTo(qreal to) {
97 m_to = to;
98 boundValue();
99 }
100 qreal to() const { return m_to; }
101
102 void setDuration(int duration) { m_duration = duration; }
103 int duration() const override { return m_duration; }
104
105 QEasingCurve easingCurve() const { return m_easing; }
106 void setEasingCurve(const QEasingCurve &curve) { m_easing = curve; }
107
108 // Initialize is called on the GUI thread just before it is started
109 // and taken over on the render thread.
110 virtual void initialize(QQuickAnimatorController *controller);
111
112 // Called on the render thread during SG shutdown.
113 virtual void invalidate() = 0;
114
115 // Called on the GUI thread after a complete render thread animation job
116 // has been completed to write back a given animator's result to the
117 // source item.
118 virtual void writeBack() = 0;
119
120 // Called before the SG sync on the render thread. The GUI thread is
121 // locked during this call.
122 virtual void preSync() { }
123
124 // Called after the SG sync on the render thread. The GUI thread is
125 // locked during this call.
126 virtual void postSync() { }
127
128 // Called after animations have ticked on the render thread. No locks are
129 // held at this time, so synchronization needs to be taken into account
130 // if applicable.
131 virtual void commit() { }
132
133 bool isTransform() const { return m_isTransform; }
134 bool isUniform() const { return m_isUniform; }
135
136 qreal value() const;
137
138 QQuickAnimatorController *controller() const { return m_controller; }
139
140protected:
141 QQuickAnimatorJob();
142 void debugAnimation(QDebug d) const override;
143
144 qreal progress(int time) const;
145 void boundValue();
146
147 QPointer<QQuickItem> m_target;
148 QQuickAnimatorController *m_controller;
149
150 qreal m_from;
151 qreal m_to;
152 qreal m_value;
153
154 QEasingCurve m_easing;
155
156 int m_duration;
157
158 uint m_isTransform : 1;
159 uint m_isUniform : 1;
160};
161
163{
164public:
165
166 struct Helper
167 {
169 : ref(1)
170 , node(nullptr)
171 , ox(0)
172 , oy(0)
173 , dx(0)
174 , dy(0)
175 , scale(1)
176 , rotation(0)
177 , wasSynced(false)
178 , wasChanged(false)
179 {
180 }
181
182 void sync();
183 void commit();
184
185 int ref;
186 QQuickItem *item;
188
189 // Origin
190 float ox;
191 float oy;
192
193 float dx;
194 float dy;
195 float scale;
196 float rotation;
197
200 };
201
203
204 void commit() override;
205 void preSync() override;
206
207 void setTarget(QQuickItem *item) override;
208
209protected:
211 void invalidate() override;
212
214};
215
216class Q_QUICK_EXPORT QQuickScaleAnimatorJob : public QQuickTransformAnimatorJob
217{
218public:
219 void updateCurrentTime(int time) override;
220 void writeBack() override;
221};
222
223class Q_QUICK_EXPORT QQuickXAnimatorJob : public QQuickTransformAnimatorJob
224{
225public:
226 void updateCurrentTime(int time) override;
227 void writeBack() override;
228};
229
230class Q_QUICK_EXPORT QQuickYAnimatorJob : public QQuickTransformAnimatorJob
231{
232public:
233 void updateCurrentTime(int time) override;
234 void writeBack() override;
235};
236
237class Q_QUICK_EXPORT QQuickRotationAnimatorJob : public QQuickTransformAnimatorJob
238{
239public:
240 QQuickRotationAnimatorJob();
241
242 void updateCurrentTime(int time) override;
243 void writeBack() override;
244
245 void setDirection(QQuickRotationAnimator::RotationDirection direction) { m_direction = direction; }
246 QQuickRotationAnimator::RotationDirection direction() const { return m_direction; }
247
248private:
249 QQuickRotationAnimator::RotationDirection m_direction;
250};
251
252class Q_QUICK_EXPORT QQuickOpacityAnimatorJob : public QQuickAnimatorJob
253{
254public:
255 QQuickOpacityAnimatorJob();
256
257 void invalidate() override;
258 void updateCurrentTime(int time) override;
259 void writeBack() override;
260 void postSync() override;
261
262private:
263 QSGOpacityNode *m_opacityNode;
264};
265
266#if QT_CONFIG(quick_shadereffect)
267class QQuickShaderEffect;
268
269class Q_QUICK_EXPORT QQuickUniformAnimatorJob : public QQuickAnimatorJob
270{
271public:
272 QQuickUniformAnimatorJob();
273
274 void setTarget(QQuickItem *target) override;
275
276 void setUniform(const QByteArray &uniform) { m_uniform = uniform; }
277 QByteArray uniform() const { return m_uniform; }
278
279 void updateCurrentTime(int time) override;
280 void writeBack() override;
281 void postSync() override;
282
283 void invalidate() override;
284
285private:
286 QByteArray m_uniform;
287 QPointer<QQuickShaderEffect> m_effect;
288};
289#endif
290
291QT_END_NAMESPACE
292
293#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
Combined button and popup list for selecting options.
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