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-16 18:36:22 +02:00
|
|
|
PulseAnimation::PulseAnimation()
|
|
|
|
: animation(0),
|
|
|
|
under(0),
|
|
|
|
pulseGeometry(0),
|
|
|
|
zvalue(0),
|
|
|
|
mscale(0),
|
|
|
|
opacityAnimation(0),
|
|
|
|
geometryAnimation(0),
|
|
|
|
scaleAnimation(0)
|
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-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAnimation::setCopy(QGraphicsWidget *copy)
|
|
|
|
{
|
|
|
|
QGraphicsWidget *target = getAnimatedObject();
|
|
|
|
under = copy;
|
2009-10-17 07:17:05 +02:00
|
|
|
if (under != target) {
|
|
|
|
under->setParentItem(target);
|
|
|
|
mopacity = 0;
|
|
|
|
} else {
|
|
|
|
mopacity = under->opacity();
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
zvalue = target->zValue();
|
|
|
|
--zvalue;
|
|
|
|
under->setOpacity(0);
|
|
|
|
under->setZValue(zvalue);
|
|
|
|
mscale = under->scale();
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
zvalue = zCoordinate;
|
|
|
|
--zvalue;
|
|
|
|
under->setGeometry(updated);
|
|
|
|
under->setPos(0, 0);
|
|
|
|
under->setOpacity(0);
|
|
|
|
under->setZValue(zvalue);
|
|
|
|
|
|
|
|
/* TODO: move this to a function */
|
|
|
|
QRectF initial(under->geometry());
|
|
|
|
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-16 18:36:22 +02:00
|
|
|
geometryAnimation->setEndValue(end);
|
2009-10-17 07:17:05 +02:00
|
|
|
}
|
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
void PulseAnimation::resetPulser()
|
|
|
|
{
|
|
|
|
under->setGeometry(*pulseGeometry);
|
2009-10-17 07:17:05 +02:00
|
|
|
under->setOpacity(mopacity);
|
2009-10-15 21:36:38 +02:00
|
|
|
under->setZValue(zvalue);
|
|
|
|
under->setScale(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-17 07:17:05 +02:00
|
|
|
QGraphicsWidget *target = getAnimatedObject();
|
2009-10-16 00:29:21 +02:00
|
|
|
/* Fallback to parent widget if we don't have one 'shadow' widget */
|
2009-10-16 18:36:22 +02:00
|
|
|
if (!under) {
|
2009-10-17 07:17:05 +02:00
|
|
|
setCopy(target);
|
|
|
|
} else if (under != target) {
|
|
|
|
delete under;
|
|
|
|
under = new QGraphicsWidget(target);
|
|
|
|
setCopy(under);
|
2009-10-16 18:36:22 +02:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
pulseGeometry = new QRectF(under->geometry());
|
|
|
|
QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
|
2009-10-16 18:36:22 +02:00
|
|
|
opacityAnimation = new QPropertyAnimation(under, "opacity");
|
|
|
|
opacityAnimation->setDuration(duration);
|
|
|
|
opacityAnimation->setEndValue(0);
|
|
|
|
group->addAnimation(opacityAnimation);
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
/* TODO: move this to a function */
|
2009-10-16 18:36:22 +02:00
|
|
|
geometryAnimation = new QPropertyAnimation(under, "geometry");
|
|
|
|
geometryAnimation->setDuration(duration);
|
2009-10-15 21:36:38 +02:00
|
|
|
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);
|
2009-10-16 18:36:22 +02:00
|
|
|
geometryAnimation->setEndValue(end);
|
|
|
|
group->addAnimation(geometryAnimation);
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
scaleAnimation = new QPropertyAnimation(under, "scale");
|
|
|
|
scaleAnimation->setDuration(duration);
|
|
|
|
scaleAnimation->setEndValue(scale);
|
|
|
|
group->addAnimation(scaleAnimation);
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
animation = group;
|
|
|
|
|
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
|
|
|
|
connect(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();
|
|
|
|
under->setOpacity(1);
|
2009-10-15 21:36:38 +02:00
|
|
|
return animation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAnimation::start()
|
|
|
|
{
|
2009-10-16 00:29:21 +02:00
|
|
|
under->setOpacity(1);
|
2009-10-15 21:36:38 +02:00
|
|
|
animation->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|