1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtQml module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#ifndef QQUICKANIMATION2_P_H
43
#define QQUICKANIMATION2_P_H
49
// This file is not part of the Qt API. It exists purely as an
50
// implementation detail. This header file may change from version to
51
// version without notice, or even be removed.
56
#include "qquickanimation_p.h"
58
#include <private/qqmlnullablevalue_p_p.h>
61
#include <qqmlcontext.h>
63
#include <private/qvariantanimation_p.h>
64
#include "private/qpauseanimationjob_p.h"
67
#include <private/qobject_p.h>
68
#include "private/qanimationgroupjob_p.h"
71
#include <private/qobject_p.h>
76
//interface for classes that provide animation actions for QActionAnimation
77
class QAbstractAnimationAction
80
virtual ~QAbstractAnimationAction() {}
81
virtual void doAction() = 0;
84
//templated animation action
85
//allows us to specify an action that calls a function of a class.
86
//(so that class doesn't have to inherit QQuickAbstractAnimationAction)
87
template<class T, void (T::*method)()>
88
class QAnimationActionProxy : public QAbstractAnimationAction
91
QAnimationActionProxy(T *instance) : m_instance(instance) {}
92
virtual void doAction() { (m_instance->*method)(); }
98
//performs an action of type QAbstractAnimationAction
99
class Q_AUTOTEST_EXPORT QActionAnimation : public QAbstractAnimationJob
101
Q_DISABLE_COPY(QActionAnimation)
105
QActionAnimation(QAbstractAnimationAction *action);
108
virtual int duration() const;
109
void setAnimAction(QAbstractAnimationAction *action);
112
virtual void updateCurrentTime(int);
113
virtual void updateState(State newState, State oldState);
116
QAbstractAnimationAction *animAction;
119
class QQuickBulkValueUpdater
122
virtual ~QQuickBulkValueUpdater() {}
123
virtual void setValue(qreal value) = 0;
126
//animates QQuickBulkValueUpdater (assumes start and end values will be reals or compatible)
127
class Q_AUTOTEST_EXPORT QQuickBulkValueAnimator : public QAbstractAnimationJob
129
Q_DISABLE_COPY(QQuickBulkValueAnimator)
131
QQuickBulkValueAnimator();
132
~QQuickBulkValueAnimator();
134
void setAnimValue(QQuickBulkValueUpdater *value);
135
QQuickBulkValueUpdater *getAnimValue() const { return animValue; }
137
void setFromSourcedValue(bool *value) { fromSourced = value; }
139
int duration() const { return m_duration; }
140
void setDuration(int msecs) { m_duration = msecs; }
142
QEasingCurve easingCurve() const { return easing; }
143
void setEasingCurve(const QEasingCurve &curve) { easing = curve; }
146
void updateCurrentTime(int currentTime);
147
void topLevelAnimationLoopChanged();
150
QQuickBulkValueUpdater *animValue;
156
//an animation that just gives a tick
157
template<class T, void (T::*method)(int)>
158
class QTickAnimationProxy : public QAbstractAnimationJob
160
Q_DISABLE_COPY(QTickAnimationProxy)
162
QTickAnimationProxy(T *instance) : QAbstractAnimationJob(), m_instance(instance) {}
163
virtual int duration() const { return -1; }
165
virtual void updateCurrentTime(int msec) { (m_instance->*method)(msec); }
171
class QQuickAbstractAnimationPrivate : public QObjectPrivate, public QAnimationJobChangeListener
173
Q_DECLARE_PUBLIC(QQuickAbstractAnimation)
175
QQuickAbstractAnimationPrivate()
176
: running(false), paused(false), alwaysRunToEnd(false),
177
/*connectedTimeLine(false), */componentComplete(true),
178
avoidPropertyValueSourceStart(false), disableUserControl(false),
179
registered(false), loopCount(1), group(0), animationInstance(0) {}
183
bool alwaysRunToEnd:1;
184
//bool connectedTimeLine:1;
185
bool componentComplete:1;
186
bool avoidPropertyValueSourceStart:1;
187
bool disableUserControl:1;
193
virtual void animationFinished(QAbstractAnimationJob *);
195
QQmlProperty defaultProperty;
197
QQuickAnimationGroup *group;
198
QAbstractAnimationJob* animationInstance;
200
static QQmlProperty createProperty(QObject *obj, const QString &str, QObject *infoObj);
203
class QQuickPauseAnimationPrivate : public QQuickAbstractAnimationPrivate
205
Q_DECLARE_PUBLIC(QQuickPauseAnimation)
207
QQuickPauseAnimationPrivate()
208
: QQuickAbstractAnimationPrivate(), duration(250) {}
213
class QQuickScriptActionPrivate : public QQuickAbstractAnimationPrivate
215
Q_DECLARE_PUBLIC(QQuickScriptAction)
217
QQuickScriptActionPrivate();
219
QQmlScriptString script;
221
QQmlScriptString runScriptScript;
222
bool hasRunScriptScript;
226
QAbstractAnimationAction* createAction();
227
typedef QAnimationActionProxy<QQuickScriptActionPrivate,
228
&QQuickScriptActionPrivate::execute> Proxy;
231
class QQuickPropertyActionPrivate : public QQuickAbstractAnimationPrivate
233
Q_DECLARE_PUBLIC(QQuickPropertyAction)
235
QQuickPropertyActionPrivate()
236
: QQuickAbstractAnimationPrivate(), target(0) {}
239
QString propertyName;
241
QList<QObject *> targets;
242
QList<QObject *> exclude;
244
QQmlNullableValue<QVariant> value;
247
class QQuickAnimationGroupPrivate : public QQuickAbstractAnimationPrivate
249
Q_DECLARE_PUBLIC(QQuickAnimationGroup)
251
QQuickAnimationGroupPrivate()
252
: QQuickAbstractAnimationPrivate() {}
254
static void append_animation(QQmlListProperty<QQuickAbstractAnimation> *list, QQuickAbstractAnimation *role);
255
static void clear_animation(QQmlListProperty<QQuickAbstractAnimation> *list);
256
QList<QQuickAbstractAnimation *> animations;
259
class QQuickPropertyAnimationPrivate : public QQuickAbstractAnimationPrivate
261
Q_DECLARE_PUBLIC(QQuickPropertyAnimation)
263
QQuickPropertyAnimationPrivate()
264
: QQuickAbstractAnimationPrivate(), target(0), fromSourced(false), fromIsDefined(false), toIsDefined(false),
265
defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), duration(250), actions(0) {}
271
QString propertyName;
273
QList<QObject *> targets;
274
QList<QObject *> exclude;
275
QString defaultProperties;
278
bool fromIsDefined:1;
280
bool defaultToInterpolatorType:1;
281
int interpolatorType;
282
QVariantAnimation::Interpolator interpolator;
286
// for animations that don't use the QQuickBulkValueAnimator
287
QQuickStateActions *actions;
289
static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress);
290
static void convertVariant(QVariant &variant, int type);
293
class QQuickRotationAnimationPrivate : public QQuickPropertyAnimationPrivate
295
Q_DECLARE_PUBLIC(QQuickRotationAnimation)
297
QQuickRotationAnimationPrivate() : direction(QQuickRotationAnimation::Numerical) {}
299
QQuickRotationAnimation::RotationDirection direction;
302
class Q_AUTOTEST_EXPORT QQuickAnimationPropertyUpdater : public QQuickBulkValueUpdater
305
QQuickAnimationPropertyUpdater() : interpolatorType(0), interpolator(0), prevInterpolatorType(0), reverse(false), fromSourced(false), fromDefined(false), wasDeleted(0) {}
306
~QQuickAnimationPropertyUpdater() { if (wasDeleted) *wasDeleted = true; }
308
void setValue(qreal v);
310
QQuickStateActions actions;
311
int interpolatorType; //for Number/ColorAnimation
312
QVariantAnimation::Interpolator interpolator;
313
int prevInterpolatorType; //for generic
322
#endif // QQUICKANIMATION2_P_H