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),
|
2009-12-07 19:16:33 +01:00
|
|
|
scale(0),
|
2009-12-07 21:21:50 +01:00
|
|
|
mopacity(0),
|
2009-12-07 21:24:20 +01:00
|
|
|
endScale(1.5)
|
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;
|
2009-12-07 19:16:33 +01:00
|
|
|
qreal zvalue, scale, mopacity;
|
|
|
|
qreal endScale;
|
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;
|
|
|
|
}
|
2009-12-07 21:21:50 +01:00
|
|
|
setCopy();
|
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);
|
|
|
|
|
2009-10-17 22:04:58 +02:00
|
|
|
d->zvalue = target->zValue();
|
|
|
|
--d->zvalue;
|
2009-12-07 19:16:33 +01:00
|
|
|
d->scale = target->scale();
|
2009-11-13 02:20:51 +01:00
|
|
|
|
|
|
|
d->under = shadow;
|
|
|
|
d->under->setOpacity(d->mopacity);
|
2009-12-07 19:16:33 +01:00
|
|
|
d->under->setScale(d->scale);
|
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);
|
2009-12-07 19:16:33 +01:00
|
|
|
d->under->setScale(d->scale);
|
2009-11-13 02:20:51 +01:00
|
|
|
d->under->setZValue(d->zvalue);
|
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) {
|
2009-12-07 21:21:50 +01:00
|
|
|
if (d->under->size() != widgetToAnimate()->size()) {
|
|
|
|
setCopy();
|
2009-12-07 17:37:23 +01:00
|
|
|
}
|
2009-12-07 21:21:50 +01:00
|
|
|
d->under->setOpacity(direction() == Forward ? 1 : 0);
|
|
|
|
d->under->setScale(direction() == Forward ? d->scale : d->endScale);
|
2009-12-07 17:37:23 +01:00
|
|
|
} else if (newState == Stopped) {
|
2009-12-07 21:21:50 +01:00
|
|
|
resetPulser();
|
2009-12-07 17:37:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAnimation::updateCurrentTime(int currentTime)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
2009-12-07 21:21:50 +01:00
|
|
|
QGraphicsWidget *w = d->under;
|
|
|
|
if (w) {
|
|
|
|
qreal delta = currentTime / qreal(duration());
|
|
|
|
delta = (1 - d->endScale) * delta;
|
|
|
|
w->setScale(1 - delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w) {
|
|
|
|
qreal delta = currentTime / qreal(duration());
|
|
|
|
if (direction() == Forward) {
|
|
|
|
w->setOpacity(1.0 - delta);
|
|
|
|
} else if (direction() == Backward) {
|
|
|
|
w->setOpacity(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Animation::updateCurrentTime(currentTime);
|
2009-10-22 04:50:58 +02:00
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|