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:
|
2009-11-18 22:53:40 +01:00
|
|
|
* - fix opacity (for some reason is not working)
|
2009-10-16 00:29:21 +02:00
|
|
|
*/
|
|
|
|
|
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>
|
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()
|
2009-12-03 20:30:02 +01:00
|
|
|
: under(0),
|
2009-10-22 04:50:58 +02:00
|
|
|
zvalue(0),
|
|
|
|
mscale(0),
|
|
|
|
opacityAnimation(0),
|
|
|
|
scaleAnimation(0)
|
2009-10-17 22:04:58 +02:00
|
|
|
{}
|
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
~PulseAnimationPrivate()
|
2009-11-18 22:53:40 +01:00
|
|
|
{ }
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
QGraphicsWidget *under;
|
|
|
|
qreal zvalue, mscale, mopacity;
|
|
|
|
QPropertyAnimation *opacityAnimation;
|
|
|
|
QPropertyAnimation *scaleAnimation;
|
2009-12-03 20:30:02 +01:00
|
|
|
QWeakPointer<QParallelAnimationGroup> animation;
|
2009-10-17 22:04:58 +02:00
|
|
|
};
|
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
void PulseAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
|
|
|
|
{
|
2009-12-07 17:37:23 +01:00
|
|
|
if (widget == widgetToAnimate()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
Animation::setWidgetToAnimate(widget);
|
2009-12-07 17:37:23 +01:00
|
|
|
if (widget) {
|
|
|
|
if (d->under) {
|
|
|
|
delete d->under;
|
|
|
|
d->under = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
createAnimation();
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PulseAnimation::PulseAnimation(QObject *parent)
|
|
|
|
: Animation(parent), 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;
|
2009-11-17 23:53:08 +01:00
|
|
|
else
|
|
|
|
shadow = dynamic_cast<ShadowFake*>(d->under);
|
2009-11-13 02:20:51 +01:00
|
|
|
|
|
|
|
shadow->copyTarget(target);
|
|
|
|
|
|
|
|
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-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-12-06 16:24:09 +01:00
|
|
|
if (!d->under) {
|
2009-11-13 02:20:51 +01:00
|
|
|
setCopy();
|
2009-12-06 16:24:09 +01:00
|
|
|
}
|
2009-10-23 20:39:57 +02:00
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
QParallelAnimationGroup *anim = d->animation.data();
|
2009-10-23 20:39:57 +02:00
|
|
|
if (!anim) {
|
2009-10-27 15:22:21 +01:00
|
|
|
QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
|
2009-12-06 16:24:09 +01:00
|
|
|
connect(group, SIGNAL(finished()), this, SLOT(resetPulser()));
|
|
|
|
|
2009-10-27 15:22:21 +01:00
|
|
|
d->opacityAnimation = new QPropertyAnimation(d->under, "opacity");
|
|
|
|
d->opacityAnimation->setDuration(duration);
|
2009-12-03 20:30:02 +01:00
|
|
|
d->opacityAnimation->setStartValue(1);
|
2009-10-27 15:22:21 +01:00
|
|
|
d->opacityAnimation->setEndValue(0);
|
|
|
|
group->addAnimation(d->opacityAnimation);
|
|
|
|
|
|
|
|
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;
|
2009-10-23 20:39:57 +02:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-12-07 17:37:23 +01:00
|
|
|
void PulseAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (oldState == Stopped && newState == Running) {
|
|
|
|
QParallelAnimationGroup *anim = d->animation.data();
|
|
|
|
QAbstractAnimation::State temp = anim->state();
|
|
|
|
if (temp == QAbstractAnimation::Running) {
|
|
|
|
anim->stop();
|
|
|
|
/* TODO: will need to watch stateChanged signal
|
|
|
|
* and *then* reset the geometry
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
if (d->under->size() != widgetToAnimate()->size()) {
|
|
|
|
setCopy();
|
|
|
|
}
|
|
|
|
d->opacityAnimation->setEndValue(0);
|
|
|
|
/* TODO: save the scale factor somewhere */
|
|
|
|
d->scaleAnimation->setEndValue(1.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->animation.data()->start();
|
|
|
|
|
|
|
|
} else if (newState == Stopped) {
|
2009-12-07 17:41:40 +01:00
|
|
|
|
2009-12-07 17:37:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAnimation::updateCurrentTime(int currentTime)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
2009-10-22 04:50:58 +02:00
|
|
|
|
2009-12-07 17:41:40 +01:00
|
|
|
/* TODO: reuse this time and update properties without the
|
|
|
|
* the need of an internal animation group.
|
|
|
|
*/
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|