move panelttoolbox animation to new animation api
svn path=/trunk/KDE/kdelibs/; revision=1077220
This commit is contained in:
parent
d7e63f903c
commit
c334033bf3
@ -24,6 +24,8 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRadialGradient>
|
#include <QRadialGradient>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
#include <QWeakPointer>
|
||||||
|
|
||||||
#include <kcolorscheme.h>
|
#include <kcolorscheme.h>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
@ -43,15 +45,13 @@ class PanelToolBoxPrivate
|
|||||||
public:
|
public:
|
||||||
PanelToolBoxPrivate()
|
PanelToolBoxPrivate()
|
||||||
: icon("plasma"),
|
: icon("plasma"),
|
||||||
animId(0),
|
|
||||||
animFrame(0),
|
animFrame(0),
|
||||||
highlighting(false)
|
highlighting(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KIcon icon;
|
KIcon icon;
|
||||||
int animId;
|
QWeakPointer<QPropertyAnimation> anim;
|
||||||
qreal animFrame;
|
qreal animFrame;
|
||||||
QColor fgColor;
|
QColor fgColor;
|
||||||
QColor bgColor;
|
QColor bgColor;
|
||||||
@ -83,6 +83,7 @@ PanelToolBox::PanelToolBox(Containment *parent)
|
|||||||
|
|
||||||
PanelToolBox::~PanelToolBox()
|
PanelToolBox::~PanelToolBox()
|
||||||
{
|
{
|
||||||
|
d->anim.clear();
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,36 +268,46 @@ void PanelToolBox::highlight(bool highlighting)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Animator *animdriver = Plasma::Animator::self();
|
d->highlighting = highlighting;
|
||||||
|
|
||||||
if (d->animId) {
|
QPropertyAnimation *anim = d->anim.data();
|
||||||
animdriver->stopCustomAnimation(d->animId);
|
if (d->highlighting) {
|
||||||
|
if (anim) {
|
||||||
|
anim->stop();
|
||||||
|
d->anim.clear();
|
||||||
|
}
|
||||||
|
anim = new QPropertyAnimation(this, "highlight", this);
|
||||||
|
d->anim = anim;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->highlighting = highlighting;
|
if (anim->state() != QAbstractAnimation::Stopped) {
|
||||||
d->animId = animdriver->customAnimation(10, 240,
|
anim->stop();
|
||||||
highlighting ? Plasma::Animator::EaseInCurve
|
}
|
||||||
: Plasma::Animator::EaseOutCurve,
|
|
||||||
this, "animate");
|
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 = progress;
|
||||||
d->animFrame = size() * progress;
|
|
||||||
} else {
|
|
||||||
d->animFrame = size() * (1.0 - progress);
|
|
||||||
}
|
|
||||||
|
|
||||||
//kDebug() << "animating at" << progress << "for" << d->animFrame;
|
|
||||||
|
|
||||||
if (progress >= 1) {
|
|
||||||
d->animId = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal PanelToolBox::highlightValue() const
|
||||||
|
{
|
||||||
|
return d->animFrame;
|
||||||
|
}
|
||||||
|
|
||||||
void PanelToolBox::toggle()
|
void PanelToolBox::toggle()
|
||||||
{
|
{
|
||||||
setShowing(!isShowing());
|
setShowing(!isShowing());
|
||||||
|
@ -41,6 +41,7 @@ class PanelToolBoxPrivate;
|
|||||||
class PanelToolBox : public InternalToolBox
|
class PanelToolBox : public InternalToolBox
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(qreal highlight READ highlightValue WRITE setHighlightValue)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PanelToolBox(Containment *parent);
|
explicit PanelToolBox(Containment *parent);
|
||||||
@ -62,7 +63,8 @@ protected:
|
|||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void animate(qreal progress);
|
void setHighlightValue(qreal progress);
|
||||||
|
qreal highlightValue() const;
|
||||||
void toggle();
|
void toggle();
|
||||||
void assignColors();
|
void assignColors();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user