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 | |
4 | #ifndef QQUICKANIMATION_H |
5 | #define QQUICKANIMATION_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qquickstate_p.h" |
19 | #include <QtGui/qvector3d.h> |
20 | |
21 | #include <qqmlpropertyvaluesource.h> |
22 | #include <qqml.h> |
23 | #include <qqmlscriptstring.h> |
24 | |
25 | #include <QtCore/qvariant.h> |
26 | #include <QtCore/qeasingcurve.h> |
27 | #include "private/qabstractanimationjob_p.h" |
28 | #include <QtGui/qcolor.h> |
29 | |
30 | QT_BEGIN_NAMESPACE |
31 | |
32 | class QQuickAbstractAnimationPrivate; |
33 | class QQuickAnimationGroup; |
34 | class Q_QUICK_PRIVATE_EXPORT QQuickAbstractAnimation : public QObject, public QQmlPropertyValueSource, public QQmlParserStatus |
35 | { |
36 | Q_OBJECT |
37 | Q_DECLARE_PRIVATE(QQuickAbstractAnimation) |
38 | |
39 | Q_INTERFACES(QQmlParserStatus) |
40 | Q_INTERFACES(QQmlPropertyValueSource) |
41 | Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged FINAL) |
42 | Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged FINAL) |
43 | Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged FINAL) |
44 | Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopCountChanged FINAL) |
45 | Q_CLASSINFO("DefaultMethod" , "start()" ) |
46 | |
47 | QML_NAMED_ELEMENT(Animation) |
48 | QML_ADDED_IN_VERSION(2, 0) |
49 | QML_UNCREATABLE("Animation is an abstract class" ) |
50 | |
51 | public: |
52 | enum ThreadingModel { |
53 | GuiThread, |
54 | RenderThread, |
55 | AnyThread |
56 | }; |
57 | |
58 | QQuickAbstractAnimation(QObject *parent=nullptr); |
59 | ~QQuickAbstractAnimation() override; |
60 | |
61 | enum Loops { Infinite = -2 }; |
62 | Q_ENUM(Loops) |
63 | |
64 | bool isRunning() const; |
65 | void setRunning(bool); |
66 | bool isPaused() const; |
67 | void setPaused(bool); |
68 | bool alwaysRunToEnd() const; |
69 | void setAlwaysRunToEnd(bool); |
70 | |
71 | int loops() const; |
72 | void setLoops(int); |
73 | int duration() const; |
74 | |
75 | int currentTime(); |
76 | void setCurrentTime(int); |
77 | |
78 | QQuickAnimationGroup *group() const; |
79 | void setGroup(QQuickAnimationGroup *, int index = -1); |
80 | |
81 | void setDefaultTarget(const QQmlProperty &); |
82 | void setDisableUserControl(); |
83 | void setEnableUserControl(); |
84 | bool userControlDisabled() const; |
85 | void classBegin() override; |
86 | void componentComplete() override; |
87 | |
88 | virtual ThreadingModel threadingModel() const; |
89 | |
90 | Q_SIGNALS: |
91 | void started(); |
92 | void stopped(); |
93 | void runningChanged(bool); |
94 | void pausedChanged(bool); |
95 | void alwaysRunToEndChanged(bool); |
96 | void loopCountChanged(int); |
97 | Q_REVISION(2, 12) void finished(); |
98 | |
99 | public Q_SLOTS: |
100 | void restart(); |
101 | void start(); |
102 | void pause(); |
103 | void resume(); |
104 | void stop(); |
105 | void complete(); |
106 | |
107 | protected: |
108 | QQuickAbstractAnimation(QQuickAbstractAnimationPrivate &dd, QObject *parent); |
109 | QAbstractAnimationJob* initInstance(QAbstractAnimationJob *animation); |
110 | |
111 | public: |
112 | enum TransitionDirection { Forward, Backward }; |
113 | virtual QAbstractAnimationJob* transition(QQuickStateActions &actions, |
114 | QQmlProperties &modified, |
115 | TransitionDirection direction, |
116 | QObject *defaultTarget = nullptr); |
117 | QAbstractAnimationJob* qtAnimation(); |
118 | |
119 | private: |
120 | void setTarget(const QQmlProperty &) override; |
121 | void notifyRunningChanged(bool running); |
122 | friend class QQuickBehavior; |
123 | friend class QQuickBehaviorPrivate; |
124 | friend class QQuickAnimationGroup; |
125 | }; |
126 | |
127 | class QQuickPauseAnimationPrivate; |
128 | class Q_QUICK_PRIVATE_EXPORT QQuickPauseAnimation : public QQuickAbstractAnimation |
129 | { |
130 | Q_OBJECT |
131 | Q_DECLARE_PRIVATE(QQuickPauseAnimation) |
132 | |
133 | Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged FINAL) |
134 | QML_NAMED_ELEMENT(PauseAnimation) |
135 | QML_ADDED_IN_VERSION(2, 0) |
136 | |
137 | public: |
138 | QQuickPauseAnimation(QObject *parent=nullptr); |
139 | ~QQuickPauseAnimation() override; |
140 | |
141 | int duration() const; |
142 | void setDuration(int); |
143 | |
144 | Q_SIGNALS: |
145 | void durationChanged(int); |
146 | |
147 | protected: |
148 | QAbstractAnimationJob* transition(QQuickStateActions &actions, |
149 | QQmlProperties &modified, |
150 | TransitionDirection direction, |
151 | QObject *defaultTarget = nullptr) override; |
152 | }; |
153 | |
154 | class QQuickScriptActionPrivate; |
155 | class Q_QUICK_PRIVATE_EXPORT QQuickScriptAction : public QQuickAbstractAnimation |
156 | { |
157 | Q_OBJECT |
158 | Q_DECLARE_PRIVATE(QQuickScriptAction) |
159 | |
160 | Q_PROPERTY(QQmlScriptString script READ script WRITE setScript FINAL) |
161 | Q_PROPERTY(QString scriptName READ stateChangeScriptName WRITE setStateChangeScriptName FINAL) |
162 | QML_NAMED_ELEMENT(ScriptAction) |
163 | QML_ADDED_IN_VERSION(2, 0) |
164 | |
165 | public: |
166 | QQuickScriptAction(QObject *parent=nullptr); |
167 | ~QQuickScriptAction() override; |
168 | |
169 | QQmlScriptString script() const; |
170 | void setScript(const QQmlScriptString &); |
171 | |
172 | QString stateChangeScriptName() const; |
173 | void setStateChangeScriptName(const QString &); |
174 | |
175 | protected: |
176 | QAbstractAnimationJob* transition(QQuickStateActions &actions, |
177 | QQmlProperties &modified, |
178 | TransitionDirection direction, |
179 | QObject *defaultTarget = nullptr) override; |
180 | }; |
181 | |
182 | class QQuickPropertyActionPrivate; |
183 | class Q_QUICK_PRIVATE_EXPORT QQuickPropertyAction : public QQuickAbstractAnimation |
184 | { |
185 | Q_OBJECT |
186 | Q_DECLARE_PRIVATE(QQuickPropertyAction) |
187 | |
188 | Q_PROPERTY(QObject *target READ target WRITE setTargetObject NOTIFY targetChanged FINAL) |
189 | Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged FINAL) |
190 | Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged FINAL) |
191 | Q_PROPERTY(QQmlListProperty<QObject> targets READ targets FINAL) |
192 | Q_PROPERTY(QQmlListProperty<QObject> exclude READ exclude FINAL) |
193 | Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged FINAL) |
194 | QML_NAMED_ELEMENT(PropertyAction) |
195 | QML_ADDED_IN_VERSION(2, 0) |
196 | |
197 | public: |
198 | QQuickPropertyAction(QObject *parent=nullptr); |
199 | ~QQuickPropertyAction() override; |
200 | |
201 | QObject *target() const; |
202 | void setTargetObject(QObject *); |
203 | |
204 | QString property() const; |
205 | void setProperty(const QString &); |
206 | |
207 | QString properties() const; |
208 | void setProperties(const QString &); |
209 | |
210 | QQmlListProperty<QObject> targets(); |
211 | QQmlListProperty<QObject> exclude(); |
212 | |
213 | QVariant value() const; |
214 | void setValue(const QVariant &); |
215 | |
216 | Q_SIGNALS: |
217 | void valueChanged(const QVariant &); |
218 | void propertiesChanged(const QString &); |
219 | void targetChanged(); |
220 | void propertyChanged(); |
221 | |
222 | protected: |
223 | QAbstractAnimationJob* transition(QQuickStateActions &actions, |
224 | QQmlProperties &modified, |
225 | TransitionDirection direction, |
226 | QObject *defaultTarget = nullptr) override; |
227 | }; |
228 | |
229 | class QQuickPropertyAnimationPrivate; |
230 | class Q_QUICK_PRIVATE_EXPORT QQuickPropertyAnimation : public QQuickAbstractAnimation |
231 | { |
232 | Q_OBJECT |
233 | Q_DECLARE_PRIVATE(QQuickPropertyAnimation) |
234 | |
235 | Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged FINAL) |
236 | Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged) |
237 | Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged) |
238 | Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged FINAL) |
239 | Q_PROPERTY(QObject *target READ target WRITE setTargetObject NOTIFY targetChanged FINAL) |
240 | Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged FINAL) |
241 | Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged FINAL) |
242 | Q_PROPERTY(QQmlListProperty<QObject> targets READ targets FINAL) |
243 | Q_PROPERTY(QQmlListProperty<QObject> exclude READ exclude FINAL) |
244 | QML_NAMED_ELEMENT(PropertyAnimation) |
245 | QML_ADDED_IN_VERSION(2, 0) |
246 | |
247 | public: |
248 | QQuickPropertyAnimation(QObject *parent=nullptr); |
249 | ~QQuickPropertyAnimation() override; |
250 | |
251 | virtual int duration() const; |
252 | virtual void setDuration(int); |
253 | |
254 | QVariant from() const; |
255 | void setFrom(const QVariant &); |
256 | |
257 | QVariant to() const; |
258 | void setTo(const QVariant &); |
259 | |
260 | QEasingCurve easing() const; |
261 | void setEasing(const QEasingCurve &); |
262 | |
263 | QObject *target() const; |
264 | void setTargetObject(QObject *); |
265 | |
266 | QString property() const; |
267 | void setProperty(const QString &); |
268 | |
269 | QString properties() const; |
270 | void setProperties(const QString &); |
271 | |
272 | QQmlListProperty<QObject> targets(); |
273 | QQmlListProperty<QObject> exclude(); |
274 | |
275 | protected: |
276 | QQuickStateActions createTransitionActions(QQuickStateActions &actions, |
277 | QQmlProperties &modified, |
278 | QObject *defaultTarget = nullptr); |
279 | |
280 | QQuickPropertyAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent); |
281 | QAbstractAnimationJob* transition(QQuickStateActions &actions, |
282 | QQmlProperties &modified, |
283 | TransitionDirection direction, |
284 | QObject *defaultTarget = nullptr) override; |
285 | Q_SIGNALS: |
286 | void durationChanged(int); |
287 | void fromChanged(); |
288 | void toChanged(); |
289 | void easingChanged(const QEasingCurve &); |
290 | void propertiesChanged(const QString &); |
291 | void targetChanged(); |
292 | void propertyChanged(); |
293 | }; |
294 | |
295 | class Q_QUICK_PRIVATE_EXPORT QQuickColorAnimation : public QQuickPropertyAnimation |
296 | { |
297 | Q_OBJECT |
298 | Q_DECLARE_PRIVATE(QQuickPropertyAnimation) |
299 | Q_PROPERTY(QColor from READ from WRITE setFrom FINAL) |
300 | Q_PROPERTY(QColor to READ to WRITE setTo FINAL) |
301 | QML_NAMED_ELEMENT(ColorAnimation) |
302 | QML_ADDED_IN_VERSION(2, 0) |
303 | |
304 | public: |
305 | QQuickColorAnimation(QObject *parent=nullptr); |
306 | ~QQuickColorAnimation() override; |
307 | |
308 | QColor from() const; |
309 | void setFrom(const QColor &); |
310 | |
311 | QColor to() const; |
312 | void setTo(const QColor &); |
313 | }; |
314 | |
315 | class Q_QUICK_PRIVATE_EXPORT QQuickNumberAnimation : public QQuickPropertyAnimation |
316 | { |
317 | Q_OBJECT |
318 | Q_DECLARE_PRIVATE(QQuickPropertyAnimation) |
319 | |
320 | Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged FINAL) |
321 | Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged FINAL) |
322 | QML_NAMED_ELEMENT(NumberAnimation) |
323 | QML_ADDED_IN_VERSION(2, 0) |
324 | |
325 | public: |
326 | QQuickNumberAnimation(QObject *parent=nullptr); |
327 | ~QQuickNumberAnimation() override; |
328 | |
329 | qreal from() const; |
330 | void setFrom(qreal); |
331 | |
332 | qreal to() const; |
333 | void setTo(qreal); |
334 | |
335 | protected: |
336 | QQuickNumberAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent); |
337 | |
338 | private: |
339 | void init(); |
340 | }; |
341 | |
342 | class Q_QUICK_PRIVATE_EXPORT QQuickVector3dAnimation : public QQuickPropertyAnimation |
343 | { |
344 | Q_OBJECT |
345 | Q_DECLARE_PRIVATE(QQuickPropertyAnimation) |
346 | |
347 | Q_PROPERTY(QVector3D from READ from WRITE setFrom NOTIFY fromChanged FINAL) |
348 | Q_PROPERTY(QVector3D to READ to WRITE setTo NOTIFY toChanged FINAL) |
349 | QML_NAMED_ELEMENT(Vector3dAnimation) |
350 | QML_ADDED_IN_VERSION(2, 0) |
351 | |
352 | public: |
353 | QQuickVector3dAnimation(QObject *parent=nullptr); |
354 | ~QQuickVector3dAnimation() override; |
355 | |
356 | QVector3D from() const; |
357 | void setFrom(QVector3D); |
358 | |
359 | QVector3D to() const; |
360 | void setTo(QVector3D); |
361 | }; |
362 | |
363 | class QQuickRotationAnimationPrivate; |
364 | class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimation : public QQuickPropertyAnimation |
365 | { |
366 | Q_OBJECT |
367 | Q_DECLARE_PRIVATE(QQuickRotationAnimation) |
368 | |
369 | Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged FINAL) |
370 | Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged FINAL) |
371 | Q_PROPERTY(RotationDirection direction READ direction WRITE setDirection NOTIFY directionChanged FINAL) |
372 | QML_NAMED_ELEMENT(RotationAnimation) |
373 | QML_ADDED_IN_VERSION(2, 0) |
374 | |
375 | public: |
376 | QQuickRotationAnimation(QObject *parent=nullptr); |
377 | ~QQuickRotationAnimation() override; |
378 | |
379 | qreal from() const; |
380 | void setFrom(qreal); |
381 | |
382 | qreal to() const; |
383 | void setTo(qreal); |
384 | |
385 | enum RotationDirection { Numerical, Shortest, Clockwise, Counterclockwise }; |
386 | Q_ENUM(RotationDirection) |
387 | RotationDirection direction() const; |
388 | void setDirection(RotationDirection direction); |
389 | |
390 | Q_SIGNALS: |
391 | void directionChanged(); |
392 | }; |
393 | |
394 | class QQuickAnimationGroupPrivate; |
395 | class Q_QUICK_PRIVATE_EXPORT QQuickAnimationGroup : public QQuickAbstractAnimation |
396 | { |
397 | Q_OBJECT |
398 | Q_DECLARE_PRIVATE(QQuickAnimationGroup) |
399 | |
400 | Q_CLASSINFO("DefaultProperty" , "animations" ) |
401 | Q_PROPERTY(QQmlListProperty<QQuickAbstractAnimation> animations READ animations FINAL) |
402 | |
403 | public: |
404 | QQuickAnimationGroup(QObject *parent); |
405 | ~QQuickAnimationGroup() override; |
406 | |
407 | QQmlListProperty<QQuickAbstractAnimation> animations(); |
408 | friend class QQuickAbstractAnimation; |
409 | |
410 | protected: |
411 | QQuickAnimationGroup(QQuickAnimationGroupPrivate &dd, QObject *parent); |
412 | }; |
413 | |
414 | class Q_QUICK_PRIVATE_EXPORT QQuickSequentialAnimation : public QQuickAnimationGroup |
415 | { |
416 | Q_OBJECT |
417 | Q_DECLARE_PRIVATE(QQuickAnimationGroup) |
418 | QML_NAMED_ELEMENT(SequentialAnimation) |
419 | QML_ADDED_IN_VERSION(2, 0) |
420 | |
421 | public: |
422 | QQuickSequentialAnimation(QObject *parent=nullptr); |
423 | ~QQuickSequentialAnimation() override; |
424 | |
425 | protected: |
426 | ThreadingModel threadingModel() const override; |
427 | QAbstractAnimationJob* transition(QQuickStateActions &actions, |
428 | QQmlProperties &modified, |
429 | TransitionDirection direction, |
430 | QObject *defaultTarget = nullptr) override; |
431 | }; |
432 | |
433 | class Q_QUICK_PRIVATE_EXPORT QQuickParallelAnimation : public QQuickAnimationGroup |
434 | { |
435 | Q_OBJECT |
436 | Q_DECLARE_PRIVATE(QQuickAnimationGroup) |
437 | QML_NAMED_ELEMENT(ParallelAnimation) |
438 | QML_ADDED_IN_VERSION(2, 0) |
439 | |
440 | public: |
441 | QQuickParallelAnimation(QObject *parent=nullptr); |
442 | ~QQuickParallelAnimation() override; |
443 | |
444 | protected: |
445 | ThreadingModel threadingModel() const override; |
446 | QAbstractAnimationJob* transition(QQuickStateActions &actions, |
447 | QQmlProperties &modified, |
448 | TransitionDirection direction, |
449 | QObject *defaultTarget = nullptr) override; |
450 | }; |
451 | |
452 | |
453 | QT_END_NAMESPACE |
454 | |
455 | QML_DECLARE_TYPE(QQuickAbstractAnimation) |
456 | QML_DECLARE_TYPE(QQuickPauseAnimation) |
457 | QML_DECLARE_TYPE(QQuickScriptAction) |
458 | QML_DECLARE_TYPE(QQuickPropertyAction) |
459 | QML_DECLARE_TYPE(QQuickPropertyAnimation) |
460 | QML_DECLARE_TYPE(QQuickColorAnimation) |
461 | QML_DECLARE_TYPE(QQuickNumberAnimation) |
462 | QML_DECLARE_TYPE(QQuickSequentialAnimation) |
463 | QML_DECLARE_TYPE(QQuickParallelAnimation) |
464 | QML_DECLARE_TYPE(QQuickVector3dAnimation) |
465 | QML_DECLARE_TYPE(QQuickRotationAnimation) |
466 | |
467 | #endif // QQUICKANIMATION_H |
468 | |