68 \omit OK, we'll put in a snippet on this here \endomit |
68 \omit OK, we'll put in a snippet on this here \endomit |
69 |
69 |
70 QAnimationGroup provides methods for adding and retrieving |
70 QAnimationGroup provides methods for adding and retrieving |
71 animations. Besides that, you can remove animations by calling |
71 animations. Besides that, you can remove animations by calling |
72 remove(), and clear the animation group by calling |
72 remove(), and clear the animation group by calling |
73 clearAnimations(). You may keep track of changes in the group's |
73 clear(). You may keep track of changes in the group's |
74 animations by listening to QEvent::ChildAdded and |
74 animations by listening to QEvent::ChildAdded and |
75 QEvent::ChildRemoved events. |
75 QEvent::ChildRemoved events. |
76 |
76 |
77 \omit OK, let's find a snippet here as well. \endomit |
77 \omit OK, let's find a snippet here as well. \endomit |
78 |
78 |
149 |
149 |
150 /*! |
150 /*! |
151 Returns the index of \a animation. The returned index can be passed |
151 Returns the index of \a animation. The returned index can be passed |
152 to the other functions that take an index as an argument. |
152 to the other functions that take an index as an argument. |
153 |
153 |
154 \sa insertAnimationAt(), animationAt(), takeAnimationAt() |
154 \sa insertAnimation(), animationAt(), takeAnimation() |
155 */ |
155 */ |
156 int QAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const |
156 int QAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const |
157 { |
157 { |
158 Q_D(const QAnimationGroup); |
158 Q_D(const QAnimationGroup); |
159 return d->animations.indexOf(animation); |
159 return d->animations.indexOf(animation); |
160 } |
160 } |
161 |
161 |
162 /*! |
162 /*! |
163 Adds \a animation to this group. This will call insertAnimationAt with |
163 Adds \a animation to this group. This will call insertAnimation with |
164 index equals to animationCount(). |
164 index equals to animationCount(). |
165 |
165 |
166 \note The group takes ownership of the animation. |
166 \note The group takes ownership of the animation. |
167 |
167 |
168 \sa removeAnimation() |
168 \sa removeAnimation() |
169 */ |
169 */ |
170 void QAnimationGroup::addAnimation(QAbstractAnimation *animation) |
170 void QAnimationGroup::addAnimation(QAbstractAnimation *animation) |
171 { |
171 { |
172 Q_D(QAnimationGroup); |
172 Q_D(QAnimationGroup); |
173 insertAnimationAt(d->animations.count(), animation); |
173 insertAnimation(d->animations.count(), animation); |
174 } |
174 } |
175 |
175 |
176 /*! |
176 /*! |
177 Inserts \a animation into this animation group at \a index. |
177 Inserts \a animation into this animation group at \a index. |
178 If \a index is 0 the animation is inserted at the beginning. |
178 If \a index is 0 the animation is inserted at the beginning. |
179 If \a index is animationCount(), the animation is inserted at the end. |
179 If \a index is animationCount(), the animation is inserted at the end. |
180 |
180 |
181 \note The group takes ownership of the animation. |
181 \note The group takes ownership of the animation. |
182 |
182 |
183 \sa takeAnimationAt(), addAnimation(), indexOfAnimation(), removeAnimation() |
183 \sa takeAnimation(), addAnimation(), indexOfAnimation(), removeAnimation() |
184 */ |
184 */ |
185 void QAnimationGroup::insertAnimationAt(int index, QAbstractAnimation *animation) |
185 void QAnimationGroup::insertAnimation(int index, QAbstractAnimation *animation) |
186 { |
186 { |
187 Q_D(QAnimationGroup); |
187 Q_D(QAnimationGroup); |
188 |
188 |
189 if (index < 0 || index > d->animations.size()) { |
189 if (index < 0 || index > d->animations.size()) { |
190 qWarning("QAnimationGroup::insertAnimationAt: index is out of bounds"); |
190 qWarning("QAnimationGroup::insertAnimation: index is out of bounds"); |
191 return; |
191 return; |
192 } |
192 } |
193 |
193 |
194 if (QAnimationGroup *oldGroup = animation->group()) |
194 if (QAnimationGroup *oldGroup = animation->group()) |
195 oldGroup->removeAnimation(animation); |
195 oldGroup->removeAnimation(animation); |
203 |
203 |
204 /*! |
204 /*! |
205 Removes \a animation from this group. The ownership of \a animation is |
205 Removes \a animation from this group. The ownership of \a animation is |
206 transferred to the caller. |
206 transferred to the caller. |
207 |
207 |
208 \sa takeAnimationAt(), insertAnimationAt(), addAnimation() |
208 \sa takeAnimation(), insertAnimation(), addAnimation() |
209 */ |
209 */ |
210 void QAnimationGroup::removeAnimation(QAbstractAnimation *animation) |
210 void QAnimationGroup::removeAnimation(QAbstractAnimation *animation) |
211 { |
211 { |
212 Q_D(QAnimationGroup); |
212 Q_D(QAnimationGroup); |
213 |
213 |
219 if (index == -1) { |
219 if (index == -1) { |
220 qWarning("QAnimationGroup::remove: animation is not part of this group"); |
220 qWarning("QAnimationGroup::remove: animation is not part of this group"); |
221 return; |
221 return; |
222 } |
222 } |
223 |
223 |
224 takeAnimationAt(index); |
224 takeAnimation(index); |
225 } |
225 } |
226 |
226 |
227 /*! |
227 /*! |
228 Returns the animation at \a index and removes it from the animation group. |
228 Returns the animation at \a index and removes it from the animation group. |
229 |
229 |
230 \note The ownership of the animation is transferred to the caller. |
230 \note The ownership of the animation is transferred to the caller. |
231 |
231 |
232 \sa removeAnimation(), addAnimation(), insertAnimationAt(), indexOfAnimation() |
232 \sa removeAnimation(), addAnimation(), insertAnimation(), indexOfAnimation() |
233 */ |
233 */ |
234 QAbstractAnimation *QAnimationGroup::takeAnimationAt(int index) |
234 QAbstractAnimation *QAnimationGroup::takeAnimation(int index) |
235 { |
235 { |
236 Q_D(QAnimationGroup); |
236 Q_D(QAnimationGroup); |
237 if (index < 0 || index >= d->animations.size()) { |
237 if (index < 0 || index >= d->animations.size()) { |
238 qWarning("QAnimationGroup::takeAnimationAt: no animation at index %d", index); |
238 qWarning("QAnimationGroup::takeAnimation: no animation at index %d", index); |
239 return 0; |
239 return 0; |
240 } |
240 } |
241 QAbstractAnimation *animation = d->animations.at(index); |
241 QAbstractAnimation *animation = d->animations.at(index); |
242 QAbstractAnimationPrivate::get(animation)->group = 0; |
242 QAbstractAnimationPrivate::get(animation)->group = 0; |
243 // ### removing from list before doing setParent to avoid inifinite recursion |
243 // ### removing from list before doing setParent to avoid inifinite recursion |
277 QAbstractAnimation *a = static_cast<QAbstractAnimation *>(childEvent->child()); |
277 QAbstractAnimation *a = static_cast<QAbstractAnimation *>(childEvent->child()); |
278 // You can only rely on the child being a QObject because in the QEvent::ChildRemoved |
278 // You can only rely on the child being a QObject because in the QEvent::ChildRemoved |
279 // case it might be called from the destructor. |
279 // case it might be called from the destructor. |
280 int index = d->animations.indexOf(a); |
280 int index = d->animations.indexOf(a); |
281 if (index != -1) |
281 if (index != -1) |
282 takeAnimationAt(index); |
282 takeAnimation(index); |
283 } |
283 } |
284 return QAbstractAnimation::event(event); |
284 return QAbstractAnimation::event(event); |
285 } |
285 } |
286 |
286 |
287 |
287 |