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)
|
2010-04-08 19:07:33 +02:00
|
|
|
: EasingAnimation(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-12-04 20:06:01 +01:00
|
|
|
void FadeAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
2009-12-04 02:14:23 +01:00
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *w = targetWidget();
|
2009-12-04 02:14:23 +01:00
|
|
|
if (!w) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-04 20:06:01 +01:00
|
|
|
if (oldState == Stopped && newState == Running) {
|
|
|
|
w->setOpacity(direction() == Forward ? m_startOpacity : m_targetOpacity);
|
|
|
|
} else if (newState == Stopped) {
|
|
|
|
w->setOpacity(direction() == Forward ? m_targetOpacity : m_startOpacity);
|
2009-10-22 06:34:03 +02:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2010-04-08 19:07:33 +02:00
|
|
|
void FadeAnimation::updateEffectiveTime(int currentTime)
|
2009-10-21 09:47:05 +02:00
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *w = targetWidget();
|
2009-12-04 20:06:01 +01:00
|
|
|
if (w) {
|
|
|
|
qreal delta = currentTime / qreal(duration());
|
2010-04-23 01:10:29 +02:00
|
|
|
delta *= m_startOpacity - m_targetOpacity;
|
2009-12-04 20:06:01 +01:00
|
|
|
w->setOpacity(m_startOpacity - delta);
|
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|
2010-02-24 00:31:45 +01:00
|
|
|
|
2012-01-22 15:37:37 +01:00
|
|
|
#include "moc_fade_p.cpp"
|