Qt 4.8
qdeclarativeanimation_p_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative 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 QDECLARATIVEANIMATION_P_H
43 #define QDECLARATIVEANIMATION_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 "private/qdeclarativeanimation_p.h"
57 
58 #include "private/qdeclarativenullablevalue_p_p.h"
59 #include "private/qdeclarativetimeline_p_p.h"
60 
61 #include <qdeclarative.h>
62 #include <qdeclarativeitem.h>
63 #include <qdeclarativecontext.h>
64 
65 #include <QtCore/QPauseAnimation>
66 #include <QtCore/QVariantAnimation>
67 #include <QtCore/QAnimationGroup>
68 #include <QtGui/QColor>
69 #include <QDebug>
70 
71 #include <private/qobject_p.h>
72 #include <private/qvariantanimation_p.h>
73 
75 
76 //interface for classes that provide animation actions for QActionAnimation
78 {
79 public:
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 QDeclarativeAbstractAnimationAction)
87 template<class T, void (T::*method)()>
89 {
90 public:
91  QAnimationActionProxy(T *p) : m_p(p) {}
92  virtual void doAction() { (m_p->*method)(); }
93 
94 private:
95  T *m_p;
96 };
97 
98 //performs an action of type QAbstractAnimationAction
100 {
101  Q_OBJECT
102 public:
103  QActionAnimation(QObject *parent = 0) : QAbstractAnimation(parent), animAction(0), policy(KeepWhenStopped) {}
105  : QAbstractAnimation(parent), animAction(action), policy(KeepWhenStopped) {}
106  ~QActionAnimation() { if (policy == DeleteWhenStopped) { delete animAction; animAction = 0; } }
107  virtual int duration() const { return 0; }
109  {
110  if (state() == Running)
111  stop();
112  if (policy == DeleteWhenStopped)
113  delete animAction;
114  animAction = action;
115  policy = p;
116  }
117 protected:
118  virtual void updateCurrentTime(int) {}
119 
120  virtual void updateState(State newState, State /*oldState*/)
121  {
122  if (newState == Running) {
123  if (animAction) {
124  animAction->doAction();
125  if (state() == Stopped && policy == DeleteWhenStopped) {
126  delete animAction;
127  animAction = 0;
128  }
129  }
130  }
131  }
132 
133 private:
136 };
137 
139 {
140 public:
142  virtual void setValue(qreal value) = 0;
143 };
144 
145 //animates QDeclarativeBulkValueUpdater (assumes start and end values will be reals or compatible)
147 {
148  Q_OBJECT
149 public:
150  QDeclarativeBulkValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {}
151  ~QDeclarativeBulkValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } }
153  {
154  if (state() == Running)
155  stop();
156  if (policy == DeleteWhenStopped)
157  delete animValue;
158  animValue = value;
159  policy = p;
160  }
161  void setFromSourcedValue(bool *value)
162  {
163  fromSourced = value;
164  }
165 protected:
166  virtual void updateCurrentValue(const QVariant &value)
167  {
168  if (state() == QAbstractAnimation::Stopped)
169  return;
170 
171  if (animValue)
172  animValue->setValue(value.toReal());
173  }
174  virtual void updateState(State newState, State oldState)
175  {
176  QVariantAnimation::updateState(newState, oldState);
177  if (newState == Running) {
178  //check for new from every loop
179  if (fromSourced)
180  *fromSourced = false;
181  }
182  }
183 
184 private:
186  bool *fromSourced;
188 };
189 
190 //an animation that just gives a tick
191 template<class T, void (T::*method)(int)>
193 {
194  //Q_OBJECT //doesn't work with templating
195 public:
196  QTickAnimationProxy(T *p, QObject *parent = 0) : QAbstractAnimation(parent), m_p(p) {}
197  virtual int duration() const { return -1; }
198 protected:
199  virtual void updateCurrentTime(int msec) { (m_p->*method)(msec); }
200 
201 private:
202  T *m_p;
203 };
204 
206 {
208 public:
210  : running(false), paused(false), alwaysRunToEnd(false),
211  connectedTimeLine(false), componentComplete(true),
212  avoidPropertyValueSourceStart(false), disableUserControl(false),
213  registered(false), loopCount(1), group(0) {}
214 
215  bool running:1;
216  bool paused:1;
222  bool registered:1;
223 
225 
226  void commence();
227 
229 
231 
232  static QDeclarativeProperty createProperty(QObject *obj, const QString &str, QObject *infoObj);
233 };
234 
236 {
238 public:
241 
242  void init();
243 
245 };
246 
248 {
250 public:
252 
253  void init();
254 
259  bool reversing;
260 
261  void execute();
262 
266 };
267 
269 {
271 public:
273  : QDeclarativeAbstractAnimationPrivate(), target(0), spa(0) {}
274 
275  void init();
276 
282 
284 
286 };
287 
289 {
291 public:
294 
296  static void clear_animation(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list);
299 };
300 
302 {
304 public:
306  : QDeclarativeAbstractAnimationPrivate(), target(0), fromSourced(false), fromIsDefined(false), toIsDefined(false),
307  rangeIsSet(false), defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), va(0), actions(0) {}
308 
309  void init();
310 
313 
320 
323  bool toIsDefined:1;
324  bool rangeIsSet:1;
328 
330 
331  // for animations that don't use the QDeclarativeBulkValueAnimator
333 
334  static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress);
335  static void convertVariant(QVariant &variant, int type);
336 };
337 
339 {
341 public:
343 
345 };
346 
348 {
350 public:
352  : QDeclarativeAnimationGroupPrivate(), target(0), newParent(0),
353  via(0), topLevelGroup(0), startAction(0), endAction(0) {}
354 
358 
362 
363  QPointF computeTransformOrigin(QDeclarativeItem::TransformOrigin origin, qreal width, qreal height) const;
364 };
365 
367 {
369 public:
370  QDeclarativeAnchorAnimationPrivate() : rangeIsSet(false), va(0),
371  interpolator(QVariantAnimationPrivate::getInterpolator(QMetaType::QReal)) {}
372 
377 };
378 
380 {
381 public:
383  int interpolatorType; //for Number/ColorAnimation
384  int prevInterpolatorType; //for generic
386  bool reverse;
389  bool *wasDeleted;
390  QDeclarativeAnimationPropertyUpdater() : prevInterpolatorType(0), wasDeleted(0) {}
391  ~QDeclarativeAnimationPropertyUpdater() { if (wasDeleted) *wasDeleted = true; }
392  void setValue(qreal v);
393 };
394 
396 
397 #endif // QDECLARATIVEANIMATION_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void setAnimValue(QDeclarativeBulkValueUpdater *value, DeletionPolicy p)
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual int duration() const
The QSequentialAnimationGroup class provides a sequential group of animations.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QActionAnimation(QAbstractAnimationAction *action, QObject *parent=0)
The QPauseAnimation class provides a pause for QSequentialAnimationGroup.
QVariantAnimation::Interpolator interpolator
QVariantAnimation::Interpolator interpolator
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual void updateCurrentTime(int)
This pure virtual function is called every time the animation&#39;s currentTime changes.
QDeclarativeBulkValueUpdater * animValue
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual void updateState(State newState, State oldState)
QVariant(* Interpolator)(const void *from, const void *to, qreal progress)
virtual int duration() const
QDeclarativeNullableValue< QVariant > value
virtual void updateState(State newState, State)
virtual void doAction()=0
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QTickAnimationProxy(T *p, QObject *parent=0)
QAnimationActionProxy< QDeclarativeScriptActionPrivate, &QDeclarativeScriptActionPrivate::execute > proxy
The QDeclarativeScriptString class encapsulates a script and its context.
QDeclarativeBulkValueAnimator * va
The QDeclarativeItem class provides the most basic of all visual items in QML.
The QVariantAnimation class provides an abstract base class for animations.
static bool init
QAbstractAnimationAction * animAction
QList< QDeclarativeAbstractAnimation * > animations
The State element defines configurations of objects and properties.
The QAbstractAnimation class is the base of all animations.
#define Q_OBJECT
Definition: qobjectdefs.h:157
QActionAnimation(QObject *parent=0)
The QMetaType class manages named types in the meta-object system.
Definition: qmetatype.h:62
QVariantAnimation::Interpolator interpolator
TransformOrigin
Controls the point about which simple transforms like scale apply.
QDeclarativeRotationAnimation::RotationDirection direction
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
virtual void updateCurrentTime(int msec)
This pure virtual function is called every time the animation&#39;s currentTime changes.
void setAnimAction(QAbstractAnimationAction *action, DeletionPolicy p)
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
Reimplemented Function
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
The QDeclarativeProperty class abstracts accessing properties on objects created from QML...
virtual void updateCurrentValue(const QVariant &value)
This pure virtual function is called every time the animation&#39;s current value changes.
const char * variant
The QAnimationGroup class is an abstract base class for groups of animations.
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Qt::LayoutDirection direction