Qt 4.8
qanimationgroup.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 QtCore 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 
88 #include "qanimationgroup.h"
89 #include <QtCore/qdebug.h>
90 #include <QtCore/qcoreevent.h>
91 #include "qanimationgroup_p.h"
92 
93 #ifndef QT_NO_ANIMATION
94 
96 
97 
104 {
105 }
106 
111  : QAbstractAnimation(dd, parent)
112 {
113 }
114 
119 {
120 }
121 
130 {
131  Q_D(const QAnimationGroup);
132 
133  if (index < 0 || index >= d->animations.size()) {
134  qWarning("QAnimationGroup::animationAt: index is out of bounds");
135  return 0;
136  }
137 
138  return d->animations.at(index);
139 }
140 
141 
148 {
149  Q_D(const QAnimationGroup);
150  return d->animations.size();
151 }
152 
160 {
161  Q_D(const QAnimationGroup);
162  return d->animations.indexOf(animation);
163 }
164 
174 {
176  insertAnimation(d->animations.count(), animation);
177 }
178 
189 {
191 
192  if (index < 0 || index > d->animations.size()) {
193  qWarning("QAnimationGroup::insertAnimation: index is out of bounds");
194  return;
195  }
196 
197  if (QAnimationGroup *oldGroup = animation->group())
198  oldGroup->removeAnimation(animation);
199 
200  d->animations.insert(index, animation);
201  QAbstractAnimationPrivate::get(animation)->group = this;
202  // this will make sure that ChildAdded event is sent to 'this'
203  animation->setParent(this);
204  d->animationInsertedAt(index);
205 }
206 
214 {
216 
217  if (!animation) {
218  qWarning("QAnimationGroup::remove: cannot remove null animation");
219  return;
220  }
221  int index = d->animations.indexOf(animation);
222  if (index == -1) {
223  qWarning("QAnimationGroup::remove: animation is not part of this group");
224  return;
225  }
226 
227  takeAnimation(index);
228 }
229 
238 {
240  if (index < 0 || index >= d->animations.size()) {
241  qWarning("QAnimationGroup::takeAnimation: no animation at index %d", index);
242  return 0;
243  }
244  QAbstractAnimation *animation = d->animations.at(index);
245  QAbstractAnimationPrivate::get(animation)->group = 0;
246  // ### removing from list before doing setParent to avoid inifinite recursion
247  // in ChildRemoved event
248  d->animations.removeAt(index);
249  animation->setParent(0);
250  d->animationRemoved(index, animation);
251  return animation;
252 }
253 
261 {
263  qDeleteAll(d->animations);
264 }
265 
270 {
272  if (event->type() == QEvent::ChildAdded) {
273  QChildEvent *childEvent = static_cast<QChildEvent *>(event);
274  if (QAbstractAnimation *a = qobject_cast<QAbstractAnimation *>(childEvent->child())) {
275  if (a->group() != this)
276  addAnimation(a);
277  }
278  } else if (event->type() == QEvent::ChildRemoved) {
279  QChildEvent *childEvent = static_cast<QChildEvent *>(event);
280  QAbstractAnimation *a = static_cast<QAbstractAnimation *>(childEvent->child());
281  // You can only rely on the child being a QObject because in the QEvent::ChildRemoved
282  // case it might be called from the destructor.
283  int index = d->animations.indexOf(a);
284  if (index != -1)
285  takeAnimation(index);
286  }
287  return QAbstractAnimation::event(event);
288 }
289 
290 
292 {
294  Q_UNUSED(index);
295  if (animations.isEmpty()) {
296  currentTime = 0;
297  q->stop();
298  }
299 }
300 
302 
303 #include "moc_qanimationgroup.cpp"
304 
305 #endif //QT_NO_ANIMATION
double d
Definition: qnumeric_p.h:62
QAbstractAnimation * animationAt(int index) const
Returns a pointer to the animation at index in this group.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void insertAnimation(int index, QAbstractAnimation *animation)
Inserts animation into this animation group at index.
QAbstractAnimation * takeAnimation(int index)
Returns the animation at index and removes it from the animation group.
int animationCount() const
Returns the number of animations managed by this group.
static QAbstractAnimationPrivate * get(QAbstractAnimation *q)
long ASN1_INTEGER_get ASN1_INTEGER * a
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
#define Q_Q(Class)
Definition: qglobal.h:2483
int currentTime() const
QAnimationGroup * group() const
If this animation is part of a QAnimationGroup, this function returns a pointer to the group; otherwi...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void clear()
Removes and deletes all animations in this animation group, and resets the current time to 0...
void addAnimation(QAbstractAnimation *animation)
Adds animation to this group.
virtual void childEvent(QChildEvent *)
This event handler can be reimplemented in a subclass to receive child events.
Definition: qobject.cpp:1332
Q_CORE_EXPORT void qWarning(const char *,...)
void removeAnimation(QAbstractAnimation *animation)
Removes animation from this group.
The QAbstractAnimation class is the base of all animations.
~QAnimationGroup()
Destroys the animation group.
bool event(QEvent *event)
Reimplemented Function
The QChildEvent class contains event parameters for child object events.
Definition: qcoreevent.h:353
virtual void animationRemoved(int, QAbstractAnimation *)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QAnimationGroup(QObject *parent=0)
Constructs a QAnimationGroup.
bool event(QEvent *event)
Reimplemented Function
int indexOfAnimation(QAbstractAnimation *animation) const
Returns the index of animation.
quint16 index
The QAnimationGroup class is an abstract base class for groups of animations.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QObject * child() const
Returns the child object that was added or removed.
Definition: qcoreevent.h:358