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
|
|
|
#include <QtGui/QGraphicsOpacityEffect>
|
|
|
|
|
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-10-22 06:34:03 +02:00
|
|
|
QGraphicsOpacityEffect *effect = m_opacityEffect.data();
|
|
|
|
delete effect;
|
2009-10-21 18:29:00 +02:00
|
|
|
|
|
|
|
Animation::setWidgetToAnimate(widget);
|
|
|
|
|
2009-10-22 06:34:03 +02:00
|
|
|
if (widget) {
|
|
|
|
effect = new QGraphicsOpacityEffect(widget);
|
2009-10-22 19:39:43 +02:00
|
|
|
effect->setOpacity(m_startOpacity);
|
2009-10-22 06:34:03 +02:00
|
|
|
widget->setGraphicsEffect(effect);
|
|
|
|
m_opacityEffect = effect;
|
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 09:47:05 +02:00
|
|
|
QAbstractAnimation* FadeAnimation::render(QObject* parent)
|
|
|
|
{
|
2009-10-15 21:36:38 +02:00
|
|
|
//create animation
|
2009-10-23 20:39:57 +02:00
|
|
|
QPropertyAnimation* anim = dynamic_cast<QPropertyAnimation* >(animation());
|
|
|
|
if (!anim) {
|
|
|
|
anim = new QPropertyAnimation(m_opacityEffect.data(), "opacity", parent);
|
|
|
|
setAnimation(anim);
|
|
|
|
}
|
|
|
|
|
2009-10-22 19:39:43 +02:00
|
|
|
anim->setStartValue(m_startOpacity);
|
|
|
|
anim->setEndValue(m_targetOpacity);
|
2009-10-20 23:04:49 +02:00
|
|
|
anim->setDuration(duration());
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
return anim;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|
|
|
|
|