PulserAnimation done.

svn path=/trunk/KDE/kdelibs/; revision=1036805
This commit is contained in:
Adenilson Cavalcanti Da Silva 2009-10-17 20:04:58 +00:00
parent 00e5a53873
commit 7bc808c132
2 changed files with 75 additions and 63 deletions

View File

@ -31,8 +31,10 @@
namespace Plasma namespace Plasma
{ {
PulseAnimation::PulseAnimation() class PulseAnimationPrivate
: animation(0), {
public:
PulseAnimationPrivate(): animation(0),
under(0), under(0),
pulseGeometry(0), pulseGeometry(0),
zvalue(0), zvalue(0),
@ -40,6 +42,18 @@ PulseAnimation::PulseAnimation()
opacityAnimation(0), opacityAnimation(0),
geometryAnimation(0), geometryAnimation(0),
scaleAnimation(0) scaleAnimation(0)
{}
QAbstractAnimation *animation;
QGraphicsWidget *under;
QRectF *pulseGeometry;
qreal zvalue, mscale, mopacity;
QPropertyAnimation *opacityAnimation;
QPropertyAnimation *geometryAnimation;
QPropertyAnimation *scaleAnimation;
};
PulseAnimation::PulseAnimation(): d(new PulseAnimationPrivate)
{ {
} }
@ -49,52 +63,53 @@ PulseAnimation::~PulseAnimation()
//XXX: current plasma::Animation model will delete all animation objects //XXX: current plasma::Animation model will delete all animation objects
// delete animation; // delete animation;
// delete pulseGeometry; // delete pulseGeometry;
delete d;
} }
void PulseAnimation::setCopy(QGraphicsWidget *copy) void PulseAnimation::setCopy(QGraphicsWidget *copy)
{ {
QGraphicsWidget *target = getAnimatedObject(); QGraphicsWidget *target = getAnimatedObject();
under = copy; d->under = copy;
if (under != target) { if (d->under != target) {
under->setParentItem(target); d->under->setParentItem(target);
mopacity = 0; d->mopacity = 0;
} else { } else {
mopacity = under->opacity(); d->mopacity = d->under->opacity();
} }
zvalue = target->zValue(); d->zvalue = target->zValue();
--zvalue; --d->zvalue;
under->setOpacity(0); d->under->setOpacity(0);
under->setZValue(zvalue); d->under->setZValue(d->zvalue);
mscale = under->scale(); d->mscale = d->under->scale();
} }
void PulseAnimation::updateGeometry(QRectF updated, qreal zCoordinate, qreal scale) void PulseAnimation::updateGeometry(QRectF updated, qreal zCoordinate, qreal scale)
{ {
zvalue = zCoordinate; d->zvalue = zCoordinate;
--zvalue; --d->zvalue;
under->setGeometry(updated); d->under->setGeometry(updated);
under->setPos(0, 0); d->under->setPos(0, 0);
under->setOpacity(0); d->under->setOpacity(0);
under->setZValue(zvalue); d->under->setZValue(d->zvalue);
/* TODO: move this to a function */ /* TODO: move this to a function */
QRectF initial(under->geometry()); QRectF initial(d->under->geometry());
qreal W = initial.width() * scale * 0.33; qreal W = initial.width() * scale * 0.33;
qreal H = initial.height() * scale * 0.33; qreal H = initial.height() * scale * 0.33;
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale, QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale,
initial.height() * scale); initial.height() * scale);
geometryAnimation->setEndValue(end); d->geometryAnimation->setEndValue(end);
} }
void PulseAnimation::resetPulser() void PulseAnimation::resetPulser()
{ {
under->setGeometry(*pulseGeometry); d->under->setGeometry(*d->pulseGeometry);
under->setOpacity(mopacity); d->under->setOpacity(d->mopacity);
under->setZValue(zvalue); d->under->setZValue(d->zvalue);
under->setScale(mscale); d->under->setScale(d->mscale);
} }
@ -103,56 +118,56 @@ void PulseAnimation::createAnimation(qreal duration, qreal scale)
{ {
QGraphicsWidget *target = getAnimatedObject(); QGraphicsWidget *target = getAnimatedObject();
/* Fallback to parent widget if we don't have one 'shadow' widget */ /* Fallback to parent widget if we don't have one 'shadow' widget */
if (!under) { if (!d->under) {
setCopy(target); setCopy(target);
} else if (under != target) { } else if (d->under != target) {
delete under; delete d->under;
under = new QGraphicsWidget(target); d->under = new QGraphicsWidget(target);
setCopy(under); setCopy(d->under);
} }
pulseGeometry = new QRectF(under->geometry()); d->pulseGeometry = new QRectF(d->under->geometry());
QParallelAnimationGroup *group = new QParallelAnimationGroup(this); QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
opacityAnimation = new QPropertyAnimation(under, "opacity"); d->opacityAnimation = new QPropertyAnimation(d->under, "opacity");
opacityAnimation->setDuration(duration); d->opacityAnimation->setDuration(duration);
opacityAnimation->setEndValue(0); d->opacityAnimation->setEndValue(0);
group->addAnimation(opacityAnimation); group->addAnimation(d->opacityAnimation);
/* TODO: move this to a function */ /* TODO: move this to a function */
geometryAnimation = new QPropertyAnimation(under, "geometry"); d->geometryAnimation = new QPropertyAnimation(d->under, "geometry");
geometryAnimation->setDuration(duration); d->geometryAnimation->setDuration(duration);
QRectF initial(under->geometry()); QRectF initial(d->under->geometry());
qreal W = initial.width() * scale * 0.33; qreal W = initial.width() * scale * 0.33;
qreal H = initial.height() * scale * 0.33; qreal H = initial.height() * scale * 0.33;
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale, QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale,
initial.height() * scale); initial.height() * scale);
geometryAnimation->setEndValue(end); d->geometryAnimation->setEndValue(end);
group->addAnimation(geometryAnimation); group->addAnimation(d->geometryAnimation);
scaleAnimation = new QPropertyAnimation(under, "scale"); d->scaleAnimation = new QPropertyAnimation(d->under, "scale");
scaleAnimation->setDuration(duration); d->scaleAnimation->setDuration(duration);
scaleAnimation->setEndValue(scale); d->scaleAnimation->setEndValue(scale);
group->addAnimation(scaleAnimation); group->addAnimation(d->scaleAnimation);
animation = group; d->animation = group;
//This makes sure that if there is *not* a shadow widget, the //This makes sure that if there is *not* a shadow widget, the
//parent widget will still remain visible //parent widget will still remain visible
connect(animation, SIGNAL(finished()), this, SLOT(resetPulser())); connect(d->animation, SIGNAL(finished()), this, SLOT(resetPulser()));
} }
QAbstractAnimation* PulseAnimation::render(QObject* parent) QAbstractAnimation* PulseAnimation::render(QObject* parent)
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
createAnimation(); createAnimation();
under->setOpacity(1); d->under->setOpacity(1);
return animation; return d->animation;
} }
void PulseAnimation::start() void PulseAnimation::start()
{ {
under->setOpacity(1); d->under->setOpacity(1);
animation->start(); d->animation->start();
} }
} //namespace Plasma } //namespace Plasma

View File

@ -25,6 +25,8 @@
namespace Plasma namespace Plasma
{ {
class PulseAnimationPrivate;
class PLASMA_EXPORT PulseAnimation : public Animation class PLASMA_EXPORT PulseAnimation : public Animation
{ {
Q_OBJECT Q_OBJECT
@ -45,13 +47,8 @@ protected:
private: private:
void createAnimation(qreal _duration = 500, qreal _scale = 1.5); void createAnimation(qreal _duration = 500, qreal _scale = 1.5);
QAbstractAnimation *animation;
QGraphicsWidget *under; PulseAnimationPrivate *d;
QRectF *pulseGeometry;
qreal zvalue, mscale, mopacity;
QPropertyAnimation *opacityAnimation;
QPropertyAnimation *geometryAnimation;
QPropertyAnimation *scaleAnimation;
}; };
} }