diff --git a/kdecoration/breezebutton.h b/kdecoration/breezebutton.h --- a/kdecoration/breezebutton.h +++ b/kdecoration/breezebutton.h @@ -26,18 +26,16 @@ #include #include -#include + +class QVariantAnimation; namespace Breeze { class Button : public KDecoration2::DecorationButton { Q_OBJECT - //* declare active state opacity - Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) - public: //* constructor @@ -123,7 +121,7 @@ Flag m_flag = FlagNone; //* active state change animation - QPropertyAnimation *m_animation; + QVariantAnimation *m_animation; //* vertical offset (for rendering) QPointF m_offset; diff --git a/kdecoration/breezebutton.cpp b/kdecoration/breezebutton.cpp --- a/kdecoration/breezebutton.cpp +++ b/kdecoration/breezebutton.cpp @@ -24,6 +24,7 @@ #include #include +#include namespace Breeze { @@ -36,15 +37,17 @@ //__________________________________________________________________ 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 @@ 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 @@ 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 @@ auto d = qobject_cast(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(); } diff --git a/kdecoration/breezedecoration.h b/kdecoration/breezedecoration.h --- a/kdecoration/breezedecoration.h +++ b/kdecoration/breezedecoration.h @@ -30,9 +30,10 @@ #include #include -#include #include +class QVariantAnimation; + namespace KDecoration2 { class DecorationButton; @@ -46,9 +47,6 @@ { Q_OBJECT - //* declare active state opacity - Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) - public: //* constructor @@ -145,7 +143,7 @@ SizeGrip *m_sizeGrip = nullptr; //* active state change animation - QPropertyAnimation *m_animation; + QVariantAnimation *m_animation; //* active state change opacity qreal m_opacity = 0; diff --git a/kdecoration/breezedecoration.cpp b/kdecoration/breezedecoration.cpp --- a/kdecoration/breezedecoration.cpp +++ b/kdecoration/breezedecoration.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #if BREEZE_HAVE_X11 #include @@ -159,7 +160,7 @@ //________________________________________________________________ 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 @@ 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 @@ 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 @@ { 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 @@ 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 @@ { 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 {