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-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-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-12-07 23:55:56 +01:00
|
|
|
PulseAnimation::PulseAnimation(QObject *parent)
|
|
|
|
: Animation(parent),
|
|
|
|
zvalue(0), scale(0), mopacity(0), endScale(1.5),
|
|
|
|
under(0)
|
2009-10-17 22:04:58 +02:00
|
|
|
{
|
2009-12-07 23:55:56 +01:00
|
|
|
}
|
2009-10-17 22:04:58 +02:00
|
|
|
|
2009-12-07 23:55:56 +01:00
|
|
|
PulseAnimation::~PulseAnimation()
|
|
|
|
{
|
|
|
|
}
|
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) {
|
2009-12-07 21:21:50 +01:00
|
|
|
setCopy();
|
2009-12-03 20:30:02 +01: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-12-07 23:36:30 +01:00
|
|
|
/* the parent to an image, the animation will happen on the pixmap copy.
|
2009-11-13 02:20:51 +01:00
|
|
|
*/
|
2009-12-07 23:55:56 +01:00
|
|
|
if (!under)
|
|
|
|
under = new ShadowFake;
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2009-12-07 23:55:56 +01:00
|
|
|
under->copyTarget(target);
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2009-12-07 23:55:56 +01:00
|
|
|
zvalue = target->zValue();
|
|
|
|
--zvalue;
|
|
|
|
scale = target->scale();
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2009-12-07 23:55:56 +01:00
|
|
|
under->setOpacity(mopacity);
|
|
|
|
under->setScale(scale);
|
|
|
|
under->setZValue(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-12-07 23:55:56 +01:00
|
|
|
under->setOpacity(mopacity);
|
|
|
|
under->setScale(scale);
|
|
|
|
under->setZValue(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 23:55:56 +01:00
|
|
|
if (under->size() != widgetToAnimate()->size()) {
|
2009-12-07 21:21:50 +01:00
|
|
|
setCopy();
|
2009-12-07 17:37:23 +01:00
|
|
|
}
|
2009-12-07 23:36:30 +01:00
|
|
|
|
2009-12-07 23:55:56 +01:00
|
|
|
under->setOpacity(direction() == Forward ? 1 : 0);
|
|
|
|
under->setScale(direction() == Forward ? scale : endScale);
|
2009-12-07 23:36:30 +01:00
|
|
|
|
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 23:55:56 +01:00
|
|
|
QGraphicsWidget *w = under;
|
2009-12-07 21:21:50 +01:00
|
|
|
if (w) {
|
2009-12-09 17:34:43 +01:00
|
|
|
qreal delta = Animation::easingCurve().valueForProgress(
|
|
|
|
currentTime / qreal(duration()));
|
2009-12-07 23:55:56 +01:00
|
|
|
delta = (1 - endScale) * delta;
|
2009-12-07 21:21:50 +01:00
|
|
|
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-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|