move panelttoolbox animation to new animation api

svn path=/trunk/KDE/kdelibs/; revision=1077220
This commit is contained in:
Igor Trindade Oliveira 2010-01-19 18:12:23 +00:00
parent d7e63f903c
commit c334033bf3
2 changed files with 38 additions and 25 deletions

View File

@ -24,6 +24,8 @@
#include <QPainter>
#include <QRadialGradient>
#include <QApplication>
#include <QPropertyAnimation>
#include <QWeakPointer>
#include <kcolorscheme.h>
#include <kdebug.h>
@ -43,15 +45,13 @@ class PanelToolBoxPrivate
public:
PanelToolBoxPrivate()
: icon("plasma"),
animId(0),
animFrame(0),
highlighting(false)
{
}
KIcon icon;
int animId;
QWeakPointer<QPropertyAnimation> anim;
qreal animFrame;
QColor fgColor;
QColor bgColor;
@ -83,6 +83,7 @@ PanelToolBox::PanelToolBox(Containment *parent)
PanelToolBox::~PanelToolBox()
{
d->anim.clear();
delete d;
}
@ -267,36 +268,46 @@ void PanelToolBox::highlight(bool highlighting)
return;
}
Plasma::Animator *animdriver = Plasma::Animator::self();
d->highlighting = highlighting;
if (d->animId) {
animdriver->stopCustomAnimation(d->animId);
QPropertyAnimation *anim = d->anim.data();
if (d->highlighting) {
if (anim) {
anim->stop();
d->anim.clear();
}
anim = new QPropertyAnimation(this, "highlight", this);
d->anim = anim;
}
d->highlighting = highlighting;
d->animId = animdriver->customAnimation(10, 240,
highlighting ? Plasma::Animator::EaseInCurve
: Plasma::Animator::EaseOutCurve,
this, "animate");
if (anim->state() != QAbstractAnimation::Stopped) {
anim->stop();
}
anim->setDuration(240);
anim->setStartValue(0);
anim->setEndValue(size());
if(d->highlighting) {
anim->start();
} else {
anim->setDirection(QAbstractAnimation::Backward);
anim->start(QAbstractAnimation::DeleteWhenStopped);
}
}
void PanelToolBox::animate(qreal progress)
void PanelToolBox::setHighlightValue(qreal progress)
{
if (d->highlighting) {
d->animFrame = size() * progress;
} else {
d->animFrame = size() * (1.0 - progress);
}
//kDebug() << "animating at" << progress << "for" << d->animFrame;
if (progress >= 1) {
d->animId = 0;
}
d->animFrame = progress;
update();
}
qreal PanelToolBox::highlightValue() const
{
return d->animFrame;
}
void PanelToolBox::toggle()
{
setShowing(!isShowing());

View File

@ -41,6 +41,7 @@ class PanelToolBoxPrivate;
class PanelToolBox : public InternalToolBox
{
Q_OBJECT
Q_PROPERTY(qreal highlight READ highlightValue WRITE setHighlightValue)
public:
explicit PanelToolBox(Containment *parent);
@ -62,7 +63,8 @@ protected:
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
protected slots:
void animate(qreal progress);
void setHighlightValue(qreal progress);
qreal highlightValue() const;
void toggle();
void assignColors();