~ubuntu-branches/ubuntu/saucy/qtdeclarative-opensource-src/saucy

« back to all changes in this revision

Viewing changes to src/quick/util/qquickanimation_p_p.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 14:17:19 UTC
  • Revision ID: package-import@ubuntu.com-20130205141719-qqeyml8wslpyez52
Tags: upstream-5.0.1
ImportĀ upstreamĀ versionĀ 5.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtQml module of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
24
**
 
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.
 
28
**
 
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.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QQUICKANIMATION2_P_H
 
43
#define QQUICKANIMATION2_P_H
 
44
 
 
45
//
 
46
//  W A R N I N G
 
47
//  -------------
 
48
//
 
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.
 
52
//
 
53
// We mean it.
 
54
//
 
55
 
 
56
#include "qquickanimation_p.h"
 
57
 
 
58
#include <private/qqmlnullablevalue_p_p.h>
 
59
 
 
60
#include <qqml.h>
 
61
#include <qqmlcontext.h>
 
62
 
 
63
#include <private/qvariantanimation_p.h>
 
64
#include "private/qpauseanimationjob_p.h"
 
65
#include <QDebug>
 
66
 
 
67
#include <private/qobject_p.h>
 
68
#include "private/qanimationgroupjob_p.h"
 
69
#include <QDebug>
 
70
 
 
71
#include <private/qobject_p.h>
 
72
 
 
73
 
 
74
QT_BEGIN_NAMESPACE
 
75
 
 
76
//interface for classes that provide animation actions for QActionAnimation
 
77
class QAbstractAnimationAction
 
78
{
 
79
public:
 
80
    virtual ~QAbstractAnimationAction() {}
 
81
    virtual void doAction() = 0;
 
82
};
 
83
 
 
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
 
89
{
 
90
public:
 
91
    QAnimationActionProxy(T *instance) : m_instance(instance) {}
 
92
    virtual void doAction() { (m_instance->*method)(); }
 
93
 
 
94
private:
 
95
    T *m_instance;
 
96
};
 
97
 
 
98
//performs an action of type QAbstractAnimationAction
 
99
class Q_AUTOTEST_EXPORT QActionAnimation : public QAbstractAnimationJob
 
100
{
 
101
    Q_DISABLE_COPY(QActionAnimation)
 
102
public:
 
103
    QActionAnimation();
 
104
 
 
105
    QActionAnimation(QAbstractAnimationAction *action);
 
106
    ~QActionAnimation();
 
107
 
 
108
    virtual int duration() const;
 
109
    void setAnimAction(QAbstractAnimationAction *action);
 
110
 
 
111
protected:
 
112
    virtual void updateCurrentTime(int);
 
113
    virtual void updateState(State newState, State oldState);
 
114
 
 
115
private:
 
116
    QAbstractAnimationAction *animAction;
 
117
};
 
118
 
 
119
class QQuickBulkValueUpdater
 
120
{
 
121
public:
 
122
    virtual ~QQuickBulkValueUpdater() {}
 
123
    virtual void setValue(qreal value) = 0;
 
124
};
 
125
 
 
126
//animates QQuickBulkValueUpdater (assumes start and end values will be reals or compatible)
 
127
class Q_AUTOTEST_EXPORT QQuickBulkValueAnimator : public QAbstractAnimationJob
 
128
{
 
129
    Q_DISABLE_COPY(QQuickBulkValueAnimator)
 
130
public:
 
131
    QQuickBulkValueAnimator();
 
132
    ~QQuickBulkValueAnimator();
 
133
 
 
134
    void setAnimValue(QQuickBulkValueUpdater *value);
 
135
    QQuickBulkValueUpdater *getAnimValue() const { return animValue; }
 
136
 
 
137
    void setFromSourcedValue(bool *value) { fromSourced = value; }
 
138
 
 
139
    int duration() const { return m_duration; }
 
140
    void setDuration(int msecs) { m_duration = msecs; }
 
141
 
 
142
    QEasingCurve easingCurve() const { return easing; }
 
143
    void setEasingCurve(const QEasingCurve &curve) { easing = curve; }
 
144
 
 
145
protected:
 
146
    void updateCurrentTime(int currentTime);
 
147
    void topLevelAnimationLoopChanged();
 
148
 
 
149
private:
 
150
    QQuickBulkValueUpdater *animValue;
 
151
    bool *fromSourced;
 
152
    int m_duration;
 
153
    QEasingCurve easing;
 
154
};
 
155
 
 
156
//an animation that just gives a tick
 
157
template<class T, void (T::*method)(int)>
 
158
class QTickAnimationProxy : public QAbstractAnimationJob
 
159
{
 
160
    Q_DISABLE_COPY(QTickAnimationProxy)
 
161
public:
 
162
    QTickAnimationProxy(T *instance) : QAbstractAnimationJob(), m_instance(instance) {}
 
163
    virtual int duration() const { return -1; }
 
164
protected:
 
165
    virtual void updateCurrentTime(int msec) { (m_instance->*method)(msec); }
 
166
 
 
167
private:
 
168
    T *m_instance;
 
169
};
 
170
 
 
171
class QQuickAbstractAnimationPrivate : public QObjectPrivate, public QAnimationJobChangeListener
 
172
{
 
173
    Q_DECLARE_PUBLIC(QQuickAbstractAnimation)
 
174
public:
 
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) {}
 
180
 
 
181
    bool running:1;
 
182
    bool paused:1;
 
183
    bool alwaysRunToEnd:1;
 
184
    //bool connectedTimeLine:1;
 
185
    bool componentComplete:1;
 
186
    bool avoidPropertyValueSourceStart:1;
 
187
    bool disableUserControl:1;
 
188
    bool registered:1;
 
189
 
 
190
    int loopCount;
 
191
 
 
192
    void commence();
 
193
    virtual void animationFinished(QAbstractAnimationJob *);
 
194
 
 
195
    QQmlProperty defaultProperty;
 
196
 
 
197
    QQuickAnimationGroup *group;
 
198
    QAbstractAnimationJob* animationInstance;
 
199
 
 
200
    static QQmlProperty createProperty(QObject *obj, const QString &str, QObject *infoObj);
 
201
};
 
202
 
 
203
class QQuickPauseAnimationPrivate : public QQuickAbstractAnimationPrivate
 
204
{
 
205
    Q_DECLARE_PUBLIC(QQuickPauseAnimation)
 
206
public:
 
207
    QQuickPauseAnimationPrivate()
 
208
        : QQuickAbstractAnimationPrivate(), duration(250) {}
 
209
 
 
210
    int duration;
 
211
};
 
212
 
 
213
class QQuickScriptActionPrivate : public QQuickAbstractAnimationPrivate
 
214
{
 
215
    Q_DECLARE_PUBLIC(QQuickScriptAction)
 
216
public:
 
217
    QQuickScriptActionPrivate();
 
218
 
 
219
    QQmlScriptString script;
 
220
    QString name;
 
221
    QQmlScriptString runScriptScript;
 
222
    bool hasRunScriptScript;
 
223
    bool reversing;
 
224
 
 
225
    void execute();
 
226
    QAbstractAnimationAction* createAction();
 
227
    typedef QAnimationActionProxy<QQuickScriptActionPrivate,
 
228
                                 &QQuickScriptActionPrivate::execute> Proxy;
 
229
};
 
230
 
 
231
class QQuickPropertyActionPrivate : public QQuickAbstractAnimationPrivate
 
232
{
 
233
    Q_DECLARE_PUBLIC(QQuickPropertyAction)
 
234
public:
 
235
    QQuickPropertyActionPrivate()
 
236
    : QQuickAbstractAnimationPrivate(), target(0) {}
 
237
 
 
238
    QObject *target;
 
239
    QString propertyName;
 
240
    QString properties;
 
241
    QList<QObject *> targets;
 
242
    QList<QObject *> exclude;
 
243
 
 
244
    QQmlNullableValue<QVariant> value;
 
245
};
 
246
 
 
247
class QQuickAnimationGroupPrivate : public QQuickAbstractAnimationPrivate
 
248
{
 
249
    Q_DECLARE_PUBLIC(QQuickAnimationGroup)
 
250
public:
 
251
    QQuickAnimationGroupPrivate()
 
252
    : QQuickAbstractAnimationPrivate() {}
 
253
 
 
254
    static void append_animation(QQmlListProperty<QQuickAbstractAnimation> *list, QQuickAbstractAnimation *role);
 
255
    static void clear_animation(QQmlListProperty<QQuickAbstractAnimation> *list);
 
256
    QList<QQuickAbstractAnimation *> animations;
 
257
};
 
258
 
 
259
class QQuickPropertyAnimationPrivate : public QQuickAbstractAnimationPrivate
 
260
{
 
261
    Q_DECLARE_PUBLIC(QQuickPropertyAnimation)
 
262
public:
 
263
    QQuickPropertyAnimationPrivate()
 
264
    : QQuickAbstractAnimationPrivate(), target(0), fromSourced(false), fromIsDefined(false), toIsDefined(false),
 
265
      defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), duration(250), actions(0) {}
 
266
 
 
267
    QVariant from;
 
268
    QVariant to;
 
269
 
 
270
    QObject *target;
 
271
    QString propertyName;
 
272
    QString properties;
 
273
    QList<QObject *> targets;
 
274
    QList<QObject *> exclude;
 
275
    QString defaultProperties;
 
276
 
 
277
    bool fromSourced;
 
278
    bool fromIsDefined:1;
 
279
    bool toIsDefined:1;
 
280
    bool defaultToInterpolatorType:1;
 
281
    int interpolatorType;
 
282
    QVariantAnimation::Interpolator interpolator;
 
283
    int duration;
 
284
    QEasingCurve easing;
 
285
 
 
286
    // for animations that don't use the QQuickBulkValueAnimator
 
287
    QQuickStateActions *actions;
 
288
 
 
289
    static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress);
 
290
    static void convertVariant(QVariant &variant, int type);
 
291
};
 
292
 
 
293
class QQuickRotationAnimationPrivate : public QQuickPropertyAnimationPrivate
 
294
{
 
295
    Q_DECLARE_PUBLIC(QQuickRotationAnimation)
 
296
public:
 
297
    QQuickRotationAnimationPrivate() : direction(QQuickRotationAnimation::Numerical) {}
 
298
 
 
299
    QQuickRotationAnimation::RotationDirection direction;
 
300
};
 
301
 
 
302
class Q_AUTOTEST_EXPORT QQuickAnimationPropertyUpdater : public QQuickBulkValueUpdater
 
303
{
 
304
public:
 
305
    QQuickAnimationPropertyUpdater() : interpolatorType(0), interpolator(0), prevInterpolatorType(0), reverse(false), fromSourced(false), fromDefined(false), wasDeleted(0) {}
 
306
    ~QQuickAnimationPropertyUpdater() { if (wasDeleted) *wasDeleted = true; }
 
307
 
 
308
    void setValue(qreal v);
 
309
 
 
310
    QQuickStateActions actions;
 
311
    int interpolatorType;       //for Number/ColorAnimation
 
312
    QVariantAnimation::Interpolator interpolator;
 
313
    int prevInterpolatorType;   //for generic
 
314
    bool reverse;
 
315
    bool fromSourced;
 
316
    bool fromDefined;
 
317
    bool *wasDeleted;
 
318
};
 
319
 
 
320
QT_END_NAMESPACE
 
321
 
 
322
#endif // QQUICKANIMATION2_P_H