Phase becomes Animator

Animator becomes AnimationDriver

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800870
This commit is contained in:
Aaron J. Seigo 2008-04-25 03:11:59 +00:00
parent 39acf3e24d
commit 6e80fe4354
10 changed files with 148 additions and 148 deletions

View File

@ -26,44 +26,44 @@
namespace Plasma namespace Plasma
{ {
Animator::Animator(QObject *parent) AnimationDriver::AnimationDriver(QObject *parent)
: QObject(parent), : QObject(parent),
d(0) d(0)
{ {
} }
Animator::~Animator() AnimationDriver::~AnimationDriver()
{ {
} }
int Animator::animationFPS(Plasma::AnimationDriver::Animation animation) const int AnimationDriver::animationFPS(Plasma::Animator::Animation animation) const
{ {
Q_UNUSED(animation) Q_UNUSED(animation)
return 0; return 0;
} }
int Animator::movementAnimationFPS(Plasma::AnimationDriver::Movement movement) const int AnimationDriver::movementAnimationFPS(Plasma::Animator::Movement movement) const
{ {
Q_UNUSED(movement) Q_UNUSED(movement)
return 20; return 20;
} }
int Animator::elementAnimationFPS(Plasma::AnimationDriver::Animation animation) const int AnimationDriver::elementAnimationFPS(Plasma::Animator::Animation animation) const
{ {
Q_UNUSED(animation) Q_UNUSED(animation)
return 0; return 0;
} }
int Animator::animationDuration(Plasma::AnimationDriver::Animation) const int AnimationDriver::animationDuration(Plasma::Animator::Animation) const
{ {
return 200; return 200;
} }
int Animator::movementAnimationDuration(Plasma::AnimationDriver::Movement movement) const int AnimationDriver::movementAnimationDuration(Plasma::Animator::Movement movement) const
{ {
switch (movement) { switch (movement) {
case AnimationDriver::FastSlideInMovement: case Animator::FastSlideInMovement:
case AnimationDriver::FastSlideOutMovement: case Animator::FastSlideOutMovement:
return 100; return 100;
break; break;
default: default:
@ -73,33 +73,33 @@ int Animator::movementAnimationDuration(Plasma::AnimationDriver::Movement moveme
return 270; return 270;
} }
int Animator::elementAnimationDuration(Plasma::AnimationDriver::Animation) const int AnimationDriver::elementAnimationDuration(Plasma::Animator::Animation) const
{ {
return 333; return 333;
} }
AnimationDriver::CurveShape Animator::animationCurve(Plasma::AnimationDriver::Animation) const Animator::CurveShape AnimationDriver::animationCurve(Plasma::Animator::Animation) const
{ {
return AnimationDriver::EaseInOutCurve; return Animator::EaseInOutCurve;
} }
AnimationDriver::CurveShape Animator::movementAnimationCurve(Plasma::AnimationDriver::Movement) const Animator::CurveShape AnimationDriver::movementAnimationCurve(Plasma::Animator::Movement) const
{ {
return AnimationDriver::EaseInOutCurve; return Animator::EaseInOutCurve;
} }
AnimationDriver::CurveShape Animator::elementAnimationCurve(Plasma::AnimationDriver::Animation) const Animator::CurveShape AnimationDriver::elementAnimationCurve(Plasma::Animator::Animation) const
{ {
return AnimationDriver::EaseInOutCurve; return Animator::EaseInOutCurve;
} }
QPixmap Animator::elementAppear(qreal progress, const QPixmap& pixmap) QPixmap AnimationDriver::elementAppear(qreal progress, const QPixmap& pixmap)
{ {
Q_UNUSED(progress) Q_UNUSED(progress)
return pixmap; return pixmap;
} }
QPixmap Animator::elementDisappear(qreal progress, const QPixmap& pixmap) QPixmap AnimationDriver::elementDisappear(qreal progress, const QPixmap& pixmap)
{ {
Q_UNUSED(progress) Q_UNUSED(progress)
QPixmap pix(pixmap.size()); QPixmap pix(pixmap.size());
@ -108,32 +108,32 @@ QPixmap Animator::elementDisappear(qreal progress, const QPixmap& pixmap)
return pix; return pix;
} }
void Animator::itemAppear(qreal frame, QGraphicsItem* item) void AnimationDriver::itemAppear(qreal frame, QGraphicsItem* item)
{ {
Q_UNUSED(frame) Q_UNUSED(frame)
Q_UNUSED(item) Q_UNUSED(item)
} }
void Animator::itemDisappear(qreal frame, QGraphicsItem* item) void AnimationDriver::itemDisappear(qreal frame, QGraphicsItem* item)
{ {
Q_UNUSED(frame) Q_UNUSED(frame)
Q_UNUSED(item) Q_UNUSED(item)
} }
void Animator::itemActivated(qreal frame, QGraphicsItem* item) void AnimationDriver::itemActivated(qreal frame, QGraphicsItem* item)
{ {
Q_UNUSED(frame) Q_UNUSED(frame)
Q_UNUSED(item) Q_UNUSED(item)
} }
void Animator::itemSlideIn(qreal progress, QGraphicsItem *item, const QPoint &start, const QPoint &destination) void AnimationDriver::itemSlideIn(qreal progress, QGraphicsItem *item, const QPoint &start, const QPoint &destination)
{ {
double x = start.x() + (destination.x() - start.x()) * progress; double x = start.x() + (destination.x() - start.x()) * progress;
double y = start.y() + (destination.y() - start.y()) * progress; double y = start.y() + (destination.y() - start.y()) * progress;
item->setPos(x, y); item->setPos(x, y);
} }
void Animator::itemSlideOut(qreal progress, QGraphicsItem *item, const QPoint &start, const QPoint &destination) void AnimationDriver::itemSlideOut(qreal progress, QGraphicsItem *item, const QPoint &start, const QPoint &destination)
{ {
//kDebug(); //kDebug();
double x = start.x() + (destination.x() - start.x()) * progress; double x = start.x() + (destination.x() - start.x()) * progress;

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 ANIMATOR_H #ifndef ANIMATORDRIVER_H
#define ANIMATOR_H #define ANIMATORDRIVER_H
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtGui/QRegion> #include <QtGui/QRegion>
@ -35,24 +35,24 @@ class QGraphicsItem;
namespace Plasma namespace Plasma
{ {
class PLASMA_EXPORT Animator : public QObject class PLASMA_EXPORT AnimationDriver : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Animator(QObject *parent = 0); explicit AnimationDriver(QObject *parent = 0);
~Animator(); ~AnimationDriver();
// Parameter definitions // Parameter definitions
virtual int animationFPS(Plasma::AnimationDriver::Animation) const; virtual int animationFPS(Plasma::Animator::Animation) const;
virtual int movementAnimationFPS(Plasma::AnimationDriver::Movement) const; virtual int movementAnimationFPS(Plasma::Animator::Movement) const;
virtual int elementAnimationFPS(Plasma::AnimationDriver::Animation) const; virtual int elementAnimationFPS(Plasma::Animator::Animation) const;
virtual int animationDuration(Plasma::AnimationDriver::Animation) const; virtual int animationDuration(Plasma::Animator::Animation) const;
virtual int movementAnimationDuration(Plasma::AnimationDriver::Movement) const; virtual int movementAnimationDuration(Plasma::Animator::Movement) const;
virtual int elementAnimationDuration(Plasma::AnimationDriver::Animation) const; virtual int elementAnimationDuration(Plasma::Animator::Animation) const;
virtual AnimationDriver::CurveShape animationCurve(Plasma::AnimationDriver::Animation) const; virtual Animator::CurveShape animationCurve(Plasma::Animator::Animation) const;
virtual AnimationDriver::CurveShape movementAnimationCurve(Plasma::AnimationDriver::Movement) const; virtual Animator::CurveShape movementAnimationCurve(Plasma::Animator::Movement) const;
virtual AnimationDriver::CurveShape elementAnimationCurve(Plasma::AnimationDriver::Animation) const; virtual Animator::CurveShape elementAnimationCurve(Plasma::Animator::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();
AnimationDriver::self()->animateItem(m_applet, AnimationDriver::DisappearAnimation); Animator::self()->animateItem(m_applet, Animator::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) {
AnimationDriver::self()->stopCustomAnimation(m_animId); Animator::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 = AnimationDriver::self()->customAnimation(40, (int)time, AnimationDriver::EaseInOutCurve, this, "fadeAnimation"); m_animId = Animator::self()->customAnimation(40, (int)time, Animator::EaseInOutCurve, this, "fadeAnimation");
} }
void AppletHandle::forceDisappear() void AppletHandle::forceDisappear()

View File

@ -207,9 +207,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 AnimationDriver to init //TODO: would be nice to not do this on init, as it causes Animator to init
connect(AnimationDriver::self(), SIGNAL(animationFinished(QGraphicsItem*,Plasma::AnimationDriver::Animation)), connect(Animator::self(), SIGNAL(animationFinished(QGraphicsItem*,Plasma::Animator::Animation)),
this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::AnimationDriver::Animation))); this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::Animator::Animation)));
if (d->type == NoContainmentType) { if (d->type == NoContainmentType) {
setContainmentType(DesktopContainment); setContainmentType(DesktopContainment);
@ -511,7 +511,7 @@ void Containment::Private::destroyApplet()
} }
Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>()); Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>());
AnimationDriver::self()->animateItem(applet, AnimationDriver::DisappearAnimation); Animator::self()->animateItem(applet, Animator::DisappearAnimation);
} }
void Containment::setFormFactor(FormFactor formFactor) void Containment::setFormFactor(FormFactor formFactor)
@ -770,7 +770,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
} }
} else { } else {
applet->init(); applet->init();
AnimationDriver::self()->animateItem(applet, AnimationDriver::AppearAnimation); Animator::self()->animateItem(applet, Animator::AppearAnimation);
} }
applet->updateConstraints(Plasma::AllConstraints | Plasma::StartupCompletedConstraint); applet->updateConstraints(Plasma::AllConstraints | Plasma::StartupCompletedConstraint);
@ -804,9 +804,9 @@ void Containment::appletDestroyed(QObject* object)
emit configNeedsSaving(); emit configNeedsSaving();
} }
void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::AnimationDriver::Animation anim) void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)
{ {
if (anim == AnimationDriver::DisappearAnimation) { if (anim == Animator::DisappearAnimation) {
QGraphicsItem *parent = item->parentItem(); QGraphicsItem *parent = item->parentItem();
while (parent) { while (parent) {
@ -822,7 +822,7 @@ void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Animation
parent = parent->parentItem(); parent = parent->parentItem();
} }
} else if (anim == AnimationDriver::AppearAnimation) { } else if (anim == Animator::AppearAnimation) {
if (containmentType() == DesktopContainment && if (containmentType() == DesktopContainment &&
item->parentItem() == this && item->parentItem() == this &&
qgraphicsitem_cast<Applet*>(item)) { qgraphicsitem_cast<Applet*>(item)) {

View File

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

View File

@ -97,7 +97,7 @@ DesktopToolbox::DesktopToolbox(QGraphicsItem *parent)
: Toolbox(parent), : Toolbox(parent),
d(new Private) d(new Private)
{ {
connect(Plasma::AnimationDriver::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*))); connect(Plasma::Animator::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::AnimationDriver* animdriver = Plasma::AnimationDriver::self(); Plasma::Animator* animdriver = Plasma::Animator::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());
animdriver->moveItem(tool, Plasma::AnimationDriver::SlideOutMovement, QPoint(size() * 2, -height)); animdriver->moveItem(tool, Plasma::Animator::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();
animdriver->moveItem(tool, Plasma::AnimationDriver::SlideInMovement, QPoint(x, y)); animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
//x += 0; //x += 0;
y += static_cast<int>(tool->boundingRect().height()) + 5; y += static_cast<int>(tool->boundingRect().height()) + 5;
} }
@ -240,7 +240,7 @@ void DesktopToolbox::showToolbox()
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 = animdriver->customAnimation(10, 240, Plasma::AnimationDriver::EaseInCurve, this, "animate"); d->animId = animdriver->customAnimation(10, 240, Plasma::Animator::EaseInCurve, this, "animate");
d->stopwatch.restart(); d->stopwatch.restart();
} }
@ -264,14 +264,14 @@ void DesktopToolbox::hideToolbox()
int x = size() * 2; int x = size() * 2;
int y = 0; int y = 0;
Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self(); Plasma::Animator* animdriver = Plasma::Animator::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());
animdriver->moveItem(tool, Plasma::AnimationDriver::SlideOutMovement, QPoint(x, y-height)); animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement, QPoint(x, y-height));
} }
if (d->animId) { if (d->animId) {
@ -279,7 +279,7 @@ void DesktopToolbox::hideToolbox()
} }
setShowing(false); setShowing(false);
d->animId = animdriver->customAnimation(10, 240, Plasma::AnimationDriver::EaseOutCurve, this, "animate"); d->animId = animdriver->customAnimation(10, 240, Plasma::Animator::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::AnimationDriver::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*))); connect(Plasma::Animator::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::AnimationDriver* animdriver = Plasma::AnimationDriver::self(); Plasma::Animator* animdriver = Plasma::Animator::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());
animdriver->moveItem(tool, Plasma::AnimationDriver::SlideOutMovement, QPoint(size() * 2, -height)); animdriver->moveItem(tool, Plasma::Animator::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();
animdriver->moveItem(tool, Plasma::AnimationDriver::SlideInMovement, QPoint(x, y)); animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
//x += 0; //x += 0;
y += static_cast<int>(tool->boundingRect().height()) + 5; y += static_cast<int>(tool->boundingRect().height()) + 5;
} }
@ -265,7 +265,7 @@ void PanelToolbox::showToolbox()
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 = animdriver->customAnimation(10, 240, Plasma::AnimationDriver::EaseInCurve, this, "animate"); d->animId = animdriver->customAnimation(10, 240, Plasma::Animator::EaseInCurve, this, "animate");
d->stopwatch.restart(); d->stopwatch.restart();
} }
@ -289,14 +289,14 @@ void PanelToolbox::hideToolbox()
int x = size() * 2; int x = size() * 2;
int y = 0; int y = 0;
Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self(); Plasma::Animator* animdriver = Plasma::Animator::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());
animdriver->moveItem(tool, Plasma::AnimationDriver::SlideOutMovement, QPoint(x, y-height)); animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement, QPoint(x, y-height));
} }
if (d->animId) { if (d->animId) {
@ -304,7 +304,7 @@ void PanelToolbox::hideToolbox()
} }
setShowing(false); setShowing(false);
d->animId = animdriver->customAnimation(10, 240, Plasma::AnimationDriver::EaseOutCurve, this, "animate"); d->animId = animdriver->customAnimation(10, 240, Plasma::Animator::EaseOutCurve, this, "animate");
if (d->toolBacker) { if (d->toolBacker) {
d->toolBacker->hide(); d->toolBacker->hide();

128
phase.cpp
View File

@ -39,8 +39,8 @@ struct AnimationState
{ {
QGraphicsItem *item; QGraphicsItem *item;
QObject *qobj; QObject *qobj;
AnimationDriver::Animation animation; Animator::Animation animation;
AnimationDriver::CurveShape curve; Animator::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;
AnimationDriver::CurveShape curve; Animator::CurveShape curve;
AnimationDriver::Animation animation; Animator::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;
AnimationDriver::CurveShape curve; Animator::CurveShape curve;
AnimationDriver::Movement movement; Animator::Movement movement;
int interval; int interval;
int currentInterval; int currentInterval;
int frames; int frames;
@ -77,7 +77,7 @@ struct MovementState
struct CustomAnimationState struct CustomAnimationState
{ {
AnimationDriver::CurveShape curve; Animator::CurveShape curve;
int frames; int frames;
int currentFrame; int currentFrame;
int interval; int interval;
@ -87,12 +87,12 @@ struct CustomAnimationState
char* slot; char* slot;
}; };
class AnimationDriver::Private class Animator::Private
{ {
public: public:
Private() Private()
: animator(0), : driver(0),
animId(0), animId(0),
timerId(0) timerId(0)
{ {
@ -130,17 +130,17 @@ class AnimationDriver::Private
void performAnimation(qreal amount, const AnimationState* state) void performAnimation(qreal amount, const AnimationState* state)
{ {
switch (state->animation) { switch (state->animation) {
case AnimationDriver::AppearAnimation: case Animator::AppearAnimation:
animator->itemAppear(amount, state->item); driver->itemAppear(amount, state->item);
break; break;
case AnimationDriver::DisappearAnimation: case Animator::DisappearAnimation:
animator->itemDisappear(amount, state->item); driver->itemDisappear(amount, state->item);
if (amount >= 1) { if (amount >= 1) {
state->item->hide(); state->item->hide();
} }
break; break;
case AnimationDriver::ActivateAnimation: case Animator::ActivateAnimation:
animator->itemActivated(amount, state->item); driver->itemActivated(amount, state->item);
break; break;
} }
} }
@ -148,20 +148,20 @@ class AnimationDriver::Private
void performMovement(qreal amount, const MovementState* state) void performMovement(qreal amount, const MovementState* state)
{ {
switch (state->movement) { switch (state->movement) {
case AnimationDriver::SlideInMovement: case Animator::SlideInMovement:
case AnimationDriver::FastSlideInMovement: case Animator::FastSlideInMovement:
//kDebug() << "performMovement, SlideInMovement"; //kDebug() << "performMovement, SlideInMovement";
animator->itemSlideIn(amount, state->item, state->start, state->destination); driver->itemSlideIn(amount, state->item, state->start, state->destination);
break; break;
case AnimationDriver::SlideOutMovement: case Animator::SlideOutMovement:
case AnimationDriver::FastSlideOutMovement: case Animator::FastSlideOutMovement:
//kDebug() << "performMovement, SlideOutMovement"; //kDebug() << "performMovement, SlideOutMovement";
animator->itemSlideOut(amount, state->item, state->start, state->destination); driver->itemSlideOut(amount, state->item, state->start, state->destination);
break; break;
} }
} }
Animator* animator; AnimationDriver* driver;
int animId; int animId;
int timerId; int timerId;
QTime time; QTime time;
@ -175,33 +175,33 @@ class AnimationDriver::Private
QMap<int, CustomAnimationState*> customAnims; QMap<int, CustomAnimationState*> customAnims;
}; };
class AnimationDriverSingleton class AnimatorSingleton
{ {
public: public:
AnimationDriver self; Animator self;
}; };
K_GLOBAL_STATIC( AnimationDriverSingleton, privateSelf ) K_GLOBAL_STATIC( AnimatorSingleton, privateSelf )
AnimationDriver* AnimationDriver::self() Animator* Animator::self()
{ {
return &privateSelf->self; return &privateSelf->self;
} }
AnimationDriver::AnimationDriver(QObject * parent) Animator::Animator(QObject * parent)
: QObject(parent), : QObject(parent),
d(new Private) d(new Private)
{ {
init(); init();
} }
AnimationDriver::~AnimationDriver() Animator::~Animator()
{ {
delete d; delete d;
} }
void AnimationDriver::animatedItemDestroyed(QObject* o) void Animator::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 AnimationDriver::animatedItemDestroyed(QObject* o)
} }
} }
void AnimationDriver::movingItemDestroyed(QObject* o) void Animator::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 AnimationDriver::movingItemDestroyed(QObject* o)
} }
} }
void AnimationDriver::animatedElementDestroyed(QObject* o) void Animator::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 AnimationDriver::animatedElementDestroyed(QObject* o)
} }
} }
void AnimationDriver::customAnimReceiverDestroyed(QObject* o) void Animator::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 AnimationDriver::customAnimReceiverDestroyed(QObject* o)
} }
} }
void AnimationDriver::animateItem(QGraphicsItem* item, Animation animation) void Animator::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.
@ -263,7 +263,7 @@ void AnimationDriver::animateItem(QGraphicsItem* item, Animation animation)
d->animatedItems.erase(it); d->animatedItems.erase(it);
} }
int frames = d->animator->animationFPS(animation); int frames = d->driver->animationFPS(animation);
if (frames < 1) { if (frames < 1) {
// evidently this animator doesn't have an implementation // evidently this animator doesn't have an implementation
@ -274,11 +274,11 @@ void AnimationDriver::animateItem(QGraphicsItem* item, Animation animation)
AnimationState* state = new AnimationState; AnimationState* state = new AnimationState;
state->item = item; state->item = item;
state->animation = animation; state->animation = animation;
state->curve = d->animator->animationCurve(animation); state->curve = d->driver->animationCurve(animation);
//TODO: variance in times based on the value of animation //TODO: variance in times based on the value of animation
state->frames = frames / 3; state->frames = frames / 3;
state->currentFrame = 0; state->currentFrame = 0;
state->interval = d->animator->animationDuration(animation) / state->frames; state->interval = d->driver->animationDuration(animation) / state->frames;
state->interval = (state->interval / MIN_TICK_RATE) * MIN_TICK_RATE; state->interval = (state->interval / MIN_TICK_RATE) * MIN_TICK_RATE;
state->currentInterval = state->interval; state->currentInterval = state->interval;
state->qobj = dynamic_cast<QObject*>(item); state->qobj = dynamic_cast<QObject*>(item);
@ -298,7 +298,7 @@ void AnimationDriver::animateItem(QGraphicsItem* item, Animation animation)
} }
} }
void AnimationDriver::moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination) void Animator::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);
@ -307,7 +307,7 @@ void AnimationDriver::moveItem(QGraphicsItem* item, Movement movement, const QPo
d->movingItems.erase(it); d->movingItems.erase(it);
} }
int frames = d->animator->movementAnimationFPS(movement); int frames = d->driver->movementAnimationFPS(movement);
if (frames <= 1) { if (frames <= 1) {
// evidently this animator doesn't have an implementation // evidently this animator doesn't have an implementation
// for this Animation // for this Animation
@ -319,11 +319,11 @@ void AnimationDriver::moveItem(QGraphicsItem* item, Movement movement, const QPo
state->start = item->pos().toPoint(); state->start = item->pos().toPoint();
state->item = item; state->item = item;
state->movement = movement; state->movement = movement;
state->curve = d->animator->movementAnimationCurve(movement); state->curve = d->driver->movementAnimationCurve(movement);
//TODO: variance in times based on the value of animation //TODO: variance in times based on the value of animation
state->frames = frames / 2; state->frames = frames / 2;
state->currentFrame = 0; state->currentFrame = 0;
state->interval = d->animator->movementAnimationDuration(movement) / state->frames; state->interval = d->driver->movementAnimationDuration(movement) / state->frames;
state->interval = (state->interval / MIN_TICK_RATE) * MIN_TICK_RATE; state->interval = (state->interval / MIN_TICK_RATE) * MIN_TICK_RATE;
state->currentInterval = state->interval; state->currentInterval = state->interval;
state->qobj = dynamic_cast<QObject*>(item); state->qobj = dynamic_cast<QObject*>(item);
@ -342,7 +342,7 @@ void AnimationDriver::moveItem(QGraphicsItem* item, Movement movement, const QPo
} }
} }
int AnimationDriver::customAnimation(int frames, int duration, AnimationDriver::CurveShape curve, int Animator::customAnimation(int frames, int duration, Animator::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 AnimationDriver::customAnimation(int frames, int duration, AnimationDriver::
return state->id; return state->id;
} }
void AnimationDriver::stopCustomAnimation(int id) void Animator::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,17 +389,17 @@ void AnimationDriver::stopCustomAnimation(int id)
//kDebug() << "stopCustomAnimation(AnimId " << id << ") done"; //kDebug() << "stopCustomAnimation(AnimId " << id << ") done";
} }
int AnimationDriver::animateElement(QGraphicsItem *item, Animation animation) int Animator::animateElement(QGraphicsItem *item, Animation animation)
{ {
//kDebug() << "startElementAnimation(AnimId " << animation << ")"; //kDebug() << "startElementAnimation(AnimId " << animation << ")";
ElementAnimationState *state = new ElementAnimationState; ElementAnimationState *state = new ElementAnimationState;
state->item = item; state->item = item;
state->curve = d->animator->elementAnimationCurve(animation); state->curve = d->driver->elementAnimationCurve(animation);
state->animation = animation; state->animation = animation;
//TODO: variance in times based on the value of animation //TODO: variance in times based on the value of animation
state->frames = d->animator->elementAnimationFPS(animation) / 5; state->frames = d->driver->elementAnimationFPS(animation) / 5;
state->currentFrame = 0; state->currentFrame = 0;
state->interval = d->animator->elementAnimationDuration(animation) / state->frames; state->interval = d->driver->elementAnimationDuration(animation) / state->frames;
state->interval = (state->interval / MIN_TICK_RATE) * MIN_TICK_RATE; state->interval = (state->interval / MIN_TICK_RATE) * MIN_TICK_RATE;
state->currentInterval = state->interval; state->currentInterval = state->interval;
state->id = ++d->animId; state->id = ++d->animId;
@ -430,7 +430,7 @@ int AnimationDriver::animateElement(QGraphicsItem *item, Animation animation)
return state->id; return state->id;
} }
void AnimationDriver::stopElementAnimation(int id) void Animator::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,47 +440,47 @@ void AnimationDriver::stopElementAnimation(int id)
//kDebug() << "stopElementAnimation(AnimId " << id << ") done"; //kDebug() << "stopElementAnimation(AnimId " << id << ") done";
} }
void AnimationDriver::setInitialPixmap(int id, const QPixmap &pixmap) void Animator::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() << "AnimationDriver::setInitialPixmap(" << id << ") found no entry for it!"; kDebug() << "Animator::setInitialPixmap(" << id << ") found no entry for it!";
return; return;
} }
it.value()->pixmap = pixmap; it.value()->pixmap = pixmap;
} }
QPixmap AnimationDriver::currentPixmap(int id) QPixmap Animator::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() << "AnimationDriver::currentPixmap(" << id << ") found no entry for it!"; //kDebug() << "Animator::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() << "AnimationDriver::currentPixmap(" << id << " at " << progress; //kDebug() << "Animator::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() << "AnimationDriver::currentPixmap(" << id << " at " << progress; //kDebug() << "Animator::currentPixmap(" << id << " at " << progress;
switch (state->animation) { switch (state->animation) {
case AppearAnimation: case AppearAnimation:
return d->animator->elementAppear(progress, state->pixmap); return d->driver->elementAppear(progress, state->pixmap);
break; break;
case DisappearAnimation: case DisappearAnimation:
return d->animator->elementDisappear(progress, state->pixmap); return d->driver->elementDisappear(progress, state->pixmap);
break; break;
} }
return state->pixmap; return state->pixmap;
} }
bool AnimationDriver::isAnimating() const bool Animator::isAnimating() const
{ {
return (!d->animatedItems.isEmpty() || return (!d->animatedItems.isEmpty() ||
!d->movingItems.isEmpty() || !d->movingItems.isEmpty() ||
@ -488,7 +488,7 @@ bool AnimationDriver::isAnimating() const
!d->customAnims.isEmpty()); !d->customAnims.isEmpty());
} }
void AnimationDriver::timerEvent(QTimerEvent *event) void Animator::timerEvent(QTimerEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)
bool animationsRemain = false; bool animationsRemain = false;
@ -616,11 +616,11 @@ void AnimationDriver::timerEvent(QTimerEvent *event)
} }
} }
void AnimationDriver::init() void Animator::init()
{ {
KConfig c("plasmarc"); KConfig c("plasmarc");
KConfigGroup cg(&c, "AnimationDriver"); KConfigGroup cg(&c, "Animator");
QString pluginName = cg.readEntry("animator", "default"); QString pluginName = cg.readEntry("driver", "default");
if (!pluginName.isEmpty()) { if (!pluginName.isEmpty()) {
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(pluginName); QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(pluginName);
@ -628,15 +628,15 @@ void AnimationDriver::init()
if (!offers.isEmpty()) { if (!offers.isEmpty()) {
QString error; QString error;
d->animator = offers.first()->createInstance<Plasma::Animator>(0, QVariantList(), &error); d->driver = offers.first()->createInstance<Plasma::AnimationDriver>(0, QVariantList(), &error);
if (!d->animator) { if (!d->driver) {
kDebug() << "Could not load requested animator " << offers.first() << ". Error given: " << error; kDebug() << "Could not load requested animator " << offers.first() << ". Error given: " << error;
} }
} }
} }
if (!d->animator) { if (!d->driver) {
d->animator = new Animator(this); d->driver = new AnimationDriver(this);
} }
} }

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 ANIMATIONCONTROLLER_H #ifndef ANIMATOR_H
#define ANIMATIONCONTROLLER_H #define ANIMATOR_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 AnimationDriver : public QObject class PLASMA_EXPORT Animator : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS( Animation ) Q_ENUMS( Animation )
@ -70,10 +70,10 @@ public:
/** /**
* Singleton accessor * Singleton accessor
**/ **/
static AnimationDriver* self(); static Animator* self();
explicit AnimationDriver(QObject * parent = 0); explicit Animator(QObject * parent = 0);
~AnimationDriver(); ~Animator();
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, AnimationDriver::CurveShape curve, Q_INVOKABLE int customAnimation(int frames, int duration, Animator::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::AnimationDriver::Animation anim); void animationFinished(QGraphicsItem *item, Plasma::Animator::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) {
AnimationDriver::self()->stopElementAnimation(m_animationId); Animator::self()->stopElementAnimation(m_animationId);
} }
rebuildPixmap(); rebuildPixmap();
m_animationId = AnimationDriver::self()->animateElement(m_icon, AnimationDriver::AppearAnimation); m_animationId = Animator::self()->animateElement(m_icon, Animator::AppearAnimation);
AnimationDriver::self()->setInitialPixmap(m_animationId, m_pixmap); Animator::self()->setInitialPixmap(m_animationId, m_pixmap);
m_visible = true; m_visible = true;
} }
void IconAction::hide() void IconAction::hide()
{ {
if (m_animationId) { if (m_animationId) {
AnimationDriver::self()->stopElementAnimation(m_animationId); Animator::self()->stopElementAnimation(m_animationId);
} }
rebuildPixmap(); rebuildPixmap();
m_animationId = AnimationDriver::self()->animateElement(m_icon, AnimationDriver::DisappearAnimation); m_animationId = Animator::self()->animateElement(m_icon, Animator::DisappearAnimation);
AnimationDriver::self()->setInitialPixmap(m_animationId, m_pixmap); Animator::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 = AnimationDriver::self()->currentPixmap(m_animationId); QPixmap animPixmap = Animator::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,11 +485,11 @@ void Icon::hoverEffect(bool show)
const int FadeInDuration = 150; const int FadeInDuration = 150;
if (d->m_hoverAnimId != -1) { if (d->m_hoverAnimId != -1) {
AnimationDriver::self()->stopCustomAnimation(d->m_hoverAnimId); Animator::self()->stopCustomAnimation(d->m_hoverAnimId);
} }
d->m_hoverAnimId = AnimationDriver::self()->customAnimation(40 / (1000 / FadeInDuration), FadeInDuration, d->m_hoverAnimId = Animator::self()->customAnimation(40 / (1000 / FadeInDuration), FadeInDuration,
AnimationDriver::EaseOutCurve, this, Animator::EaseOutCurve, this,
"hoverAnimationUpdate"); "hoverAnimationUpdate");
} }
void Icon::hoverAnimationUpdate(qreal progress) void Icon::hoverAnimationUpdate(qreal progress)