2009-10-15 21:36:38 +02:00
|
|
|
/* Copyright (C) 2009 Adenilson Cavalcanti <cavalcantii@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2009-10-16 00:29:21 +02:00
|
|
|
/* TODO:
|
|
|
|
* - fix centering of pulsed shadow object
|
|
|
|
*/
|
|
|
|
|
2009-10-22 21:46:16 +02:00
|
|
|
#include "pulser_p.h"
|
2009-11-13 02:20:51 +01:00
|
|
|
#include "plasma/private/pulsershadow_p.h"
|
2009-10-15 21:36:38 +02:00
|
|
|
#include <QAbstractAnimation>
|
|
|
|
#include <QDebug>
|
2009-10-22 04:50:58 +02:00
|
|
|
#include <QEvent>
|
|
|
|
#include <QGraphicsWidget>
|
|
|
|
#include <QParallelAnimationGroup>
|
2009-10-15 21:36:38 +02:00
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
2009-10-22 04:50:58 +02:00
|
|
|
#include <kdebug.h>
|
2009-10-15 21:36:38 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
class PulseAnimationPrivate
|
|
|
|
{
|
2009-10-22 04:50:58 +02:00
|
|
|
public :
|
|
|
|
PulseAnimationPrivate()
|
|
|
|
: animation(0),
|
|
|
|
under(0),
|
|
|
|
pulseGeometry(0),
|
|
|
|
zvalue(0),
|
|
|
|
mscale(0),
|
|
|
|
opacityAnimation(0),
|
|
|
|
geometryAnimation(0),
|
|
|
|
scaleAnimation(0)
|
2009-10-17 22:04:58 +02:00
|
|
|
{}
|
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
~PulseAnimationPrivate()
|
|
|
|
{
|
|
|
|
if (pulseGeometry)
|
|
|
|
delete pulseGeometry;
|
|
|
|
}
|
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
QAbstractAnimation *animation;
|
|
|
|
QGraphicsWidget *under;
|
|
|
|
QRectF *pulseGeometry;
|
|
|
|
qreal zvalue, mscale, mopacity;
|
|
|
|
QPropertyAnimation *opacityAnimation;
|
|
|
|
QPropertyAnimation *geometryAnimation;
|
|
|
|
QPropertyAnimation *scaleAnimation;
|
|
|
|
};
|
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
PulseAnimation::PulseAnimation(): d(new PulseAnimationPrivate)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PulseAnimation::~PulseAnimation()
|
|
|
|
{
|
2009-10-17 22:04:58 +02:00
|
|
|
delete d;
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
void PulseAnimation::setCopy()
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
2009-10-20 23:21:40 +02:00
|
|
|
QGraphicsWidget *target = widgetToAnimate();
|
2009-11-13 02:20:51 +01:00
|
|
|
/* copy the parent to an image, the animation will happen on the
|
|
|
|
* pixmap copy.
|
|
|
|
*/
|
|
|
|
ShadowFake *shadow = 0;
|
|
|
|
if (!d->under)
|
|
|
|
shadow = new ShadowFake;
|
|
|
|
|
|
|
|
shadow->copyTarget(target);
|
|
|
|
|
|
|
|
if (d->pulseGeometry)
|
|
|
|
delete d->pulseGeometry;
|
|
|
|
d->pulseGeometry = new QRectF(target->geometry());
|
2009-10-17 07:17:05 +02:00
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
d->mopacity = 0;
|
2009-10-17 22:04:58 +02:00
|
|
|
d->zvalue = target->zValue();
|
|
|
|
--d->zvalue;
|
2009-11-13 02:20:51 +01:00
|
|
|
d->mscale = target->scale();
|
|
|
|
|
|
|
|
d->under = shadow;
|
|
|
|
d->under->setOpacity(d->mopacity);
|
|
|
|
d->under->setScale(d->mscale);
|
2009-10-17 22:04:58 +02:00
|
|
|
d->under->setZValue(d->zvalue);
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2009-10-17 07:17:05 +02:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
void PulseAnimation::resetPulser()
|
|
|
|
{
|
2009-11-13 02:20:51 +01:00
|
|
|
d->under->setGeometry(*(d->pulseGeometry));
|
2009-10-17 22:04:58 +02:00
|
|
|
d->under->setOpacity(d->mopacity);
|
|
|
|
d->under->setScale(d->mscale);
|
2009-11-13 02:20:51 +01:00
|
|
|
d->under->setZValue(d->zvalue);
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PulseAnimation::createAnimation(qreal duration, qreal scale)
|
|
|
|
{
|
2009-10-23 20:39:57 +02:00
|
|
|
bool dirty = false;
|
2009-11-13 02:20:51 +01:00
|
|
|
if (!d->under)
|
|
|
|
setCopy();
|
2009-10-23 20:39:57 +02:00
|
|
|
|
|
|
|
QParallelAnimationGroup *anim = dynamic_cast<QParallelAnimationGroup* >(animation());
|
|
|
|
if (!anim) {
|
2009-10-27 15:22:21 +01:00
|
|
|
QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
|
|
|
|
d->opacityAnimation = new QPropertyAnimation(d->under, "opacity");
|
|
|
|
d->opacityAnimation->setDuration(duration);
|
2009-11-13 02:20:51 +01:00
|
|
|
d->opacityAnimation->setStartValue(100);
|
2009-10-27 15:22:21 +01:00
|
|
|
d->opacityAnimation->setEndValue(0);
|
|
|
|
group->addAnimation(d->opacityAnimation);
|
|
|
|
|
|
|
|
QRectF initial(d->under->geometry());
|
2009-11-13 02:20:51 +01:00
|
|
|
QPointF tmp(initial.width() * 0.5, initial.height() * 0.5);
|
|
|
|
d->under->setTransformOriginPoint(tmp);
|
2009-10-27 15:22:21 +01:00
|
|
|
|
|
|
|
d->scaleAnimation = new QPropertyAnimation(d->under, "scale");
|
|
|
|
d->scaleAnimation->setDuration(duration);
|
2009-11-13 02:20:51 +01:00
|
|
|
d->scaleAnimation->setStartValue(d->mscale);
|
2009-10-27 15:22:21 +01:00
|
|
|
d->scaleAnimation->setEndValue(scale);
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2009-10-27 15:22:21 +01:00
|
|
|
/* The group takes ownership of all animations */
|
|
|
|
group->addAnimation(d->scaleAnimation);
|
|
|
|
d->animation = group;
|
|
|
|
setAnimation(d->animation);
|
|
|
|
dirty = true;
|
2009-10-23 20:39:57 +02:00
|
|
|
|
|
|
|
} else {
|
2009-10-24 05:04:17 +02:00
|
|
|
|
|
|
|
QAbstractAnimation::State temp = anim->state();
|
|
|
|
if (temp == QAbstractAnimation::Running) {
|
|
|
|
anim->stop();
|
|
|
|
/* TODO: will need to watch stateChanged signal
|
|
|
|
* and *then* reset the geometry
|
|
|
|
*/
|
|
|
|
} else {
|
2009-11-13 02:20:51 +01:00
|
|
|
if ((*d->pulseGeometry) != widgetToAnimate()->geometry()) {
|
|
|
|
/*FIXME: it crashes when deleting old the image in ShadowFake
|
|
|
|
* setCopy();
|
|
|
|
*/
|
|
|
|
qDebug() << "PulseAnimation:: it should update the geom....";
|
|
|
|
}
|
|
|
|
|
2009-10-24 05:04:17 +02:00
|
|
|
d->opacityAnimation->setEndValue(0);
|
2009-11-13 02:20:51 +01:00
|
|
|
d->scaleAnimation->setEndValue(scale);
|
|
|
|
|
2009-10-24 05:04:17 +02:00
|
|
|
QRectF initial(d->under->geometry());
|
2009-11-13 02:20:51 +01:00
|
|
|
QPointF tmp(initial.width() * 0.5, initial.height() * 0.5);
|
|
|
|
d->under->setTransformOriginPoint(tmp);
|
2009-10-24 05:04:17 +02:00
|
|
|
}
|
2009-10-23 20:39:57 +02:00
|
|
|
}
|
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
if (dirty)
|
2009-10-27 15:22:21 +01:00
|
|
|
connect(d->animation, SIGNAL(finished()), this, SLOT(resetPulser()));
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractAnimation* PulseAnimation::render(QObject* parent)
|
|
|
|
{
|
2009-10-22 04:50:58 +02:00
|
|
|
Q_UNUSED(parent)
|
|
|
|
|
2009-10-22 04:59:24 +02:00
|
|
|
createAnimation(duration());
|
2009-10-17 22:04:58 +02:00
|
|
|
return d->animation;
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|