Commit 6fe54936 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[kdecoration] Use QVariantAnimation instead of QPropertyAnimation

We don't need to go through the property system to update a value, just use a lambda.

Differential Revision: https://phabricator.kde.org/D25593
parent 0901e41a
......@@ -24,6 +24,7 @@
#include <KColorUtils>
#include <QPainter>
#include <QVariantAnimation>
namespace Breeze
{
......@@ -36,15 +37,17 @@ namespace Breeze
//__________________________________________________________________
Button::Button(DecorationButtonType type, Decoration* decoration, QObject* parent)
: DecorationButton(type, decoration, parent)
, m_animation( new QPropertyAnimation( this ) )
, m_animation( new QVariantAnimation( this ) )
{
// setup animation
m_animation->setStartValue( 0 );
// It is important start and end value are of the same type, hence 0.0 and not just 0
m_animation->setStartValue( 0.0 );
m_animation->setEndValue( 1.0 );
m_animation->setTargetObject( this );
m_animation->setPropertyName( "opacity" );
m_animation->setEasingCurve( QEasingCurve::InOutQuad );
connect(m_animation, &QVariantAnimation::valueChanged, this, [this](const QVariant &value) {
setOpacity(value.toReal());
});
// setup default geometry
const int height = decoration->buttonHeight();
......@@ -375,7 +378,7 @@ namespace Breeze
return d->titleBarColor();
} else if( m_animation->state() == QPropertyAnimation::Running ) {
} else if( m_animation->state() == QAbstractAnimation::Running ) {
return KColorUtils::mix( d->fontColor(), d->titleBarColor(), m_opacity );
......@@ -411,7 +414,7 @@ namespace Breeze
return d->fontColor();
} else if( m_animation->state() == QPropertyAnimation::Running ) {
} else if( m_animation->state() == QAbstractAnimation::Running ) {
if( type() == DecorationButtonType::Close )
{
......@@ -470,8 +473,8 @@ namespace Breeze
auto d = qobject_cast<Decoration*>(decoration());
if( !(d && d->internalSettings()->animationsEnabled() ) ) return;
m_animation->setDirection( hovered ? QPropertyAnimation::Forward : QPropertyAnimation::Backward );
if( m_animation->state() != QPropertyAnimation::Running ) m_animation->start();
m_animation->setDirection( hovered ? QAbstractAnimation::Forward : QAbstractAnimation::Backward );
if( m_animation->state() != QAbstractAnimation::Running ) m_animation->start();
}
......
......@@ -26,7 +26,8 @@
#include <QHash>
#include <QImage>
#include <QPropertyAnimation>
class QVariantAnimation;
namespace Breeze
{
......@@ -35,9 +36,6 @@ namespace Breeze
{
Q_OBJECT
//* declare active state opacity
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
public:
//* constructor
......@@ -123,7 +121,7 @@ namespace Breeze
Flag m_flag = FlagNone;
//* active state change animation
QPropertyAnimation *m_animation;
QVariantAnimation *m_animation;
//* vertical offset (for rendering)
QPointF m_offset;
......
......@@ -45,6 +45,7 @@
#include <QPainter>
#include <QTextStream>
#include <QTimer>
#include <QVariantAnimation>
#if BREEZE_HAVE_X11
#include <QX11Info>
......@@ -159,7 +160,7 @@ namespace Breeze
//________________________________________________________________
Decoration::Decoration(QObject *parent, const QVariantList &args)
: KDecoration2::Decoration(parent, args)
, m_animation( new QPropertyAnimation( this ) )
, m_animation( new QVariantAnimation( this ) )
{
g_sDecoCount++;
}
......@@ -193,7 +194,7 @@ namespace Breeze
auto c = client().data();
if( hideTitleBar() ) return c->color( ColorGroup::Inactive, ColorRole::TitleBar );
else if( m_animation->state() == QPropertyAnimation::Running )
else if( m_animation->state() == QAbstractAnimation::Running )
{
return KColorUtils::mix(
c->color( ColorGroup::Inactive, ColorRole::TitleBar ),
......@@ -209,7 +210,7 @@ namespace Breeze
auto c( client().data() );
if( !m_internalSettings->drawTitleBarSeparator() ) return QColor();
if( m_animation->state() == QPropertyAnimation::Running )
if( m_animation->state() == QAbstractAnimation::Running )
{
QColor color( c->palette().color( QPalette::Highlight ) );
color.setAlpha( color.alpha()*m_opacity );
......@@ -223,7 +224,7 @@ namespace Breeze
{
auto c = client().data();
if( m_animation->state() == QPropertyAnimation::Running )
if( m_animation->state() == QAbstractAnimation::Running )
{
return KColorUtils::mix(
c->color( ColorGroup::Inactive, ColorRole::Foreground ),
......@@ -239,11 +240,13 @@ namespace Breeze
auto c = client().data();
// active state change animation
m_animation->setStartValue( 0 );
// It is important start and end value are of the same type, hence 0.0 and not just 0
m_animation->setStartValue( 0.0 );
m_animation->setEndValue( 1.0 );
m_animation->setTargetObject( this );
m_animation->setPropertyName( "opacity" );
m_animation->setEasingCurve( QEasingCurve::InOutQuad );
connect(m_animation, &QVariantAnimation::valueChanged, this, [this](const QVariant &value) {
setOpacity(value.toReal());
});
reconfigure();
updateTitleBar();
......@@ -310,8 +313,8 @@ namespace Breeze
{
auto c = client().data();
m_animation->setDirection( c->isActive() ? QPropertyAnimation::Forward : QPropertyAnimation::Backward );
if( m_animation->state() != QPropertyAnimation::Running ) m_animation->start();
m_animation->setDirection( c->isActive() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward );
if( m_animation->state() != QAbstractAnimation::Running ) m_animation->start();
} else {
......
......@@ -30,9 +30,10 @@
#include <KDecoration2/DecorationSettings>
#include <QPalette>
#include <QPropertyAnimation>
#include <QVariant>
class QVariantAnimation;
namespace KDecoration2
{
class DecorationButton;
......@@ -46,9 +47,6 @@ namespace Breeze
{
Q_OBJECT
//* declare active state opacity
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
public:
//* constructor
......@@ -145,7 +143,7 @@ namespace Breeze
SizeGrip *m_sizeGrip = nullptr;
//* active state change animation
QPropertyAnimation *m_animation;
QVariantAnimation *m_animation;
//* active state change opacity
qreal m_opacity = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment