2009-10-15 21:36:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
|
|
|
*
|
|
|
|
* 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 "fade_p.h"
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
#include <QRect>
|
2009-10-21 18:29:00 +02:00
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-10-22 06:34:03 +02:00
|
|
|
FadeAnimation::FadeAnimation(QObject *parent)
|
|
|
|
: Animation(parent),
|
2009-10-22 19:39:43 +02:00
|
|
|
m_startOpacity(0),
|
|
|
|
m_targetOpacity(1)
|
2009-10-21 18:29:00 +02:00
|
|
|
{
|
2009-10-22 06:34:03 +02:00
|
|
|
}
|
2009-10-21 18:29:00 +02:00
|
|
|
|
2009-10-22 06:34:03 +02:00
|
|
|
FadeAnimation::~FadeAnimation()
|
2009-10-21 18:29:00 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-22 19:39:43 +02:00
|
|
|
void FadeAnimation::setStartOpacity(qreal factor)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
2009-10-22 19:39:43 +02:00
|
|
|
m_startOpacity = qBound(qreal(0.0), factor, qreal(1.0));
|
2009-10-21 18:29:00 +02:00
|
|
|
}
|
|
|
|
|
2009-10-22 19:39:43 +02:00
|
|
|
qreal FadeAnimation::startOpacity() const
|
2009-10-22 15:58:35 +02:00
|
|
|
{
|
2009-10-22 19:39:43 +02:00
|
|
|
return m_startOpacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FadeAnimation::setTargetOpacity(qreal factor)
|
|
|
|
{
|
|
|
|
m_targetOpacity = qBound(qreal(0.0), factor, qreal(1.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FadeAnimation::targetOpacity() const
|
|
|
|
{
|
|
|
|
return m_targetOpacity;
|
2009-10-22 15:58:35 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 18:29:00 +02:00
|
|
|
void FadeAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
|
|
|
|
{
|
2009-12-04 02:14:23 +01:00
|
|
|
if (widget == widgetToAnimate()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-21 18:29:00 +02:00
|
|
|
Animation::setWidgetToAnimate(widget);
|
2009-10-22 06:34:03 +02:00
|
|
|
if (widget) {
|
2009-11-11 13:04:58 +01:00
|
|
|
widget->setOpacity(m_startOpacity);
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
2009-12-04 15:56:19 +01:00
|
|
|
|
|
|
|
if(m_anim.data()) {
|
|
|
|
delete m_anim.data();
|
|
|
|
m_anim.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPropertyAnimation *anim = new QPropertyAnimation(widget, "opacity", widget);
|
|
|
|
anim->setStartValue(startOpacity());
|
|
|
|
anim->setEndValue(targetOpacity());
|
|
|
|
|
|
|
|
m_anim = anim;
|
2009-12-04 02:14:23 +01:00
|
|
|
}
|
2009-12-03 20:30:02 +01:00
|
|
|
|
2009-12-04 02:14:23 +01:00
|
|
|
void FadeAnimation::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState)
|
|
|
|
{
|
|
|
|
QGraphicsWidget *w = widgetToAnimate();
|
|
|
|
if (!w) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-04 15:56:19 +01:00
|
|
|
if( (oldState == QAbstractAnimation::Stopped) &&
|
|
|
|
(newState == QAbstractAnimation::Running)) {
|
|
|
|
QPropertyAnimation *anim = m_anim.data();
|
|
|
|
|
|
|
|
anim->setDirection(direction());
|
|
|
|
anim->start();
|
2009-10-22 06:34:03 +02:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-12-04 02:14:23 +01:00
|
|
|
void FadeAnimation::updateCurrentTime(int currentTime)
|
2009-10-21 09:47:05 +02:00
|
|
|
{
|
2009-12-04 15:56:19 +01:00
|
|
|
m_anim.data()->setCurrentTime(currentTime);
|
2009-10-23 20:39:57 +02:00
|
|
|
|
2009-12-04 02:14:23 +01:00
|
|
|
Animation::updateCurrentTime(currentTime);
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|
|
|
|
|