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
{
Animator::Animator(QObject *parent)
AnimationDriver::AnimationDriver(QObject *parent)
: QObject(parent),
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)
return 0;
}
int Animator::movementAnimationFPS(Plasma::AnimationDriver::Movement movement) const
int AnimationDriver::movementAnimationFPS(Plasma::Animator::Movement movement) const
{
Q_UNUSED(movement)
return 20;
}
int Animator::elementAnimationFPS(Plasma::AnimationDriver::Animation animation) const
int AnimationDriver::elementAnimationFPS(Plasma::Animator::Animation animation) const
{
Q_UNUSED(animation)
return 0;
}
int Animator::animationDuration(Plasma::AnimationDriver::Animation) const
int AnimationDriver::animationDuration(Plasma::Animator::Animation) const
{
return 200;
}
int Animator::movementAnimationDuration(Plasma::AnimationDriver::Movement movement) const
int AnimationDriver::movementAnimationDuration(Plasma::Animator::Movement movement) const
{
switch (movement) {
case AnimationDriver::FastSlideInMovement:
case AnimationDriver::FastSlideOutMovement:
case Animator::FastSlideInMovement:
case Animator::FastSlideOutMovement:
return 100;
break;
default:
@ -73,33 +73,33 @@ int Animator::movementAnimationDuration(Plasma::AnimationDriver::Movement moveme
return 270;
}
int Animator::elementAnimationDuration(Plasma::AnimationDriver::Animation) const
int AnimationDriver::elementAnimationDuration(Plasma::Animator::Animation) const
{
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)
return pixmap;
}
QPixmap Animator::elementDisappear(qreal progress, const QPixmap& pixmap)
QPixmap AnimationDriver::elementDisappear(qreal progress, const QPixmap& pixmap)
{
Q_UNUSED(progress)
QPixmap pix(pixmap.size());
@ -108,32 +108,32 @@ QPixmap Animator::elementDisappear(qreal progress, const QPixmap& pixmap)
return pix;
}
void Animator::itemAppear(qreal frame, QGraphicsItem* item)
void AnimationDriver::itemAppear(qreal frame, QGraphicsItem* item)
{
Q_UNUSED(frame)
Q_UNUSED(item)
}
void Animator::itemDisappear(qreal frame, QGraphicsItem* item)
void AnimationDriver::itemDisappear(qreal frame, QGraphicsItem* item)
{
Q_UNUSED(frame)
Q_UNUSED(item)
}
void Animator::itemActivated(qreal frame, QGraphicsItem* item)
void AnimationDriver::itemActivated(qreal frame, QGraphicsItem* item)
{
Q_UNUSED(frame)
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 y = start.y() + (destination.y() - start.y()) * progress;
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();
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.
*/
#ifndef ANIMATOR_H
#define ANIMATOR_H
#ifndef ANIMATORDRIVER_H
#define ANIMATORDRIVER_H
#include <QtCore/QObject>
#include <QtGui/QRegion>
@ -35,24 +35,24 @@ class QGraphicsItem;
namespace Plasma
{
class PLASMA_EXPORT Animator : public QObject
class PLASMA_EXPORT AnimationDriver : public QObject
{
Q_OBJECT
public:
explicit Animator(QObject *parent = 0);
~Animator();
explicit AnimationDriver(QObject *parent = 0);
~AnimationDriver();
// Parameter definitions
virtual int animationFPS(Plasma::AnimationDriver::Animation) const;
virtual int movementAnimationFPS(Plasma::AnimationDriver::Movement) const;
virtual int elementAnimationFPS(Plasma::AnimationDriver::Animation) const;
virtual int animationDuration(Plasma::AnimationDriver::Animation) const;
virtual int movementAnimationDuration(Plasma::AnimationDriver::Movement) const;
virtual int elementAnimationDuration(Plasma::AnimationDriver::Animation) const;
virtual AnimationDriver::CurveShape animationCurve(Plasma::AnimationDriver::Animation) const;
virtual AnimationDriver::CurveShape movementAnimationCurve(Plasma::AnimationDriver::Movement) const;
virtual AnimationDriver::CurveShape elementAnimationCurve(Plasma::AnimationDriver::Animation) const;
virtual int animationFPS(Plasma::Animator::Animation) const;
virtual int movementAnimationFPS(Plasma::Animator::Movement) const;
virtual int elementAnimationFPS(Plasma::Animator::Animation) const;
virtual int animationDuration(Plasma::Animator::Animation) const;
virtual int movementAnimationDuration(Plasma::Animator::Movement) const;
virtual int elementAnimationDuration(Plasma::Animator::Animation) const;
virtual Animator::CurveShape animationCurve(Plasma::Animator::Animation) const;
virtual Animator::CurveShape movementAnimationCurve(Plasma::Animator::Movement) const;
virtual Animator::CurveShape elementAnimationCurve(Plasma::Animator::Animation) const;
// Element animations
virtual QPixmap elementAppear(qreal progress, const QPixmap& pixmap);

View File

@ -330,7 +330,7 @@ void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
case RemoveButton:
if (m_pressedButton == releasedAtButton) {
forceDisappear();
AnimationDriver::self()->animateItem(m_applet, AnimationDriver::DisappearAnimation);
Animator::self()->animateItem(m_applet, Animator::DisappearAnimation);
}
break;
case MoveButton: {
@ -615,7 +615,7 @@ void AppletHandle::appletResized()
void AppletHandle::startFading(FadeType anim)
{
if (m_animId != 0) {
AnimationDriver::self()->stopCustomAnimation(m_animId);
Animator::self()->stopCustomAnimation(m_animId);
}
m_anim = anim;
@ -638,7 +638,7 @@ void AppletHandle::startFading(FadeType anim)
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()

View File

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

View File

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

View File

@ -97,7 +97,7 @@ DesktopToolbox::DesktopToolbox(QGraphicsItem *parent)
: Toolbox(parent),
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);
setFlag(ItemClipsToShape, true);
@ -206,7 +206,7 @@ void DesktopToolbox::showToolbox()
const int iconWidth = 32;
int x = (int)boundingRect().left() - maxwidth - iconWidth - 5;
int y = (int)boundingRect().top() + 5;
Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self();
Plasma::Animator* animdriver = Plasma::Animator::self();
foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
if (tool == d->toolBacker) {
continue;
@ -215,14 +215,14 @@ void DesktopToolbox::showToolbox()
if (!tool->isEnabled()) {
if (tool->isVisible()) {
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;
}
//kDebug() << "let's show and move" << tool << tool->boundingRect();
tool->show();
animdriver->moveItem(tool, Plasma::AnimationDriver::SlideInMovement, QPoint(x, y));
animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
//x += 0;
y += static_cast<int>(tool->boundingRect().height()) + 5;
}
@ -240,7 +240,7 @@ void DesktopToolbox::showToolbox()
setShowing(true);
// 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().
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();
}
@ -264,14 +264,14 @@ void DesktopToolbox::hideToolbox()
int x = size() * 2;
int y = 0;
Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self();
Plasma::Animator* animdriver = Plasma::Animator::self();
foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
if (tool == d->toolBacker) {
continue;
}
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) {
@ -279,7 +279,7 @@ void DesktopToolbox::hideToolbox()
}
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) {
d->toolBacker->hide();

View File

@ -96,7 +96,7 @@ PanelToolbox::PanelToolbox(QGraphicsItem *parent)
: Toolbox(parent),
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);
setFlag(ItemClipsToShape, true);
@ -231,7 +231,7 @@ void PanelToolbox::showToolbox()
const int iconWidth = 32;
int x = size()*2 - maxwidth - iconWidth - 5;
int y = 5; // pos().y();
Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self();
Plasma::Animator* animdriver = Plasma::Animator::self();
foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
if (tool == d->toolBacker) {
continue;
@ -240,14 +240,14 @@ void PanelToolbox::showToolbox()
if (!tool->isEnabled()) {
if (tool->isVisible()) {
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;
}
//kDebug() << "let's show and move" << tool << tool->boundingRect();
tool->show();
animdriver->moveItem(tool, Plasma::AnimationDriver::SlideInMovement, QPoint(x, y));
animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
//x += 0;
y += static_cast<int>(tool->boundingRect().height()) + 5;
}
@ -265,7 +265,7 @@ void PanelToolbox::showToolbox()
setShowing(true);
// 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().
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();
}
@ -289,14 +289,14 @@ void PanelToolbox::hideToolbox()
int x = size() * 2;
int y = 0;
Plasma::AnimationDriver* animdriver = Plasma::AnimationDriver::self();
Plasma::Animator* animdriver = Plasma::Animator::self();
foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
if (tool == d->toolBacker) {
continue;
}
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) {
@ -304,7 +304,7 @@ void PanelToolbox::hideToolbox()
}
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) {
d->toolBacker->hide();

128
phase.cpp
View File

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

16
phase.h
View File

@ -18,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ANIMATIONCONTROLLER_H
#define ANIMATIONCONTROLLER_H
#ifndef ANIMATOR_H
#define ANIMATOR_H
#include <QtGui/QImage>
#include <QtCore/QObject>
@ -35,7 +35,7 @@ namespace Plasma
/**
* @short A system for applying effects to Plasma elements
*/
class PLASMA_EXPORT AnimationDriver : public QObject
class PLASMA_EXPORT Animator : public QObject
{
Q_OBJECT
Q_ENUMS( Animation )
@ -70,10 +70,10 @@ public:
/**
* Singleton accessor
**/
static AnimationDriver* self();
static Animator* self();
explicit AnimationDriver(QObject * parent = 0);
~AnimationDriver();
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);
@ -92,7 +92,7 @@ public:
*
* @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);
/**
@ -118,7 +118,7 @@ public:
Q_INVOKABLE bool isAnimating() const;
Q_SIGNALS:
void animationFinished(QGraphicsItem *item, Plasma::AnimationDriver::Animation anim);
void animationFinished(QGraphicsItem *item, Plasma::Animator::Animation anim);
void movementFinished(QGraphicsItem *item);
void elementAnimationFinished(int id);
void customAnimationFinished(int id);

View File

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