Unbreaking pulse animation. It will handle the case where there

is no 'shadow' widget (and thus not set the widget itself as
its parent).

By connecting a slot to the signal emited by animation end, it will
also restore original opacity back.

TODO: instead of a copy of object, the shadow should be an image
where the animated widget was painted. This will solve a lot
of issues and make this class easier to use.


svn path=/trunk/KDE/kdelibs/; revision=1036351
This commit is contained in:
Adenilson Cavalcanti Da Silva 2009-10-17 05:17:05 +00:00
parent cb6dddf5cd
commit 66dff7cf72
2 changed files with 24 additions and 9 deletions

View File

@ -55,14 +55,20 @@ void PulseAnimation::setCopy(QGraphicsWidget *copy)
{
QGraphicsWidget *target = getAnimatedObject();
under = copy;
if (under != target) {
under->setParentItem(target);
mopacity = 0;
} else {
mopacity = under->opacity();
}
zvalue = target->zValue();
--zvalue;
under->setOpacity(0);
under->setZValue(zvalue);
mscale = under->scale();
}
}
void PulseAnimation::updateGeometry(QRectF updated, qreal zCoordinate, qreal scale)
{
@ -77,24 +83,32 @@ void PulseAnimation::updateGeometry(QRectF updated, qreal zCoordinate, qreal sca
QRectF initial(under->geometry());
qreal W = initial.width() * scale * 0.33;
qreal H = initial.height() * scale * 0.33;
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale, initial.height() * scale);
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale,
initial.height() * scale);
geometryAnimation->setEndValue(end);
}
}
void PulseAnimation::resetPulser()
{
under->setGeometry(*pulseGeometry);
under->setOpacity(0);
under->setOpacity(mopacity);
under->setZValue(zvalue);
under->setScale(mscale);
}
void PulseAnimation::createAnimation(qreal duration, qreal scale)
{
QGraphicsWidget *target = getAnimatedObject();
/* Fallback to parent widget if we don't have one 'shadow' widget */
if (!under) {
setCopy(getAnimatedObject());
setCopy(target);
} else if (under != target) {
delete under;
under = new QGraphicsWidget(target);
setCopy(under);
}
pulseGeometry = new QRectF(under->geometry());
@ -122,8 +136,9 @@ void PulseAnimation::createAnimation(qreal duration, qreal scale)
animation = group;
//XXX: current plasma::Animation model doesn't reuse animation objects
//connect(animation, SIGNAL(finished()), this, SLOT(resetPulser()));
//This makes sure that if there is *not* a shadow widget, the
//parent widget will still remain visible
connect(animation, SIGNAL(finished()), this, SLOT(resetPulser()));
}
QAbstractAnimation* PulseAnimation::render(QObject* parent)

View File

@ -48,7 +48,7 @@ private:
QAbstractAnimation *animation;
QGraphicsWidget *under;
QRectF *pulseGeometry;
qreal zvalue, mscale;
qreal zvalue, mscale, mopacity;
QPropertyAnimation *opacityAnimation;
QPropertyAnimation *geometryAnimation;
QPropertyAnimation *scaleAnimation;