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.
|
|
|
|
*/
|
2010-04-15 20:51:26 +02:00
|
|
|
#include "widgetsnapshot_p.h"
|
2009-10-22 21:46:16 +02:00
|
|
|
#include "pulser_p.h"
|
2010-01-05 00:06:50 +01:00
|
|
|
|
2009-10-22 04:50:58 +02:00
|
|
|
#include <QEvent>
|
|
|
|
#include <QGraphicsWidget>
|
|
|
|
#include <QParallelAnimationGroup>
|
2009-10-15 21:36:38 +02:00
|
|
|
#include <QPropertyAnimation>
|
2010-01-04 22:11:02 +01:00
|
|
|
#include <QWeakPointer>
|
2010-01-05 00:06:50 +01:00
|
|
|
|
2009-10-22 04:50:58 +02:00
|
|
|
#include <kdebug.h>
|
2010-01-04 22:11:02 +01:00
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-12-07 23:55:56 +01:00
|
|
|
PulseAnimation::PulseAnimation(QObject *parent)
|
2010-04-08 19:07:33 +02:00
|
|
|
: EasingAnimation(parent),
|
2010-01-04 10:17:49 +01:00
|
|
|
m_zvalue(0),
|
|
|
|
m_scale(0),
|
|
|
|
m_opacity(0),
|
2010-01-04 22:11:02 +01:00
|
|
|
m_endScale(1.5)
|
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
|
|
|
|
2010-01-05 00:06:50 +01:00
|
|
|
void PulseAnimation::setTargetScale(qreal scale)
|
|
|
|
{
|
|
|
|
m_endScale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal PulseAnimation::targetScale() const
|
|
|
|
{
|
|
|
|
return m_endScale;
|
|
|
|
}
|
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
void PulseAnimation::setCopy()
|
2009-12-03 20:30:02 +01:00
|
|
|
{
|
2010-01-04 10:17:49 +01:00
|
|
|
QGraphicsWidget *target = targetWidget();
|
|
|
|
|
|
|
|
if (!target) {
|
2010-01-04 22:11:02 +01:00
|
|
|
m_under.clear();
|
2009-12-07 17:37:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-04 22:11:02 +01:00
|
|
|
if (!m_under.data()) {
|
2010-04-15 20:51:26 +02:00
|
|
|
m_under = new WidgetSnapShot;
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
|
2010-01-04 22:11:02 +01:00
|
|
|
m_under.data()->setTarget(target);
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
m_zvalue = target->zValue() - 1;
|
|
|
|
m_scale = target->scale();
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2010-01-04 22:11:02 +01:00
|
|
|
m_under.data()->setOpacity(m_opacity);
|
|
|
|
m_under.data()->setScale(m_scale);
|
|
|
|
m_under.data()->setZValue(m_zvalue);
|
2009-10-17 07:17:05 +02:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
void PulseAnimation::resetPulser()
|
|
|
|
{
|
2010-01-04 22:11:02 +01:00
|
|
|
if (m_under.data()) {
|
|
|
|
m_under.data()->setOpacity(m_opacity);
|
|
|
|
m_under.data()->setScale(m_scale);
|
|
|
|
m_under.data()->setZValue(m_zvalue);
|
2010-01-04 23:56:41 +01:00
|
|
|
m_under.data()->hide();
|
2010-01-04 10:17:49 +01: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)
|
|
|
|
{
|
2010-01-04 10:17:49 +01:00
|
|
|
if (!targetWidget()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-12-07 17:37:23 +01:00
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
if (oldState == Stopped && newState == Running) {
|
2010-01-04 22:11:02 +01:00
|
|
|
if (!m_under.data() || m_under.data()->target() != targetWidget() || m_under.data()->size() != targetWidget()->size()) {
|
2010-01-04 10:17:49 +01:00
|
|
|
setCopy();
|
|
|
|
}
|
2009-12-07 17:37:23 +01:00
|
|
|
|
2010-02-22 23:06:05 +01:00
|
|
|
if (m_under.data()->isIconBigger()) {
|
|
|
|
m_under.data()->setScale(0);
|
|
|
|
m_endScale = 1.0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_scale = 0;
|
|
|
|
m_endScale = 1.5;
|
|
|
|
}
|
|
|
|
|
2010-01-04 23:56:41 +01:00
|
|
|
if (m_under.data()->isVisible() == false) {
|
|
|
|
m_under.data()->setVisible(true);
|
|
|
|
}
|
|
|
|
|
2010-01-04 22:11:02 +01:00
|
|
|
m_under.data()->setOpacity(direction() == Forward ? 1 : 0);
|
|
|
|
m_under.data()->setScale(direction() == Forward ? m_scale : m_endScale);
|
2010-01-04 10:17:49 +01:00
|
|
|
} else if (newState == Stopped) {
|
|
|
|
resetPulser();
|
|
|
|
}
|
2009-12-07 17:37:23 +01:00
|
|
|
}
|
|
|
|
|
2010-04-08 19:07:33 +02:00
|
|
|
void PulseAnimation::updateEffectiveTime(int currentTime)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
2010-01-04 22:11:02 +01:00
|
|
|
if (m_under.data()) {
|
2010-04-23 01:10:29 +02:00
|
|
|
qreal delta = currentTime / qreal(duration());
|
2010-02-22 23:06:05 +01:00
|
|
|
|
|
|
|
if (m_under.data()->isIconBigger()) {
|
2010-02-22 23:17:17 +01:00
|
|
|
m_under.data()->setScale(delta);
|
2010-02-22 23:06:05 +01:00
|
|
|
} else {
|
|
|
|
m_under.data()->setScale(delta);
|
|
|
|
delta = (1 - m_endScale) * delta;
|
|
|
|
m_under.data()->setScale(1 - delta);
|
|
|
|
}
|
2009-12-07 21:21:50 +01:00
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
delta = currentTime / qreal(duration());
|
2009-12-07 21:21:50 +01:00
|
|
|
if (direction() == Forward) {
|
2010-01-04 22:11:02 +01:00
|
|
|
m_under.data()->setOpacity(1.0 - delta);
|
2009-12-07 21:21:50 +01:00
|
|
|
} else if (direction() == Backward) {
|
2010-01-04 22:11:02 +01:00
|
|
|
m_under.data()->setOpacity(delta);
|
2009-12-07 21:21:50 +01:00
|
|
|
}
|
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|
2010-02-24 00:31:45 +01:00
|
|
|
|
|
|
|
#include <../pulser_p.moc>
|