* animateItem, moveItem return int
* add stopItemAnimation and stopItemMovement svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=802605
This commit is contained in:
parent
1eee210264
commit
0c2b74e11d
42
animator.cpp
42
animator.cpp
@ -45,6 +45,7 @@ struct AnimationState
|
||||
int currentInterval;
|
||||
int frames;
|
||||
int currentFrame;
|
||||
int id;
|
||||
};
|
||||
|
||||
struct ElementAnimationState
|
||||
@ -73,6 +74,7 @@ struct MovementState
|
||||
int currentFrame;
|
||||
QPoint start;
|
||||
QPoint destination;
|
||||
int id;
|
||||
};
|
||||
|
||||
struct CustomAnimationState
|
||||
@ -252,7 +254,7 @@ void Animator::customAnimReceiverDestroyed(QObject* o)
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::animateItem(QGraphicsItem* item, Animation animation)
|
||||
int Animator::animateItem(QGraphicsItem* item, Animation animation)
|
||||
{
|
||||
//kDebug();
|
||||
// get rid of any existing animations on this item.
|
||||
@ -268,10 +270,11 @@ void Animator::animateItem(QGraphicsItem* item, Animation animation)
|
||||
if (frames < 1) {
|
||||
// evidently this animator doesn't have an implementation
|
||||
// for this Animation
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
AnimationState* state = new AnimationState;
|
||||
state->id = ++d->animId;
|
||||
state->item = item;
|
||||
state->animation = animation;
|
||||
state->curve = d->driver->animationCurve(animation);
|
||||
@ -296,9 +299,11 @@ void Animator::animateItem(QGraphicsItem* item, Animation animation)
|
||||
d->timerId = startTimer(MIN_TICK_RATE);
|
||||
d->time.restart();
|
||||
}
|
||||
|
||||
return state->id;
|
||||
}
|
||||
|
||||
void Animator::moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination)
|
||||
int Animator::moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination)
|
||||
{
|
||||
//kDebug();
|
||||
QMap<QGraphicsItem*, MovementState*>::iterator it = d->movingItems.find(item);
|
||||
@ -311,10 +316,11 @@ void Animator::moveItem(QGraphicsItem* item, Movement movement, const QPoint &de
|
||||
if (frames <= 1) {
|
||||
// evidently this animator doesn't have an implementation
|
||||
// for this Animation
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
MovementState* state = new MovementState;
|
||||
state->id = ++d->animId;
|
||||
state->destination = destination;
|
||||
state->start = item->pos().toPoint();
|
||||
state->item = item;
|
||||
@ -340,6 +346,8 @@ void Animator::moveItem(QGraphicsItem* item, Movement movement, const QPoint &de
|
||||
d->timerId = startTimer(MIN_TICK_RATE);
|
||||
d->time.restart();
|
||||
}
|
||||
|
||||
return state->id;
|
||||
}
|
||||
|
||||
int Animator::customAnimation(int frames, int duration, Animator::CurveShape curve,
|
||||
@ -389,6 +397,32 @@ void Animator::stopCustomAnimation(int id)
|
||||
//kDebug() << "stopCustomAnimation(AnimId " << id << ") done";
|
||||
}
|
||||
|
||||
void Animator::stopItemAnimation(int id)
|
||||
{
|
||||
QMutableMapIterator<QGraphicsItem*, AnimationState*> it(d->animatedItems);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value()->id == id) {
|
||||
delete it.value();
|
||||
it.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::stopItemMovement(int id)
|
||||
{
|
||||
QMutableMapIterator<QGraphicsItem*, MovementState*> it(d->movingItems);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value()->id == id) {
|
||||
delete it.value();
|
||||
it.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Animator::animateElement(QGraphicsItem *item, Animation animation)
|
||||
{
|
||||
//kDebug() << "startElementAnimation(AnimId " << animation << ")";
|
||||
|
37
animator.h
37
animator.h
@ -75,8 +75,41 @@ public:
|
||||
explicit Animator(QObject * parent = 0);
|
||||
~Animator();
|
||||
|
||||
Q_INVOKABLE void animateItem(QGraphicsItem* item, Animation anim);
|
||||
Q_INVOKABLE void moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination);
|
||||
/**
|
||||
* Starts a standard animation on a QGraphicsItem.
|
||||
*
|
||||
* @arg item the item to animate in some fashion
|
||||
* @arg anim the the type of animation to perform
|
||||
* @return the id of the animation
|
||||
**/
|
||||
Q_INVOKABLE int animateItem(QGraphicsItem* item, Animation anim);
|
||||
|
||||
/**
|
||||
* Stops an item animation before the animation is complete.
|
||||
* Note that it is not necessary to call
|
||||
* this on normal completion of the animation.
|
||||
*
|
||||
* @arg id the id of the animation as returned by animateItem
|
||||
*/
|
||||
Q_INVOKABLE void stopItemAnimation(int id);
|
||||
|
||||
/**
|
||||
* Starts a standard animation on a QGraphicsItem.
|
||||
*
|
||||
* @arg item the item to animate in some fashion
|
||||
* @arg anim the the type of animation to perform
|
||||
* @return the id of the animation
|
||||
**/
|
||||
Q_INVOKABLE int moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination);
|
||||
|
||||
/**
|
||||
* Stops an item movement before the animation is complete.
|
||||
* Note that it is not necessary to call
|
||||
* this on normal completion of the animation.
|
||||
*
|
||||
* @arg id the id of the animation as returned by moveItem
|
||||
*/
|
||||
Q_INVOKABLE void stopItemMovement(int id);
|
||||
|
||||
/**
|
||||
* Starts a custom animation, preventing the need to create a timeline
|
||||
|
Loading…
Reference in New Issue
Block a user