Change the all Plasma::Animator::self() to Plasma::Animator::create in FlashingLable class.

Patch-by: Andre Loureiro <loureiro.andrew@gmail.com>

svn path=/trunk/KDE/kdelibs/; revision=1088729
This commit is contained in:
Bruno de Oliveira Abinader 2010-02-11 13:04:12 +00:00
parent ef3e69f672
commit 5571e3e549
2 changed files with 43 additions and 21 deletions

View File

@ -24,6 +24,7 @@
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QTimeLine> #include <QtCore/QTimeLine>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QWeakPointer>
#include <QtGui/QPainter> #include <QtGui/QPainter>
#include <QtGui/QPixmap> #include <QtGui/QPixmap>
#include <QtGui/QColor> #include <QtGui/QColor>
@ -31,6 +32,7 @@
#include <kdebug.h> #include <kdebug.h>
#include <plasma/animator.h> #include <plasma/animator.h>
#include <plasma/animations/animation.h>
#include <plasma/theme.h> #include <plasma/theme.h>
using namespace Plasma; using namespace Plasma;
@ -52,7 +54,6 @@ class Plasma::FlashingLabelPrivate
defaultDuration(3000), defaultDuration(3000),
type(FlashingLabelPrivate::Text), type(FlashingLabelPrivate::Text),
color(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)), color(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)),
animId(0),
state(FlashingLabelPrivate::Invisible), state(FlashingLabelPrivate::Invisible),
autohide(false) autohide(false)
{ {
@ -67,7 +68,7 @@ class Plasma::FlashingLabelPrivate
void renderPixmap(const QSize &size); void renderPixmap(const QSize &size);
void setupFlash(int duration); void setupFlash(int duration);
void elementAnimationFinished(int); void elementAnimationFinished();
void setPalette(); void setPalette();
FlashingLabel *q; FlashingLabel *q;
@ -80,7 +81,7 @@ class Plasma::FlashingLabelPrivate
QFont font; QFont font;
QPixmap pixmap; QPixmap pixmap;
int animId; QWeakPointer<Plasma::Animation> anim;
QPixmap renderedPixmap; QPixmap renderedPixmap;
QTextOption textOption; QTextOption textOption;
@ -169,11 +170,11 @@ void FlashingLabel::setAutohide(bool autohide)
d->autohide = autohide; d->autohide = autohide;
if (autohide) { if (autohide) {
connect(Plasma::Animator::self(), SIGNAL(elementAnimationFinished(int)), if (d->anim.data()) {
this, SLOT(elementAnimationFinished(int))); connect(d->anim.data(), SIGNAL(finished()), this, SLOT(elementAnimationFinished()));
} else { }
disconnect(Plasma::Animator::self(), SIGNAL(elementAnimationFinished(int)), } else if (d->anim.data()) {
this, SLOT(elementAnimationFinished(int))); disconnect(d->anim.data(), SIGNAL(finished()), this, SLOT(elementAnimationFinished()));
} }
} }
@ -198,8 +199,19 @@ void FlashingLabel::fadeIn()
} }
d->state = FlashingLabelPrivate::Visible; d->state = FlashingLabelPrivate::Visible;
d->animId = Plasma::Animator::self()->animateElement(this, Plasma::Animator::AppearAnimation); if (!d->anim.data()) {
Plasma::Animator::self()->setInitialPixmap(d->animId, d->renderedPixmap); d->anim = Plasma::Animator::create(Plasma::Animator::PixmapTransitionAnimation);
Plasma::Animation *animation = d->anim.data();
animation->setProperty("startPixmap", d->renderedPixmap);
animation->setTargetWidget(this);
animation->start();
} else {
Plasma::Animation *animation = d->anim.data();
if (animation->state() == QAbstractAnimation::Running) {
animation->stop();
animation->start();
}
}
} }
void FlashingLabel::fadeOut() void FlashingLabel::fadeOut()
@ -209,9 +221,18 @@ void FlashingLabel::fadeOut()
} }
d->state = FlashingLabelPrivate::Invisible; d->state = FlashingLabelPrivate::Invisible;
d->animId = Plasma::Animator::self()->animateElement( if (d->anim.data()) {
this, Plasma::Animator::DisappearAnimation); Plasma::Animation *animation = d->anim.data();
Plasma::Animator::self()->setInitialPixmap(d->animId, d->renderedPixmap); animation->setProperty("direction", QAbstractAnimation::Backward);
animation->start(QAbstractAnimation::DeleteWhenStopped);
} else {
d->anim = Plasma::Animator::create(Plasma::Animator::PixmapTransitionAnimation);
Plasma::Animation *animation = d->anim.data();
animation->setProperty("direction", QAbstractAnimation::Backward);
animation->setProperty("startPixmap", d->renderedPixmap);
animation->setTargetWidget(this);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
} }
void FlashingLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void FlashingLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@ -219,10 +240,10 @@ void FlashingLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
Q_UNUSED(option) Q_UNUSED(option)
Q_UNUSED(widget) Q_UNUSED(widget)
if (d->animId && !Plasma::Animator::self()->currentPixmap(d->animId).isNull()) { if (d->anim.data()) {
painter->drawPixmap(0, 0, Plasma::Animator::self()->currentPixmap(d->animId)); Plasma::Animation *animation = d->anim.data();
painter->drawPixmap(0, 0, qvariant_cast<QPixmap>(animation->property("currentPixmap")));
} else { } else {
d->animId = 0;
if (d->state == FlashingLabelPrivate::Visible) { if (d->state == FlashingLabelPrivate::Visible) {
painter->drawPixmap(0, 0, d->renderedPixmap); painter->drawPixmap(0, 0, d->renderedPixmap);
@ -274,8 +295,9 @@ void FlashingLabelPrivate::renderPixmap(const QSize &size)
} }
painter.end(); painter.end();
if (animId) { if (anim.data()) {
Plasma::Animator::self()->setInitialPixmap(animId, renderedPixmap); Plasma::Animation *animation = anim.data();
animation->setProperty("startPixmap", renderedPixmap);
} }
} }
@ -296,9 +318,9 @@ void FlashingLabelPrivate::setupFlash(int duration)
} }
} }
void FlashingLabelPrivate::elementAnimationFinished(int id) void FlashingLabelPrivate::elementAnimationFinished()
{ {
if (autohide && state == FlashingLabelPrivate::Invisible && id == animId) { if (autohide && state == FlashingLabelPrivate::Invisible && anim.data()) {
q->hide(); q->hide();
} }
} }

View File

@ -78,7 +78,7 @@ protected Q_SLOTS:
void fadeOut(); void fadeOut();
private: private:
Q_PRIVATE_SLOT(d, void elementAnimationFinished(int)) Q_PRIVATE_SLOT(d, void elementAnimationFinished())
Q_PRIVATE_SLOT(d, void setPalette()) Q_PRIVATE_SLOT(d, void setPalette())
FlashingLabelPrivate *const d; FlashingLabelPrivate *const d;
}; };