Aurorae uses a QPropertyAnimation for the animation instead of Plasma::Animator::customAnimation.
deprecatedCode-- svn path=/trunk/KDE/kdebase/workspace/; revision=1081956
This commit is contained in:
parent
b15fc9e1d9
commit
25852b6eaa
2 changed files with 70 additions and 62 deletions
|
@ -23,12 +23,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include <KConfig>
|
#include <KConfig>
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
#include <KDE/Plasma/Animator>
|
|
||||||
#include <KDE/Plasma/PaintUtils>
|
#include <KDE/Plasma/PaintUtils>
|
||||||
#include <KIconEffect>
|
#include <KIconEffect>
|
||||||
#include <KIconLoader>
|
#include <KIconLoader>
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
namespace Aurorae
|
namespace Aurorae
|
||||||
{
|
{
|
||||||
|
@ -190,12 +190,11 @@ AuroraeFactory *AuroraeFactory::s_instance = NULL;
|
||||||
*******************************************************/
|
*******************************************************/
|
||||||
AuroraeButton::AuroraeButton(ButtonType type, KCommonDecoration *parent)
|
AuroraeButton::AuroraeButton(ButtonType type, KCommonDecoration *parent)
|
||||||
: KCommonDecorationButton(type, parent)
|
: KCommonDecorationButton(type, parent)
|
||||||
, m_animationId(0)
|
|
||||||
, m_animationProgress(0.0)
|
, m_animationProgress(0.0)
|
||||||
, m_pressed(false)
|
, m_pressed(false)
|
||||||
{
|
{
|
||||||
|
m_animation = new QPropertyAnimation(this, "animation", this);
|
||||||
setAttribute(Qt::WA_NoSystemBackground);
|
setAttribute(Qt::WA_NoSystemBackground);
|
||||||
connect(Plasma::Animator::self(), SIGNAL(customAnimationFinished(int)), this, SLOT(animationFinished(int)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuroraeButton::reset(unsigned long changed)
|
void AuroraeButton::reset(unsigned long changed)
|
||||||
|
@ -206,14 +205,17 @@ void AuroraeButton::reset(unsigned long changed)
|
||||||
void AuroraeButton::enterEvent(QEvent *event)
|
void AuroraeButton::enterEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
if (m_animationId != 0) {
|
if (isAnimating()) {
|
||||||
Plasma::Animator::self()->stopCustomAnimation(m_animationId);
|
m_animation->stop();
|
||||||
}
|
}
|
||||||
m_animationProgress = 0.0;
|
m_animationProgress = 0.0;
|
||||||
int time = AuroraeFactory::instance()->themeConfig().animationTime();
|
int time = AuroraeFactory::instance()->themeConfig().animationTime();
|
||||||
if (time != 0) {
|
if (time != 0) {
|
||||||
m_animationId = Plasma::Animator::self()->customAnimation(40 / (1000.0 / qreal(time)),
|
m_animation->setDuration(time);
|
||||||
time, Plasma::Animator::EaseInCurve, this, "animationUpdate");
|
m_animation->setEasingCurve(QEasingCurve::InQuad);
|
||||||
|
m_animation->setStartValue(0.0);
|
||||||
|
m_animation->setEndValue(1.0);
|
||||||
|
m_animation->start();
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -221,14 +223,17 @@ void AuroraeButton::enterEvent(QEvent *event)
|
||||||
void AuroraeButton::leaveEvent(QEvent *event)
|
void AuroraeButton::leaveEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
if (m_animationId != 0) {
|
if (isAnimating()) {
|
||||||
Plasma::Animator::self()->stopCustomAnimation(m_animationId);
|
m_animation->stop();
|
||||||
}
|
}
|
||||||
m_animationProgress = 0.0;
|
m_animationProgress = 0.0;
|
||||||
int time = AuroraeFactory::instance()->themeConfig().animationTime();
|
int time = AuroraeFactory::instance()->themeConfig().animationTime();
|
||||||
if (time != 0) {
|
if (time != 0) {
|
||||||
m_animationId = Plasma::Animator::self()->customAnimation(40 / (1000.0 / qreal(time)),
|
m_animation->setDuration(time);
|
||||||
time, Plasma::Animator::EaseOutCurve, this, "animationUpdate");
|
m_animation->setEasingCurve(QEasingCurve::OutQuad);
|
||||||
|
m_animation->setStartValue(0.0);
|
||||||
|
m_animation->setEndValue(1.0);
|
||||||
|
m_animation->start();
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -247,21 +252,6 @@ void AuroraeButton::mouseReleaseEvent(QMouseEvent *e)
|
||||||
KCommonDecorationButton::mouseReleaseEvent(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)
|
void AuroraeButton::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
@ -445,7 +435,7 @@ void AuroraeButton::paintButton(QPainter &painter, Plasma::FrameSvg *frame, Butt
|
||||||
}
|
}
|
||||||
frame->setElementPrefix(prefix);
|
frame->setElementPrefix(prefix);
|
||||||
frame->resizeFrame(size());
|
frame->resizeFrame(size());
|
||||||
if (m_animationId != 0) {
|
if (isAnimating()) {
|
||||||
// there is an animation so we have to use it
|
// there is an animation so we have to use it
|
||||||
// the animation is definately a hover animation as currently nothing else is supported
|
// the animation is definately a hover animation as currently nothing else is supported
|
||||||
if (!states.testFlag(Hover)) {
|
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
|
* Client
|
||||||
*******************************************************/
|
*******************************************************/
|
||||||
|
@ -505,7 +511,7 @@ void AuroraeButton::paintButton(QPainter &painter, Plasma::FrameSvg *frame, Butt
|
||||||
AuroraeClient::AuroraeClient(KDecorationBridge *bridge, KDecorationFactory *factory)
|
AuroraeClient::AuroraeClient(KDecorationBridge *bridge, KDecorationFactory *factory)
|
||||||
: KCommonDecorationUnstable(bridge, factory)
|
: KCommonDecorationUnstable(bridge, factory)
|
||||||
{
|
{
|
||||||
connect(Plasma::Animator::self(), SIGNAL(customAnimationFinished(int)), this, SLOT(animationFinished(int)));
|
m_animation = new QPropertyAnimation(this, "animation", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuroraeClient::~AuroraeClient()
|
AuroraeClient::~AuroraeClient()
|
||||||
|
@ -808,7 +814,7 @@ void AuroraeClient::paintEvent(QPaintEvent *event)
|
||||||
frame->resizeFrame(rect.size());
|
frame->resizeFrame(rect.size());
|
||||||
|
|
||||||
// animation
|
// animation
|
||||||
if (m_animationId != 0 && frame->hasElementPrefix("decoration-inactive")) {
|
if (isAnimating() && frame->hasElementPrefix("decoration-inactive")) {
|
||||||
QPixmap target = frame->framePixmap();
|
QPixmap target = frame->framePixmap();
|
||||||
frame->setElementPrefix("decoration-inactive");
|
frame->setElementPrefix("decoration-inactive");
|
||||||
if (!isActive()) {
|
if (!isActive()) {
|
||||||
|
@ -829,7 +835,7 @@ void AuroraeClient::paintEvent(QPaintEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||||
if (m_animationId != 0) {
|
if (isAnimating()) {
|
||||||
QPixmap result;
|
QPixmap result;
|
||||||
if (isActive()) {
|
if (isActive()) {
|
||||||
result = Plasma::PaintUtils::transition(m_inactiveText, m_activeText, m_animationProgress);
|
result = Plasma::PaintUtils::transition(m_inactiveText, m_activeText, m_animationProgress);
|
||||||
|
@ -944,34 +950,21 @@ void AuroraeClient::updateWindowShape()
|
||||||
|
|
||||||
void AuroraeClient::activeChange()
|
void AuroraeClient::activeChange()
|
||||||
{
|
{
|
||||||
if (m_animationId != 0) {
|
if (isAnimating()) {
|
||||||
Plasma::Animator::self()->stopCustomAnimation(m_animationId);
|
m_animation->stop();
|
||||||
}
|
}
|
||||||
m_animationProgress = 0.0;
|
m_animationProgress = 0.0;
|
||||||
int time = AuroraeFactory::instance()->themeConfig().animationTime();
|
int time = AuroraeFactory::instance()->themeConfig().animationTime();
|
||||||
if (time != 0) {
|
if (time != 0) {
|
||||||
m_animationId = Plasma::Animator::self()->customAnimation(40 / (1000.0 / qreal(time)),
|
m_animation->setDuration(time);
|
||||||
time, Plasma::Animator::EaseInOutCurve, this, "animationUpdate");
|
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||||
|
m_animation->setStartValue(0.0);
|
||||||
|
m_animation->setEndValue(1.0);
|
||||||
|
m_animation->start();
|
||||||
}
|
}
|
||||||
KCommonDecoration::activeChange();
|
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)
|
void AuroraeClient::resize(const QSize& s)
|
||||||
{
|
{
|
||||||
KCommonDecoration::resize(s);
|
KCommonDecoration::resize(s);
|
||||||
|
@ -982,6 +975,22 @@ void AuroraeClient::resize(const QSize& s)
|
||||||
captionChange();
|
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
|
} // namespace Aurorae
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
|
|
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include <KDE/Plasma/FrameSvg>
|
#include <KDE/Plasma/FrameSvg>
|
||||||
|
|
||||||
class KSelectionWatcher;
|
class KSelectionWatcher;
|
||||||
|
class QPropertyAnimation;
|
||||||
|
|
||||||
namespace Aurorae
|
namespace Aurorae
|
||||||
{
|
{
|
||||||
|
@ -77,6 +78,7 @@ private:
|
||||||
class AuroraeButton : public KCommonDecorationButton
|
class AuroraeButton : public KCommonDecorationButton
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(qreal animation READ animationProgress WRITE setAnimationProgress)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AuroraeButton(ButtonType type, KCommonDecoration *parent);
|
AuroraeButton(ButtonType type, KCommonDecoration *parent);
|
||||||
|
@ -84,10 +86,8 @@ public:
|
||||||
void enterEvent(QEvent *event);
|
void enterEvent(QEvent *event);
|
||||||
void leaveEvent(QEvent *event);
|
void leaveEvent(QEvent *event);
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
|
qreal animationProgress() const;
|
||||||
public slots:
|
void setAnimationProgress(qreal progress);
|
||||||
void animationUpdate(qreal progress, int id);
|
|
||||||
void animationFinished(int id);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *e);
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
@ -102,17 +102,19 @@ private:
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(ButtonStates, ButtonState)
|
Q_DECLARE_FLAGS(ButtonStates, ButtonState)
|
||||||
void paintButton(QPainter& painter, Plasma::FrameSvg* frame, ButtonStates states);
|
void paintButton(QPainter& painter, Plasma::FrameSvg* frame, ButtonStates states);
|
||||||
|
bool isAnimating() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_animationId;
|
|
||||||
qreal m_animationProgress;
|
qreal m_animationProgress;
|
||||||
bool m_pressed;
|
bool m_pressed;
|
||||||
|
QPropertyAnimation *m_animation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class AuroraeClient : public KCommonDecorationUnstable
|
class AuroraeClient : public KCommonDecorationUnstable
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(qreal animation READ animationProgress WRITE setAnimationProgress)
|
||||||
public:
|
public:
|
||||||
AuroraeClient(KDecorationBridge *bridge, KDecorationFactory *factory);
|
AuroraeClient(KDecorationBridge *bridge, KDecorationFactory *factory);
|
||||||
~AuroraeClient();
|
~AuroraeClient();
|
||||||
|
@ -131,12 +133,9 @@ public:
|
||||||
virtual void captionChange();
|
virtual void captionChange();
|
||||||
virtual void resize(const QSize& s);
|
virtual void resize(const QSize& s);
|
||||||
|
|
||||||
bool isAnimating() const { return m_animationId != 0; }
|
bool isAnimating() const;
|
||||||
qreal animationProgress() const { return m_animationProgress; }
|
qreal animationProgress() const;
|
||||||
|
void setAnimationProgress(qreal progress);
|
||||||
public slots:
|
|
||||||
void animationUpdate(qreal progress, int id);
|
|
||||||
void animationFinished(int id);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void reset(unsigned long changed);
|
void reset(unsigned long changed);
|
||||||
|
@ -144,10 +143,10 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generateTextPixmap(QPixmap& pixmap, bool active);
|
void generateTextPixmap(QPixmap& pixmap, bool active);
|
||||||
int m_animationId;
|
|
||||||
qreal m_animationProgress;
|
qreal m_animationProgress;
|
||||||
QPixmap m_activeText;
|
QPixmap m_activeText;
|
||||||
QPixmap m_inactiveText;
|
QPixmap m_inactiveText;
|
||||||
|
QPropertyAnimation *m_animation;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue