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-15 21:36:38 +02:00
|
|
|
#include "pulser.h"
|
|
|
|
#include <QGraphicsWidget>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QAbstractAnimation>
|
|
|
|
#include <QParallelAnimationGroup>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
class PulseAnimationPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PulseAnimationPrivate(): animation(0),
|
|
|
|
under(0),
|
|
|
|
pulseGeometry(0),
|
|
|
|
zvalue(0),
|
|
|
|
mscale(0),
|
|
|
|
opacityAnimation(0),
|
|
|
|
geometryAnimation(0),
|
|
|
|
scaleAnimation(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QAbstractAnimation *animation;
|
|
|
|
QGraphicsWidget *under;
|
|
|
|
QRectF *pulseGeometry;
|
|
|
|
qreal zvalue, mscale, mopacity;
|
|
|
|
QPropertyAnimation *opacityAnimation;
|
|
|
|
QPropertyAnimation *geometryAnimation;
|
|
|
|
QPropertyAnimation *scaleAnimation;
|
|
|
|
};
|
|
|
|
|
|
|
|
PulseAnimation::PulseAnimation(): d(new PulseAnimationPrivate)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PulseAnimation::~PulseAnimation()
|
|
|
|
{
|
2009-10-16 00:29:21 +02:00
|
|
|
//XXX: current plasma::Animation model will delete all animation objects
|
|
|
|
// delete animation;
|
|
|
|
// delete pulseGeometry;
|
2009-10-17 22:04:58 +02:00
|
|
|
delete d;
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAnimation::setCopy(QGraphicsWidget *copy)
|
|
|
|
{
|
2009-10-20 23:21:40 +02:00
|
|
|
QGraphicsWidget *target = widgetToAnimate();
|
2009-10-17 22:04:58 +02:00
|
|
|
d->under = copy;
|
|
|
|
if (d->under != target) {
|
|
|
|
d->under->setParentItem(target);
|
|
|
|
d->mopacity = 0;
|
2009-10-17 07:17:05 +02:00
|
|
|
} else {
|
2009-10-17 22:04:58 +02:00
|
|
|
d->mopacity = d->under->opacity();
|
2009-10-17 07:17:05 +02:00
|
|
|
}
|
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
d->zvalue = target->zValue();
|
|
|
|
--d->zvalue;
|
|
|
|
d->under->setOpacity(0);
|
|
|
|
d->under->setZValue(d->zvalue);
|
|
|
|
d->mscale = d->under->scale();
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-10-17 07:17:05 +02:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
void PulseAnimation::updateGeometry(QRectF updated, qreal zCoordinate, qreal scale)
|
|
|
|
{
|
2009-10-17 22:04:58 +02:00
|
|
|
d->zvalue = zCoordinate;
|
|
|
|
--d->zvalue;
|
|
|
|
d->under->setGeometry(updated);
|
|
|
|
d->under->setPos(0, 0);
|
|
|
|
d->under->setOpacity(0);
|
|
|
|
d->under->setZValue(d->zvalue);
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
/* TODO: move this to a function */
|
2009-10-17 22:04:58 +02:00
|
|
|
QRectF initial(d->under->geometry());
|
2009-10-15 21:36:38 +02:00
|
|
|
qreal W = initial.width() * scale * 0.33;
|
|
|
|
qreal H = initial.height() * scale * 0.33;
|
2009-10-17 07:17:05 +02:00
|
|
|
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale,
|
|
|
|
initial.height() * scale);
|
2009-10-17 22:04:58 +02:00
|
|
|
d->geometryAnimation->setEndValue(end);
|
2009-10-17 07:17:05 +02:00
|
|
|
}
|
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
void PulseAnimation::resetPulser()
|
|
|
|
{
|
2009-10-17 22:04:58 +02:00
|
|
|
d->under->setGeometry(*d->pulseGeometry);
|
|
|
|
d->under->setOpacity(d->mopacity);
|
|
|
|
d->under->setZValue(d->zvalue);
|
|
|
|
d->under->setScale(d->mscale);
|
2009-10-17 07:17:05 +02:00
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PulseAnimation::createAnimation(qreal duration, qreal scale)
|
|
|
|
{
|
2009-10-20 23:21:40 +02:00
|
|
|
QGraphicsWidget *target = widgetToAnimate();
|
2009-10-16 00:29:21 +02:00
|
|
|
/* Fallback to parent widget if we don't have one 'shadow' widget */
|
2009-10-17 22:04:58 +02:00
|
|
|
if (!d->under) {
|
2009-10-17 07:17:05 +02:00
|
|
|
setCopy(target);
|
2009-10-17 22:04:58 +02:00
|
|
|
} else if (d->under != target) {
|
|
|
|
delete d->under;
|
|
|
|
d->under = new QGraphicsWidget(target);
|
|
|
|
setCopy(d->under);
|
2009-10-16 18:36:22 +02:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
d->pulseGeometry = new QRectF(d->under->geometry());
|
2009-10-15 21:36:38 +02:00
|
|
|
QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
|
2009-10-17 22:04:58 +02:00
|
|
|
d->opacityAnimation = new QPropertyAnimation(d->under, "opacity");
|
|
|
|
d->opacityAnimation->setDuration(duration);
|
|
|
|
d->opacityAnimation->setEndValue(0);
|
|
|
|
group->addAnimation(d->opacityAnimation);
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
/* TODO: move this to a function */
|
2009-10-17 22:04:58 +02:00
|
|
|
d->geometryAnimation = new QPropertyAnimation(d->under, "geometry");
|
|
|
|
d->geometryAnimation->setDuration(duration);
|
|
|
|
QRectF initial(d->under->geometry());
|
2009-10-15 21:36:38 +02:00
|
|
|
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);
|
2009-10-17 22:04:58 +02:00
|
|
|
d->geometryAnimation->setEndValue(end);
|
|
|
|
group->addAnimation(d->geometryAnimation);
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
d->scaleAnimation = new QPropertyAnimation(d->under, "scale");
|
|
|
|
d->scaleAnimation->setDuration(duration);
|
|
|
|
d->scaleAnimation->setEndValue(scale);
|
|
|
|
group->addAnimation(d->scaleAnimation);
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
d->animation = group;
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-10-17 07:17:05 +02:00
|
|
|
//This makes sure that if there is *not* a shadow widget, the
|
|
|
|
//parent widget will still remain visible
|
2009-10-17 22:04:58 +02:00
|
|
|
connect(d->animation, SIGNAL(finished()), this, SLOT(resetPulser()));
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractAnimation* PulseAnimation::render(QObject* parent)
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
2009-10-16 00:29:21 +02:00
|
|
|
createAnimation();
|
2009-10-17 22:04:58 +02:00
|
|
|
d->under->setOpacity(1);
|
|
|
|
return d->animation;
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAnimation::start()
|
|
|
|
{
|
2009-10-17 22:04:58 +02:00
|
|
|
d->under->setOpacity(1);
|
|
|
|
d->animation->start();
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|