API REVIEW: Phase -> AnimatorDriver

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800840
This commit is contained in:
Davide Bettio 2008-04-24 23:21:17 +00:00
parent 04ad90006a
commit aa5f747305
10 changed files with 114 additions and 114 deletions

View File

@ -36,34 +36,34 @@ Animator::~Animator()
{ {
} }
int Animator::animationFPS(Plasma::Phase::Animation animation) const int Animator::animationFPS(Plasma::AnimationDriver::Animation animation) const
{ {
Q_UNUSED(animation) Q_UNUSED(animation)
return 0; return 0;
} }
int Animator::movementAnimationFPS(Plasma::Phase::Movement movement) const int Animator::movementAnimationFPS(Plasma::AnimationDriver::Movement movement) const
{ {
Q_UNUSED(movement) Q_UNUSED(movement)
return 20; return 20;
} }
int Animator::elementAnimationFPS(Plasma::Phase::Animation animation) const int Animator::elementAnimationFPS(Plasma::AnimationDriver::Animation animation) const
{ {
Q_UNUSED(animation) Q_UNUSED(animation)
return 0; return 0;
} }
int Animator::animationDuration(Plasma::Phase::Animation) const int Animator::animationDuration(Plasma::AnimationDriver::Animation) const
{ {
return 200; return 200;
} }
int Animator::movementAnimationDuration(Plasma::Phase::Movement movement) const int Animator::movementAnimationDuration(Plasma::AnimationDriver::Movement movement) const
{ {
switch (movement) { switch (movement) {
case Phase::FastSlideInMovement: case AnimationDriver::FastSlideInMovement:
case Phase::FastSlideOutMovement: case AnimationDriver::FastSlideOutMovement:
return 100; return 100;
break; break;
default: default:
@ -73,24 +73,24 @@ int Animator::movementAnimationDuration(Plasma::Phase::Movement movement) const
return 270; return 270;
} }
int Animator::elementAnimationDuration(Plasma::Phase::Animation) const int Animator::elementAnimationDuration(Plasma::AnimationDriver::Animation) const
{ {
return 333; return 333;
} }
Phase::CurveShape Animator::animationCurve(Plasma::Phase::Animation) const AnimationDriver::CurveShape Animator::animationCurve(Plasma::AnimationDriver::Animation) const
{ {
return Phase::EaseInOutCurve; return AnimationDriver::EaseInOutCurve;
} }
Phase::CurveShape Animator::movementAnimationCurve(Plasma::Phase::Movement) const AnimationDriver::CurveShape Animator::movementAnimationCurve(Plasma::AnimationDriver::Movement) const
{ {
return Phase::EaseInOutCurve; return AnimationDriver::EaseInOutCurve;
} }
Phase::CurveShape Animator::elementAnimationCurve(Plasma::Phase::Animation) const AnimationDriver::CurveShape Animator::elementAnimationCurve(Plasma::AnimationDriver::Animation) const
{ {
return Phase::EaseInOutCurve; return AnimationDriver::EaseInOutCurve;
} }
QPixmap Animator::elementAppear(qreal progress, const QPixmap& pixmap) QPixmap Animator::elementAppear(qreal progress, const QPixmap& pixmap)

View File

@ -44,15 +44,15 @@ public:
~Animator(); ~Animator();
// Parameter definitions // Parameter definitions
virtual int animationFPS(Plasma::Phase::Animation) const; virtual int animationFPS(Plasma::AnimationDriver::Animation) const;
virtual int movementAnimationFPS(Plasma::Phase::Movement) const; virtual int movementAnimationFPS(Plasma::AnimationDriver::Movement) const;
virtual int elementAnimationFPS(Plasma::Phase::Animation) const; virtual int elementAnimationFPS(Plasma::AnimationDriver::Animation) const;
virtual int animationDuration(Plasma::Phase::Animation) const; virtual int animationDuration(Plasma::AnimationDriver::Animation) const;
virtual int movementAnimationDuration(Plasma::Phase::Movement) const; virtual int movementAnimationDuration(Plasma::AnimationDriver::Movement) const;
virtual int elementAnimationDuration(Plasma::Phase::Animation) const; virtual int elementAnimationDuration(Plasma::AnimationDriver::Animation) const;
virtual Phase::CurveShape animationCurve(Plasma::Phase::Animation) const; virtual AnimationDriver::CurveShape animationCurve(Plasma::AnimationDriver::Animation) const;
virtual Phase::CurveShape movementAnimationCurve(Plasma::Phase::Movement) const; virtual AnimationDriver::CurveShape movementAnimationCurve(Plasma::AnimationDriver::Movement) const;
virtual Phase::CurveShape elementAnimationCurve(Plasma::Phase::Animation) const; virtual AnimationDriver::CurveShape elementAnimationCurve(Plasma::AnimationDriver::Animation) const;
// Element animations // Element animations
virtual QPixmap elementAppear(qreal progress, const QPixmap& pixmap); virtual QPixmap elementAppear(qreal progress, const QPixmap& pixmap);

View File

@ -330,7 +330,7 @@ void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
case RemoveButton: case RemoveButton:
if (m_pressedButton == releasedAtButton) { if (m_pressedButton == releasedAtButton) {
forceDisappear(); forceDisappear();
Phase::self()->animateItem(m_applet, Phase::DisappearAnimation); AnimationDriver::self()->animateItem(m_applet, AnimationDriver::DisappearAnimation);
} }
break; break;
case MoveButton: { case MoveButton: {
@ -615,7 +615,7 @@ void AppletHandle::appletResized()
void AppletHandle::startFading(FadeType anim) void AppletHandle::startFading(FadeType anim)
{ {
if (m_animId != 0) { if (m_animId != 0) {
Phase::self()->stopCustomAnimation(m_animId); AnimationDriver::self()->stopCustomAnimation(m_animId);
} }
m_anim = anim; m_anim = anim;
@ -638,7 +638,7 @@ void AppletHandle::startFading(FadeType anim)
time *= m_opacity; time *= m_opacity;
} }
m_animId = Phase::self()->customAnimation(40, (int)time, Phase::EaseInOutCurve, this, "fadeAnimation"); m_animId = AnimationDriver::self()->customAnimation(40, (int)time, AnimationDriver::EaseInOutCurve, this, "fadeAnimation");
} }
void AppletHandle::forceDisappear() void AppletHandle::forceDisappear()

View File

@ -192,9 +192,9 @@ void Containment::init()
setAcceptDrops(true); setAcceptDrops(true);
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
//TODO: would be nice to not do this on init, as it causes Phase to init //TODO: would be nice to not do this on init, as it causes AnimationDriver to init
connect(Phase::self(), SIGNAL(animationComplete(QGraphicsItem*,Plasma::Phase::Animation)), connect(AnimationDriver::self(), SIGNAL(animationComplete(QGraphicsItem*,Plasma::AnimationDriver::Animation)),
this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::Phase::Animation))); this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::AnimationDriver::Animation)));
if (d->type == NoContainmentType) { if (d->type == NoContainmentType) {
setContainmentType(DesktopContainment); setContainmentType(DesktopContainment);
@ -497,7 +497,7 @@ void Containment::destroyApplet()
} }
Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>()); Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>());
Phase::self()->animateItem(applet, Phase::DisappearAnimation); AnimationDriver::self()->animateItem(applet, AnimationDriver::DisappearAnimation);
} }
void Containment::setFormFactor(FormFactor formFactor) void Containment::setFormFactor(FormFactor formFactor)
@ -756,7 +756,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
} }
} else { } else {
applet->init(); applet->init();
Phase::self()->animateItem(applet, Phase::AppearAnimation); AnimationDriver::self()->animateItem(applet, AnimationDriver::AppearAnimation);
} }
applet->updateConstraints(Plasma::AllConstraints | Plasma::StartupCompletedConstraint); applet->updateConstraints(Plasma::AllConstraints | Plasma::StartupCompletedConstraint);
@ -790,9 +790,9 @@ void Containment::appletDestroyed(QObject* object)
emit configNeedsSaving(); emit configNeedsSaving();
} }
void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Phase::Animation anim) void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::AnimationDriver::Animation anim)
{ {
if (anim == Phase::DisappearAnimation) { if (anim == AnimationDriver::DisappearAnimation) {
QGraphicsItem *parent = item->parentItem(); QGraphicsItem *parent = item->parentItem();
while (parent) { while (parent) {
@ -808,7 +808,7 @@ void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Phase::An
parent = parent->parentItem(); parent = parent->parentItem();
} }
} else if (anim == Phase::AppearAnimation) { } else if (anim == AnimationDriver::AppearAnimation) {
if (containmentType() == DesktopContainment && if (containmentType() == DesktopContainment &&
item->parentItem() == this && item->parentItem() == this &&
qgraphicsitem_cast<Applet*>(item)) { qgraphicsitem_cast<Applet*>(item)) {

View File

@ -397,7 +397,7 @@ class PLASMA_EXPORT Containment : public Applet
* @internal * @internal
*/ */
void appletDestroyed(QObject*); void appletDestroyed(QObject*);
void appletAnimationComplete(QGraphicsItem *item, Plasma::Phase::Animation anim); void appletAnimationComplete(QGraphicsItem *item, Plasma::AnimationDriver::Animation anim);
void dropEvent(QGraphicsSceneDragDropEvent* event); void dropEvent(QGraphicsSceneDragDropEvent* event);
private Q_SLOTS: private Q_SLOTS:

View File

@ -97,7 +97,7 @@ DesktopToolbox::DesktopToolbox(QGraphicsItem *parent)
: Toolbox(parent), : Toolbox(parent),
d(new Private) d(new Private)
{ {
connect(Plasma::Phase::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*))); connect(Plasma::AnimationDriver::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*)));
setZValue(10000000); setZValue(10000000);
setFlag(ItemClipsToShape, true); setFlag(ItemClipsToShape, true);
@ -206,7 +206,7 @@ void DesktopToolbox::showToolbox()
const int iconWidth = 32; const int iconWidth = 32;
int x = (int)boundingRect().left() - maxwidth - iconWidth - 5; int x = (int)boundingRect().left() - maxwidth - iconWidth - 5;
int y = (int)boundingRect().top() + 5; int y = (int)boundingRect().top() + 5;
Plasma::Phase* phase = Plasma::Phase::self(); Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self();
foreach (QGraphicsItem* tool, QGraphicsItem::children()) { foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
if (tool == d->toolBacker) { if (tool == d->toolBacker) {
continue; continue;
@ -215,14 +215,14 @@ void DesktopToolbox::showToolbox()
if (!tool->isEnabled()) { if (!tool->isEnabled()) {
if (tool->isVisible()) { if (tool->isVisible()) {
const int height = static_cast<int>(tool->boundingRect().height()); const int height = static_cast<int>(tool->boundingRect().height());
phase->moveItem(tool, Plasma::Phase::SlideOutMovement, QPoint(size() * 2, -height)); animdriver->moveItem(tool, Plasma::AnimationDriver::SlideOutMovement, QPoint(size() * 2, -height));
} }
continue; continue;
} }
//kDebug() << "let's show and move" << tool << tool->boundingRect(); //kDebug() << "let's show and move" << tool << tool->boundingRect();
tool->show(); tool->show();
phase->moveItem(tool, Plasma::Phase::SlideInMovement, QPoint(x, y)); animdriver->moveItem(tool, Plasma::AnimationDriver::SlideInMovement, QPoint(x, y));
//x += 0; //x += 0;
y += static_cast<int>(tool->boundingRect().height()) + 5; y += static_cast<int>(tool->boundingRect().height()) + 5;
} }
@ -234,13 +234,13 @@ void DesktopToolbox::showToolbox()
d->toolBacker->show(); d->toolBacker->show();
if (d->animId) { if (d->animId) {
phase->stopCustomAnimation(d->animId); animdriver->stopCustomAnimation(d->animId);
} }
setShowing(true); setShowing(true);
// TODO: 10 and 200 shouldn't be hardcoded here. There needs to be a way to // TODO: 10 and 200 shouldn't be hardcoded here. There needs to be a way to
// match whatever the time is that moveItem() takes. Same in hoverLeaveEvent(). // match whatever the time is that moveItem() takes. Same in hoverLeaveEvent().
d->animId = phase->customAnimation(10, 240, Plasma::Phase::EaseInCurve, this, "animate"); d->animId = animdriver->customAnimation(10, 240, Plasma::AnimationDriver::EaseInCurve, this, "animate");
d->stopwatch.restart(); d->stopwatch.restart();
} }
@ -264,22 +264,22 @@ void DesktopToolbox::hideToolbox()
int x = size() * 2; int x = size() * 2;
int y = 0; int y = 0;
Plasma::Phase* phase = Plasma::Phase::self(); Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self();
foreach (QGraphicsItem* tool, QGraphicsItem::children()) { foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
if (tool == d->toolBacker) { if (tool == d->toolBacker) {
continue; continue;
} }
const int height = static_cast<int>(tool->boundingRect().height()); const int height = static_cast<int>(tool->boundingRect().height());
phase->moveItem(tool, Plasma::Phase::SlideOutMovement, QPoint(x, y-height)); animdriver->moveItem(tool, Plasma::AnimationDriver::SlideOutMovement, QPoint(x, y-height));
} }
if (d->animId) { if (d->animId) {
phase->stopCustomAnimation(d->animId); animdriver->stopCustomAnimation(d->animId);
} }
setShowing(false); setShowing(false);
d->animId = phase->customAnimation(10, 240, Plasma::Phase::EaseOutCurve, this, "animate"); d->animId = animdriver->customAnimation(10, 240, Plasma::AnimationDriver::EaseOutCurve, this, "animate");
if (d->toolBacker) { if (d->toolBacker) {
d->toolBacker->hide(); d->toolBacker->hide();

View File

@ -96,7 +96,7 @@ PanelToolbox::PanelToolbox(QGraphicsItem *parent)
: Toolbox(parent), : Toolbox(parent),
d(new Private) d(new Private)
{ {
connect(Plasma::Phase::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*))); connect(Plasma::AnimationDriver::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*)));
setZValue(10000000); setZValue(10000000);
setFlag(ItemClipsToShape, true); setFlag(ItemClipsToShape, true);
@ -231,7 +231,7 @@ void PanelToolbox::showToolbox()
const int iconWidth = 32; const int iconWidth = 32;
int x = size()*2 - maxwidth - iconWidth - 5; int x = size()*2 - maxwidth - iconWidth - 5;
int y = 5; // pos().y(); int y = 5; // pos().y();
Plasma::Phase* phase = Plasma::Phase::self(); Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self();
foreach (QGraphicsItem* tool, QGraphicsItem::children()) { foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
if (tool == d->toolBacker) { if (tool == d->toolBacker) {
continue; continue;
@ -240,14 +240,14 @@ void PanelToolbox::showToolbox()
if (!tool->isEnabled()) { if (!tool->isEnabled()) {
if (tool->isVisible()) { if (tool->isVisible()) {
const int height = static_cast<int>(tool->boundingRect().height()); const int height = static_cast<int>(tool->boundingRect().height());
phase->moveItem(tool, Plasma::Phase::SlideOutMovement, QPoint(size() * 2, -height)); animdriver->moveItem(tool, Plasma::AnimationDriver::SlideOutMovement, QPoint(size() * 2, -height));
} }
continue; continue;
} }
//kDebug() << "let's show and move" << tool << tool->boundingRect(); //kDebug() << "let's show and move" << tool << tool->boundingRect();
tool->show(); tool->show();
phase->moveItem(tool, Plasma::Phase::SlideInMovement, QPoint(x, y)); animdriver->moveItem(tool, Plasma::AnimationDriver::SlideInMovement, QPoint(x, y));
//x += 0; //x += 0;
y += static_cast<int>(tool->boundingRect().height()) + 5; y += static_cast<int>(tool->boundingRect().height()) + 5;
} }
@ -259,13 +259,13 @@ void PanelToolbox::showToolbox()
d->toolBacker->show(); d->toolBacker->show();
if (d->animId) { if (d->animId) {
phase->stopCustomAnimation(d->animId); animdriver->stopCustomAnimation(d->animId);
} }
setShowing(true); setShowing(true);
// TODO: 10 and 200 shouldn't be hardcoded here. There needs to be a way to // TODO: 10 and 200 shouldn't be hardcoded here. There needs to be a way to
// match whatever the time is that moveItem() takes. Same in hoverLeaveEvent(). // match whatever the time is that moveItem() takes. Same in hoverLeaveEvent().
d->animId = phase->customAnimation(10, 240, Plasma::Phase::EaseInCurve, this, "animate"); d->animId = animdriver->customAnimation(10, 240, Plasma::AnimationDriver::EaseInCurve, this, "animate");
d->stopwatch.restart(); d->stopwatch.restart();
} }
@ -289,22 +289,22 @@ void PanelToolbox::hideToolbox()
int x = size() * 2; int x = size() * 2;
int y = 0; int y = 0;
Plasma::Phase* phase = Plasma::Phase::self(); Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self();
foreach (QGraphicsItem* tool, QGraphicsItem::children()) { foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
if (tool == d->toolBacker) { if (tool == d->toolBacker) {
continue; continue;
} }
const int height = static_cast<int>(tool->boundingRect().height()); const int height = static_cast<int>(tool->boundingRect().height());
phase->moveItem(tool, Plasma::Phase::SlideOutMovement, QPoint(x, y-height)); animdriver->moveItem(tool, Plasma::AnimationDriver::SlideOutMovement, QPoint(x, y-height));
} }
if (d->animId) { if (d->animId) {
phase->stopCustomAnimation(d->animId); animdriver->stopCustomAnimation(d->animId);
} }
setShowing(false); setShowing(false);
d->animId = phase->customAnimation(10, 240, Plasma::Phase::EaseOutCurve, this, "animate"); d->animId = animdriver->customAnimation(10, 240, Plasma::AnimationDriver::EaseOutCurve, this, "animate");
if (d->toolBacker) { if (d->toolBacker) {
d->toolBacker->hide(); d->toolBacker->hide();

View File

@ -39,8 +39,8 @@ struct AnimationState
{ {
QGraphicsItem *item; QGraphicsItem *item;
QObject *qobj; QObject *qobj;
Phase::Animation animation; AnimationDriver::Animation animation;
Phase::CurveShape curve; AnimationDriver::CurveShape curve;
int interval; int interval;
int currentInterval; int currentInterval;
int frames; int frames;
@ -51,8 +51,8 @@ struct ElementAnimationState
{ {
QGraphicsItem *item; QGraphicsItem *item;
QObject *qobj; QObject *qobj;
Phase::CurveShape curve; AnimationDriver::CurveShape curve;
Phase::Animation animation; AnimationDriver::Animation animation;
int interval; int interval;
int currentInterval; int currentInterval;
int frames; int frames;
@ -65,8 +65,8 @@ struct MovementState
{ {
QGraphicsItem *item; QGraphicsItem *item;
QObject *qobj; QObject *qobj;
Phase::CurveShape curve; AnimationDriver::CurveShape curve;
Phase::Movement movement; AnimationDriver::Movement movement;
int interval; int interval;
int currentInterval; int currentInterval;
int frames; int frames;
@ -77,7 +77,7 @@ struct MovementState
struct CustomAnimationState struct CustomAnimationState
{ {
Phase::CurveShape curve; AnimationDriver::CurveShape curve;
int frames; int frames;
int currentFrame; int currentFrame;
int interval; int interval;
@ -87,7 +87,7 @@ struct CustomAnimationState
char* slot; char* slot;
}; };
class Phase::Private class AnimationDriver::Private
{ {
public: public:
@ -130,16 +130,16 @@ class Phase::Private
void performAnimation(qreal amount, const AnimationState* state) void performAnimation(qreal amount, const AnimationState* state)
{ {
switch (state->animation) { switch (state->animation) {
case Phase::AppearAnimation: case AnimationDriver::AppearAnimation:
animator->itemAppear(amount, state->item); animator->itemAppear(amount, state->item);
break; break;
case Phase::DisappearAnimation: case AnimationDriver::DisappearAnimation:
animator->itemDisappear(amount, state->item); animator->itemDisappear(amount, state->item);
if (amount >= 1) { if (amount >= 1) {
state->item->hide(); state->item->hide();
} }
break; break;
case Phase::ActivateAnimation: case AnimationDriver::ActivateAnimation:
animator->itemActivated(amount, state->item); animator->itemActivated(amount, state->item);
break; break;
} }
@ -148,13 +148,13 @@ class Phase::Private
void performMovement(qreal amount, const MovementState* state) void performMovement(qreal amount, const MovementState* state)
{ {
switch (state->movement) { switch (state->movement) {
case Phase::SlideInMovement: case AnimationDriver::SlideInMovement:
case Phase::FastSlideInMovement: case AnimationDriver::FastSlideInMovement:
//kDebug() << "performMovement, SlideInMovement"; //kDebug() << "performMovement, SlideInMovement";
animator->itemSlideIn(amount, state->item, state->start, state->destination); animator->itemSlideIn(amount, state->item, state->start, state->destination);
break; break;
case Phase::SlideOutMovement: case AnimationDriver::SlideOutMovement:
case Phase::FastSlideOutMovement: case AnimationDriver::FastSlideOutMovement:
//kDebug() << "performMovement, SlideOutMovement"; //kDebug() << "performMovement, SlideOutMovement";
animator->itemSlideOut(amount, state->item, state->start, state->destination); animator->itemSlideOut(amount, state->item, state->start, state->destination);
break; break;
@ -175,33 +175,33 @@ class Phase::Private
QMap<int, CustomAnimationState*> customAnims; QMap<int, CustomAnimationState*> customAnims;
}; };
class PhaseSingleton class AnimationDriverSingleton
{ {
public: public:
Phase self; AnimationDriver self;
}; };
K_GLOBAL_STATIC( PhaseSingleton, privateSelf ) K_GLOBAL_STATIC( AnimationDriverSingleton, privateSelf )
Phase* Phase::self() AnimationDriver* AnimationDriver::self()
{ {
return &privateSelf->self; return &privateSelf->self;
} }
Phase::Phase(QObject * parent) AnimationDriver::AnimationDriver(QObject * parent)
: QObject(parent), : QObject(parent),
d(new Private) d(new Private)
{ {
init(); init();
} }
Phase::~Phase() AnimationDriver::~AnimationDriver()
{ {
delete d; delete d;
} }
void Phase::animatedItemDestroyed(QObject* o) void AnimationDriver::animatedItemDestroyed(QObject* o)
{ {
//kDebug() << "testing for" << (void*)o; //kDebug() << "testing for" << (void*)o;
QMutableMapIterator<QGraphicsItem*, AnimationState*> it(d->animatedItems); QMutableMapIterator<QGraphicsItem*, AnimationState*> it(d->animatedItems);
@ -216,7 +216,7 @@ void Phase::animatedItemDestroyed(QObject* o)
} }
} }
void Phase::movingItemDestroyed(QObject* o) void AnimationDriver::movingItemDestroyed(QObject* o)
{ {
QMutableMapIterator<QGraphicsItem*, MovementState*> it(d->movingItems); QMutableMapIterator<QGraphicsItem*, MovementState*> it(d->movingItems);
while (it.hasNext()) { while (it.hasNext()) {
@ -228,7 +228,7 @@ void Phase::movingItemDestroyed(QObject* o)
} }
} }
void Phase::animatedElementDestroyed(QObject* o) void AnimationDriver::animatedElementDestroyed(QObject* o)
{ {
QMutableMapIterator<int, ElementAnimationState*> it(d->animatedElements); QMutableMapIterator<int, ElementAnimationState*> it(d->animatedElements);
while (it.hasNext()) { while (it.hasNext()) {
@ -240,7 +240,7 @@ void Phase::animatedElementDestroyed(QObject* o)
} }
} }
void Phase::customAnimReceiverDestroyed(QObject* o) void AnimationDriver::customAnimReceiverDestroyed(QObject* o)
{ {
QMutableMapIterator<int, CustomAnimationState*> it(d->customAnims); QMutableMapIterator<int, CustomAnimationState*> it(d->customAnims);
while (it.hasNext()) { while (it.hasNext()) {
@ -252,7 +252,7 @@ void Phase::customAnimReceiverDestroyed(QObject* o)
} }
} }
void Phase::animateItem(QGraphicsItem* item, Animation animation) void AnimationDriver::animateItem(QGraphicsItem* item, Animation animation)
{ {
//kDebug(); //kDebug();
// get rid of any existing animations on this item. // get rid of any existing animations on this item.
@ -298,7 +298,7 @@ void Phase::animateItem(QGraphicsItem* item, Animation animation)
} }
} }
void Phase::moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination) void AnimationDriver::moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination)
{ {
//kDebug(); //kDebug();
QMap<QGraphicsItem*, MovementState*>::iterator it = d->movingItems.find(item); QMap<QGraphicsItem*, MovementState*>::iterator it = d->movingItems.find(item);
@ -342,7 +342,7 @@ void Phase::moveItem(QGraphicsItem* item, Movement movement, const QPoint &desti
} }
} }
int Phase::customAnimation(int frames, int duration, Phase::CurveShape curve, int AnimationDriver::customAnimation(int frames, int duration, AnimationDriver::CurveShape curve,
QObject* receiver, const char* slot) QObject* receiver, const char* slot)
{ {
if (frames < 1 || duration < 1 || !receiver || !slot) { if (frames < 1 || duration < 1 || !receiver || !slot) {
@ -378,7 +378,7 @@ int Phase::customAnimation(int frames, int duration, Phase::CurveShape curve,
return state->id; return state->id;
} }
void Phase::stopCustomAnimation(int id) void AnimationDriver::stopCustomAnimation(int id)
{ {
QMap<int, CustomAnimationState*>::iterator it = d->customAnims.find(id); QMap<int, CustomAnimationState*>::iterator it = d->customAnims.find(id);
if (it != d->customAnims.end()) { if (it != d->customAnims.end()) {
@ -389,7 +389,7 @@ void Phase::stopCustomAnimation(int id)
//kDebug() << "stopCustomAnimation(AnimId " << id << ") done"; //kDebug() << "stopCustomAnimation(AnimId " << id << ") done";
} }
int Phase::animateElement(QGraphicsItem *item, Animation animation) int AnimationDriver::animateElement(QGraphicsItem *item, Animation animation)
{ {
//kDebug() << "startElementAnimation(AnimId " << animation << ")"; //kDebug() << "startElementAnimation(AnimId " << animation << ")";
ElementAnimationState *state = new ElementAnimationState; ElementAnimationState *state = new ElementAnimationState;
@ -430,7 +430,7 @@ int Phase::animateElement(QGraphicsItem *item, Animation animation)
return state->id; return state->id;
} }
void Phase::stopElementAnimation(int id) void AnimationDriver::stopElementAnimation(int id)
{ {
QMap<int, ElementAnimationState*>::iterator it = d->animatedElements.find(id); QMap<int, ElementAnimationState*>::iterator it = d->animatedElements.find(id);
if (it != d->animatedElements.end()) { if (it != d->animatedElements.end()) {
@ -440,33 +440,33 @@ void Phase::stopElementAnimation(int id)
//kDebug() << "stopElementAnimation(AnimId " << id << ") done"; //kDebug() << "stopElementAnimation(AnimId " << id << ") done";
} }
void Phase::setInitialPixmap(int id, const QPixmap &pixmap) void AnimationDriver::setInitialPixmap(int id, const QPixmap &pixmap)
{ {
QMap<int, ElementAnimationState*>::iterator it = d->animatedElements.find(id); QMap<int, ElementAnimationState*>::iterator it = d->animatedElements.find(id);
if (it == d->animatedElements.end()) { if (it == d->animatedElements.end()) {
kDebug() << "Phase::setInitialPixmap(" << id << ") found no entry for it!"; kDebug() << "AnimationDriver::setInitialPixmap(" << id << ") found no entry for it!";
return; return;
} }
it.value()->pixmap = pixmap; it.value()->pixmap = pixmap;
} }
QPixmap Phase::currentPixmap(int id) QPixmap AnimationDriver::currentPixmap(int id)
{ {
QMap<int, ElementAnimationState*>::const_iterator it = d->animatedElements.find(id); QMap<int, ElementAnimationState*>::const_iterator it = d->animatedElements.find(id);
if (it == d->animatedElements.constEnd()) { if (it == d->animatedElements.constEnd()) {
//kDebug() << "Phase::currentPixmap(" << id << ") found no entry for it!"; //kDebug() << "AnimationDriver::currentPixmap(" << id << ") found no entry for it!";
return QPixmap(); return QPixmap();
} }
ElementAnimationState* state = it.value(); ElementAnimationState* state = it.value();
qreal progress = state->frames; qreal progress = state->frames;
//kDebug() << "Phase::currentPixmap(" << id << " at " << progress; //kDebug() << "AnimationDriver::currentPixmap(" << id << " at " << progress;
progress = state->currentFrame / progress; progress = state->currentFrame / progress;
progress = qMin(qreal(1.0), qMax(qreal(0.0), progress)); progress = qMin(qreal(1.0), qMax(qreal(0.0), progress));
//kDebug() << "Phase::currentPixmap(" << id << " at " << progress; //kDebug() << "AnimationDriver::currentPixmap(" << id << " at " << progress;
switch (state->animation) { switch (state->animation) {
case AppearAnimation: case AppearAnimation:
@ -480,7 +480,7 @@ QPixmap Phase::currentPixmap(int id)
return state->pixmap; return state->pixmap;
} }
bool Phase::isAnimating() const bool AnimationDriver::isAnimating() const
{ {
return (!d->animatedItems.isEmpty() || return (!d->animatedItems.isEmpty() ||
!d->movingItems.isEmpty() || !d->movingItems.isEmpty() ||
@ -488,7 +488,7 @@ bool Phase::isAnimating() const
!d->customAnims.isEmpty()); !d->customAnims.isEmpty());
} }
void Phase::timerEvent(QTimerEvent *event) void AnimationDriver::timerEvent(QTimerEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)
bool animationsRemain = false; bool animationsRemain = false;
@ -616,10 +616,10 @@ void Phase::timerEvent(QTimerEvent *event)
} }
} }
void Phase::init() void AnimationDriver::init()
{ {
KConfig c("plasmarc"); KConfig c("plasmarc");
KConfigGroup cg(&c, "Phase"); KConfigGroup cg(&c, "AnimationDriver");
QString pluginName = cg.readEntry("animator", "default"); QString pluginName = cg.readEntry("animator", "default");
if (!pluginName.isEmpty()) { if (!pluginName.isEmpty()) {

16
phase.h
View File

@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef PHASE_H #ifndef ANIMATIONCONTROLLER_H
#define PHASE_H #define ANIMATIONCONTROLLER_H
#include <QtGui/QImage> #include <QtGui/QImage>
#include <QtCore/QObject> #include <QtCore/QObject>
@ -35,7 +35,7 @@ namespace Plasma
/** /**
* @short A system for applying effects to Plasma elements * @short A system for applying effects to Plasma elements
*/ */
class PLASMA_EXPORT Phase : public QObject class PLASMA_EXPORT AnimationDriver : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS( Animation ) Q_ENUMS( Animation )
@ -70,10 +70,10 @@ public:
/** /**
* Singleton accessor * Singleton accessor
**/ **/
static Phase* self(); static AnimationDriver* self();
explicit Phase(QObject * parent = 0); explicit AnimationDriver(QObject * parent = 0);
~Phase(); ~AnimationDriver();
Q_INVOKABLE void animateItem(QGraphicsItem* item, Animation anim); Q_INVOKABLE void animateItem(QGraphicsItem* item, Animation anim);
Q_INVOKABLE void moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination); Q_INVOKABLE void moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination);
@ -92,7 +92,7 @@ public:
* *
* @return an id that can be used to identify this animation. * @return an id that can be used to identify this animation.
*/ */
Q_INVOKABLE int customAnimation(int frames, int duration, Phase::CurveShape curve, Q_INVOKABLE int customAnimation(int frames, int duration, AnimationDriver::CurveShape curve,
QObject* receiver, const char* method); QObject* receiver, const char* method);
/** /**
@ -118,7 +118,7 @@ public:
Q_INVOKABLE bool isAnimating() const; Q_INVOKABLE bool isAnimating() const;
Q_SIGNALS: Q_SIGNALS:
void animationFinished(QGraphicsItem *item, Plasma::Phase::Animation anim); void animationFinished(QGraphicsItem *item, Plasma::AnimationDriver::Animation anim);
void movementFinished(QGraphicsItem *item); void movementFinished(QGraphicsItem *item);
void elementAnimationFinished(int id); void elementAnimationFinished(int id);
void customAnimationFinished(int id); void customAnimationFinished(int id);

View File

@ -97,26 +97,26 @@ IconAction::IconAction(Icon* icon, QAction *action)
void IconAction::show() void IconAction::show()
{ {
if (m_animationId) { if (m_animationId) {
Phase::self()->stopElementAnimation(m_animationId); AnimationDriver::self()->stopElementAnimation(m_animationId);
} }
rebuildPixmap(); rebuildPixmap();
m_animationId = Phase::self()->animateElement(m_icon, Phase::AppearAnimation); m_animationId = AnimationDriver::self()->animateElement(m_icon, AnimationDriver::AppearAnimation);
Phase::self()->setInitialPixmap(m_animationId, m_pixmap); AnimationDriver::self()->setInitialPixmap(m_animationId, m_pixmap);
m_visible = true; m_visible = true;
} }
void IconAction::hide() void IconAction::hide()
{ {
if (m_animationId) { if (m_animationId) {
Phase::self()->stopElementAnimation(m_animationId); AnimationDriver::self()->stopElementAnimation(m_animationId);
} }
rebuildPixmap(); rebuildPixmap();
m_animationId = Phase::self()->animateElement(m_icon, Phase::DisappearAnimation); m_animationId = AnimationDriver::self()->animateElement(m_icon, AnimationDriver::DisappearAnimation);
Phase::self()->setInitialPixmap(m_animationId, m_pixmap); AnimationDriver::self()->setInitialPixmap(m_animationId, m_pixmap);
m_visible = false; m_visible = false;
} }
@ -247,7 +247,7 @@ void IconAction::paint(QPainter *painter) const
return; return;
} }
QPixmap animPixmap = Phase::self()->currentPixmap(m_animationId); QPixmap animPixmap = AnimationDriver::self()->currentPixmap(m_animationId);
if (m_visible && animPixmap.isNull()) { if (m_visible && animPixmap.isNull()) {
painter->drawPixmap(m_rect.toRect(), m_pixmap); painter->drawPixmap(m_rect.toRect(), m_pixmap);
@ -485,10 +485,10 @@ void Icon::hoverEffect(bool show)
const int FadeInDuration = 150; const int FadeInDuration = 150;
if (d->m_hoverAnimId != -1) { if (d->m_hoverAnimId != -1) {
Phase::self()->stopCustomAnimation(d->m_hoverAnimId); AnimationDriver::self()->stopCustomAnimation(d->m_hoverAnimId);
} }
d->m_hoverAnimId = Phase::self()->customAnimation(40 / (1000 / FadeInDuration), FadeInDuration, d->m_hoverAnimId = AnimationDriver::self()->customAnimation(40 / (1000 / FadeInDuration), FadeInDuration,
Phase::EaseOutCurve, this, AnimationDriver::EaseOutCurve, this,
"hoverAnimationUpdate"); "hoverAnimationUpdate");
} }