Qt 4.8
qdeclarativetransition.cpp
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 #include "private/qdeclarativestate_p.h"
43 #include "private/qdeclarativestategroup_p.h"
44 #include "private/qdeclarativestate_p_p.h"
45 #include "private/qdeclarativestateoperations_p.h"
46 #include "private/qdeclarativeanimation_p.h"
47 #include "private/qdeclarativeanimation_p_p.h"
48 #include "private/qdeclarativetransitionmanager_p_p.h"
49 
50 #include <QParallelAnimationGroup>
51 
53 
101 //ParallelAnimationWrapper allows us to do a "callback" when the animation finishes, rather than connecting
102 //and disconnecting signals and slots frequently
104 {
105  Q_OBJECT
106 public:
109 protected:
110  virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
111 };
112 
114 {
116 public:
118  : fromState(QLatin1String("*")), toState(QLatin1String("*")),
119  reversed(false), reversible(false), endState(0)
120  {
121  group.trans = this;
122  }
123 
126  bool reversed;
130 
131  void complete()
132  {
133  endState->complete();
134  }
136  static int animation_count(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list);
138  static void clear_animations(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list);
140 };
141 
143 {
144  QDeclarativeTransition *q = static_cast<QDeclarativeTransition *>(list->object);
145  q->d_func()->animations.append(a);
146  q->d_func()->group.addAnimation(a->qtAnimation());
148 }
149 
151 {
152  QDeclarativeTransition *q = static_cast<QDeclarativeTransition *>(list->object);
153  return q->d_func()->animations.count();
154 }
155 
157 {
158  QDeclarativeTransition *q = static_cast<QDeclarativeTransition *>(list->object);
159  return q->d_func()->animations.at(pos);
160 }
161 
163 {
164  QDeclarativeTransition *q = static_cast<QDeclarativeTransition *>(list->object);
165  while (q->d_func()->animations.count()) {
166  QDeclarativeAbstractAnimation *firstAnim = q->d_func()->animations.at(0);
167  q->d_func()->group.removeAnimation(firstAnim->qtAnimation());
168  q->d_func()->animations.removeAll(firstAnim);
169  }
170 }
171 
173 {
174  QParallelAnimationGroup::updateState(newState, oldState);
175  if (newState == Stopped && (duration() == -1
178  {
179  trans->complete();
180  }
181 }
182 
183 
184 
186  : QObject(*(new QDeclarativeTransitionPrivate), parent)
187 {
188 }
189 
191 {
192 }
193 
195 {
197  d->group.stop();
198 }
199 
201 {
203  d->reversed = r;
204 }
205 
209 {
211 
212  qmlExecuteDeferred(this);
213 
214  if (d->reversed) {
215  for (int ii = d->animations.count() - 1; ii >= 0; --ii) {
216  d->animations.at(ii)->transition(actions, after, QDeclarativeAbstractAnimation::Backward);
217  }
218  } else {
219  for (int ii = 0; ii < d->animations.count(); ++ii) {
220  d->animations.at(ii)->transition(actions, after, QDeclarativeAbstractAnimation::Forward);
221  }
222  }
223 
224  d->endState = endState;
225  d->group.setDirection(d->reversed ? QAbstractAnimation::Backward : QAbstractAnimation::Forward);
226  d->group.start();
227 }
228 
253 {
255  return d->fromState;
256 }
257 
259 {
261  if (f == d->fromState)
262  return;
263 
264  d->fromState = f;
265  emit fromChanged();
266 }
267 
296 {
298  return d->reversible;
299 }
300 
302 {
304  if (r == d->reversible)
305  return;
306 
307  d->reversible = r;
309 }
310 
312 {
314  return d->toState;
315 }
316 
318 {
320  if (t == d->toState)
321  return;
322 
323  d->toState = t;
324  emit toChanged();
325 }
326 
344 {
350 }
351 
353 
354 #include <qdeclarativetransition.moc>
double d
Definition: qnumeric_p.h:62
static void clear_animations(QDeclarativeListProperty< QDeclarativeAbstractAnimation > *list)
static int animation_count(QDeclarativeListProperty< QDeclarativeAbstractAnimation > *list)
virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
Reimplemented Function
void setToState(const QString &)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
State
This enum describes the state of the animation.
bool reversible() const
static QDeclarativeAbstractAnimation * animation_at(QDeclarativeListProperty< QDeclarativeAbstractAnimation > *list, int pos)
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
QDeclarativeListProperty< QDeclarativeAbstractAnimation > animations
QDeclarativeTransitionManager * endState
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
Reimplemented Function
QAnimationGroup * group() const
If this animation is part of a QAnimationGroup, this function returns a pointer to the group; otherwi...
QDeclarativeTransitionPrivate * trans
int currentLoopTime() const
Returns the current time inside the current loop.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_DECLARATIVE_EXPORT void qmlExecuteDeferred(QObject *)
#define emit
Definition: qobjectdefs.h:76
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
#define Q_OBJECT
Definition: qobjectdefs.h:157
void prepare(QDeclarativeStateOperation::ActionList &actions, QList< QDeclarativeProperty > &after, QDeclarativeTransitionManager *end)
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QParallelAnimationGroup class provides a parallel group of animations.
virtual QAbstractAnimation * qtAnimation()=0
ParallelAnimationWrapper(QObject *parent=0)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static void append_animation(QDeclarativeListProperty< QDeclarativeAbstractAnimation > *list, QDeclarativeAbstractAnimation *a)
QDeclarativeTransition(QObject *parent=0)
Direction direction() const
QList< QDeclarativeAbstractAnimation * > animations
void setFromState(const QString &)
int duration() const
Reimplemented Function
QDeclarativeListProperty< QDeclarativeAbstractAnimation > animations()
The QList class is a template class that provides lists.
Definition: qdatastream.h:62