From 25852b6eaafd81846b120591754fb74756c543a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 29 Jan 2010 12:37:42 +0000 Subject: [PATCH] Aurorae uses a QPropertyAnimation for the animation instead of Plasma::Animator::customAnimation. deprecatedCode-- svn path=/trunk/KDE/kdebase/workspace/; revision=1081956 --- clients/aurorae/src/aurorae.cpp | 109 +++++++++++++++++--------------- clients/aurorae/src/aurorae.h | 23 ++++--- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index ce56a8b8be..0b845b3e62 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -23,12 +23,12 @@ along with this program. If not, see . #include #include -#include #include #include #include #include +#include namespace Aurorae { @@ -190,12 +190,11 @@ AuroraeFactory *AuroraeFactory::s_instance = NULL; *******************************************************/ AuroraeButton::AuroraeButton(ButtonType type, KCommonDecoration *parent) : KCommonDecorationButton(type, parent) - , m_animationId(0) , m_animationProgress(0.0) , m_pressed(false) { + m_animation = new QPropertyAnimation(this, "animation", this); setAttribute(Qt::WA_NoSystemBackground); - connect(Plasma::Animator::self(), SIGNAL(customAnimationFinished(int)), this, SLOT(animationFinished(int))); } void AuroraeButton::reset(unsigned long changed) @@ -206,14 +205,17 @@ void AuroraeButton::reset(unsigned long changed) void AuroraeButton::enterEvent(QEvent *event) { Q_UNUSED(event) - if (m_animationId != 0) { - Plasma::Animator::self()->stopCustomAnimation(m_animationId); + if (isAnimating()) { + m_animation->stop(); } m_animationProgress = 0.0; int time = AuroraeFactory::instance()->themeConfig().animationTime(); if (time != 0) { - m_animationId = Plasma::Animator::self()->customAnimation(40 / (1000.0 / qreal(time)), - time, Plasma::Animator::EaseInCurve, this, "animationUpdate"); + m_animation->setDuration(time); + m_animation->setEasingCurve(QEasingCurve::InQuad); + m_animation->setStartValue(0.0); + m_animation->setEndValue(1.0); + m_animation->start(); } update(); } @@ -221,14 +223,17 @@ void AuroraeButton::enterEvent(QEvent *event) void AuroraeButton::leaveEvent(QEvent *event) { Q_UNUSED(event) - if (m_animationId != 0) { - Plasma::Animator::self()->stopCustomAnimation(m_animationId); + if (isAnimating()) { + m_animation->stop(); } m_animationProgress = 0.0; int time = AuroraeFactory::instance()->themeConfig().animationTime(); if (time != 0) { - m_animationId = Plasma::Animator::self()->customAnimation(40 / (1000.0 / qreal(time)), - time, Plasma::Animator::EaseOutCurve, this, "animationUpdate"); + m_animation->setDuration(time); + m_animation->setEasingCurve(QEasingCurve::OutQuad); + m_animation->setStartValue(0.0); + m_animation->setEndValue(1.0); + m_animation->start(); } update(); } @@ -247,21 +252,6 @@ void AuroraeButton::mouseReleaseEvent(QMouseEvent *e) KCommonDecorationButton::mouseReleaseEvent(e); } -void AuroraeButton::animationUpdate(qreal progress, int id) -{ - Q_UNUSED(id) - m_animationProgress = progress; - update(); -} - -void AuroraeButton::animationFinished(int id) -{ - if (m_animationId == id) { - m_animationId = 0; - update(); - } -} - void AuroraeButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event) @@ -445,7 +435,7 @@ void AuroraeButton::paintButton(QPainter &painter, Plasma::FrameSvg *frame, Butt } frame->setElementPrefix(prefix); frame->resizeFrame(size()); - if (m_animationId != 0) { + if (isAnimating()) { // there is an animation so we have to use it // the animation is definately a hover animation as currently nothing else is supported if (!states.testFlag(Hover)) { @@ -498,6 +488,22 @@ void AuroraeButton::paintButton(QPainter &painter, Plasma::FrameSvg *frame, Butt } } +bool AuroraeButton::isAnimating() const +{ + return (m_animation->state() == QAbstractAnimation::Running); +} + +qreal AuroraeButton::animationProgress() const +{ + return m_animationProgress; +} + +void AuroraeButton::setAnimationProgress(qreal progress) +{ + m_animationProgress = progress; + update(); +} + /******************************************************* * Client *******************************************************/ @@ -505,7 +511,7 @@ void AuroraeButton::paintButton(QPainter &painter, Plasma::FrameSvg *frame, Butt AuroraeClient::AuroraeClient(KDecorationBridge *bridge, KDecorationFactory *factory) : KCommonDecorationUnstable(bridge, factory) { - connect(Plasma::Animator::self(), SIGNAL(customAnimationFinished(int)), this, SLOT(animationFinished(int))); + m_animation = new QPropertyAnimation(this, "animation", this); } AuroraeClient::~AuroraeClient() @@ -808,7 +814,7 @@ void AuroraeClient::paintEvent(QPaintEvent *event) frame->resizeFrame(rect.size()); // animation - if (m_animationId != 0 && frame->hasElementPrefix("decoration-inactive")) { + if (isAnimating() && frame->hasElementPrefix("decoration-inactive")) { QPixmap target = frame->framePixmap(); frame->setElementPrefix("decoration-inactive"); if (!isActive()) { @@ -829,7 +835,7 @@ void AuroraeClient::paintEvent(QPaintEvent *event) } painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - if (m_animationId != 0) { + if (isAnimating()) { QPixmap result; if (isActive()) { result = Plasma::PaintUtils::transition(m_inactiveText, m_activeText, m_animationProgress); @@ -944,34 +950,21 @@ void AuroraeClient::updateWindowShape() void AuroraeClient::activeChange() { - if (m_animationId != 0) { - Plasma::Animator::self()->stopCustomAnimation(m_animationId); + if (isAnimating()) { + m_animation->stop(); } m_animationProgress = 0.0; int time = AuroraeFactory::instance()->themeConfig().animationTime(); if (time != 0) { - m_animationId = Plasma::Animator::self()->customAnimation(40 / (1000.0 / qreal(time)), - time, Plasma::Animator::EaseInOutCurve, this, "animationUpdate"); + m_animation->setDuration(time); + m_animation->setEasingCurve(QEasingCurve::InOutQuad); + m_animation->setStartValue(0.0); + m_animation->setEndValue(1.0); + m_animation->start(); } KCommonDecoration::activeChange(); } -void AuroraeClient::animationUpdate(qreal progress, int id) -{ - if (m_animationId == id) { - m_animationProgress = progress; - widget()->update(); - } -} - -void AuroraeClient::animationFinished(int id) -{ - if (m_animationId == id) { - m_animationId = 0; - widget()->update(); - } -} - void AuroraeClient::resize(const QSize& s) { KCommonDecoration::resize(s); @@ -982,6 +975,22 @@ void AuroraeClient::resize(const QSize& s) captionChange(); } +bool AuroraeClient::isAnimating() const +{ + return (m_animation->state() == QAbstractAnimation::Running); +} + +qreal AuroraeClient::animationProgress() const +{ + return m_animationProgress; +} + +void AuroraeClient::setAnimationProgress(qreal progress) +{ + m_animationProgress = progress; + widget()->update(); +} + } // namespace Aurorae extern "C" diff --git a/clients/aurorae/src/aurorae.h b/clients/aurorae/src/aurorae.h index f7bcfee1f5..b0e45827c7 100644 --- a/clients/aurorae/src/aurorae.h +++ b/clients/aurorae/src/aurorae.h @@ -25,6 +25,7 @@ along with this program. If not, see . #include class KSelectionWatcher; +class QPropertyAnimation; namespace Aurorae { @@ -77,6 +78,7 @@ private: class AuroraeButton : public KCommonDecorationButton { Q_OBJECT + Q_PROPERTY(qreal animation READ animationProgress WRITE setAnimationProgress) public: AuroraeButton(ButtonType type, KCommonDecoration *parent); @@ -84,10 +86,8 @@ public: void enterEvent(QEvent *event); void leaveEvent(QEvent *event); void paintEvent(QPaintEvent *event); - -public slots: - void animationUpdate(qreal progress, int id); - void animationFinished(int id); + qreal animationProgress() const; + void setAnimationProgress(qreal progress); protected: void mousePressEvent(QMouseEvent *e); @@ -102,17 +102,19 @@ private: }; Q_DECLARE_FLAGS(ButtonStates, ButtonState) void paintButton(QPainter& painter, Plasma::FrameSvg* frame, ButtonStates states); + bool isAnimating() const; private: - int m_animationId; qreal m_animationProgress; bool m_pressed; + QPropertyAnimation *m_animation; }; class AuroraeClient : public KCommonDecorationUnstable { Q_OBJECT + Q_PROPERTY(qreal animation READ animationProgress WRITE setAnimationProgress) public: AuroraeClient(KDecorationBridge *bridge, KDecorationFactory *factory); ~AuroraeClient(); @@ -131,12 +133,9 @@ public: virtual void captionChange(); virtual void resize(const QSize& s); - bool isAnimating() const { return m_animationId != 0; } - qreal animationProgress() const { return m_animationProgress; } - -public slots: - void animationUpdate(qreal progress, int id); - void animationFinished(int id); + bool isAnimating() const; + qreal animationProgress() const; + void setAnimationProgress(qreal progress); protected: void reset(unsigned long changed); @@ -144,10 +143,10 @@ protected: private: void generateTextPixmap(QPixmap& pixmap, bool active); - int m_animationId; qreal m_animationProgress; QPixmap m_activeText; QPixmap m_inactiveText; + QPropertyAnimation *m_animation; };