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),
|
|
|
|
geometryAnimation(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 *geometryAnimation;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Animation::setWidgetToAnimate(widget);
|
|
|
|
if (d->animation.data()) {
|
|
|
|
delete d->animation.data();
|
|
|
|
d->animation.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
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-18 22:53:40 +01:00
|
|
|
if (d->under->size() != widgetToAnimate()->size())
|
2009-11-17 23:53:08 +01:00
|
|
|
setCopy();
|
2009-11-13 02:20:51 +01:00
|
|
|
|
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
|
|
|
}
|
2009-10-23 20:39:57 +02:00
|
|
|
}
|
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
if (dirty)
|
2009-12-03 20:30:02 +01:00
|
|
|
connect(d->animation.data(), SIGNAL(finished()), this, SLOT(resetPulser()));
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractAnimation* PulseAnimation::render(QObject* parent)
|
|
|
|
{
|
2009-12-03 20:30:02 +01:00
|
|
|
Q_UNUSED(parent);
|
2009-10-22 04:50:58 +02:00
|
|
|
|
2009-10-22 04:59:24 +02:00
|
|
|
createAnimation(duration());
|
2009-12-03 20:30:02 +01:00
|
|
|
return d->animation.data();
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|