* standardize and add a parent in the ctor

* 1.0 is the proper start value when we're going towards 0

svn path=/trunk/KDE/kdelibs/; revision=1038855
This commit is contained in:
Aaron J. Seigo 2009-10-22 04:34:03 +00:00
parent d04ef47d95
commit 27d61c2fca
2 changed files with 26 additions and 34 deletions

View File

@ -27,58 +27,44 @@
namespace Plasma
{
class FadeAnimationPrivate
{
public:
FadeAnimationPrivate()
{
}
~FadeAnimationPrivate()
{
}
QGraphicsOpacityEffect *opacityEffect;
};
FadeAnimation::FadeAnimation(qreal factor)
: d(new FadeAnimationPrivate()),
m_animFactor(qBound(qreal(0.0), factor, qreal(1.0)))
FadeAnimation::FadeAnimation(QObject *parent)
: Animation(parent),
m_animFactor(0.5)
{
}
FadeAnimation::~FadeAnimation()
{
delete d;
}
void FadeAnimation::setFactor(qreal factor)
{
m_animFactor = qBound(qreal(0.0), factor, qreal(1.0));
}
void FadeAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
{
QGraphicsWidget *m_widget = widgetToAnimate();
if (m_widget) {
QGraphicsEffect *effect = m_widget->graphicsEffect();
if (effect && dynamic_cast<QGraphicsOpacityEffect *>(effect)) {
effect->deleteLater();
}
}
QGraphicsOpacityEffect *effect = m_opacityEffect.data();
delete effect;
Animation::setWidgetToAnimate(widget);
d->opacityEffect = new QGraphicsOpacityEffect(widget);
widget->setGraphicsEffect(d->opacityEffect);
if (widget) {
effect = new QGraphicsOpacityEffect(widget);
effect->setOpacity(qreal(1.0));
widget->setGraphicsEffect(effect);
m_opacityEffect = effect;
}
}
QAbstractAnimation* FadeAnimation::render(QObject* parent)
{
//create animation
QPropertyAnimation* anim = new QPropertyAnimation(d->opacityEffect, "opacity", parent);
anim->setStartValue(0);
QPropertyAnimation* anim = new QPropertyAnimation(m_opacityEffect.data(), "opacity", parent);
anim->setStartValue(qreal(1.0));
anim->setEndValue(m_animFactor);
anim->setDuration(duration());
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
return anim;
}

View File

@ -27,6 +27,8 @@
#include <plasma/animations/animation.h>
#include <plasma/plasma_export.h>
class QGraphicsOpacityEffect;
namespace Plasma
{
@ -41,18 +43,22 @@ class FadeAnimationPrivate;
class FadeAnimation : public Animation
{
Q_OBJECT
Q_PROPERTY(qreal factor READ factor WRITE setFactor)
public:
FadeAnimation(qreal factor = 0.5);
FadeAnimation(QObject *parent = 0);
virtual ~FadeAnimation();
qreal factor() const;
void setFactor(qreal);
void setWidgetToAnimate(QGraphicsWidget *widget);
protected:
virtual QAbstractAnimation* render(QObject* parent = 0);
private:
FadeAnimationPrivate *const d;
QWeakPointer<QGraphicsOpacityEffect> m_opacityEffect;
qreal m_animFactor;
};