From 4abb699e63b78a1e5a4191a5354fa2ded45debd5 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Thu, 7 Aug 2014 21:15:43 +0200 Subject: [PATCH] Implemented toolbutton animations --- kstyle/animations/breezeanimations.cpp | 1 + kstyle/breeze.h | 2 +- kstyle/breezestyle.cpp | 28 ++++++++++++++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/kstyle/animations/breezeanimations.cpp b/kstyle/animations/breezeanimations.cpp index 4ea22b8f..a78d0e06 100644 --- a/kstyle/animations/breezeanimations.cpp +++ b/kstyle/animations/breezeanimations.cpp @@ -120,6 +120,7 @@ namespace Breeze if( qobject_cast(widget) ) { + _widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } else if( qobject_cast(widget) ) { diff --git a/kstyle/breeze.h b/kstyle/breeze.h index caea7b96..32e72403 100644 --- a/kstyle/breeze.h +++ b/kstyle/breeze.h @@ -70,7 +70,7 @@ namespace Breeze // tool buttons ToolButton_MarginWidth = 6, - ToolButton_BoxTextSpace = 8, + ToolButton_BoxTextSpace = 12, // checkboxes and radio buttons CheckBox_Size = 22, diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 4dc3eb3c..8e36f6df 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -2691,6 +2691,14 @@ namespace Breeze const bool mouseOver( enabled && (option->state & State_MouseOver) ); const bool hasFocus( enabled && (option->state & State_HasFocus) ); + // update animation state + // mouse over takes precedence over focus + _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); + _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver ); + + const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); + const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); + if( !autoRaise ) { @@ -2700,8 +2708,8 @@ namespace Breeze // render as push button const QColor shadow( _helper->shadowColor( palette ) ); - const QColor outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus ) ); - const QColor background( _helper->buttonBackgroundColor( palette, mouseOver, hasFocus ) ); + const QColor outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); + const QColor background( _helper->buttonBackgroundColor( palette, mouseOver, hasFocus, opacity, mode ) ); // adjust frame in case of menu if( hasPopupMenu ) @@ -2716,7 +2724,7 @@ namespace Breeze } else { - const QColor color( _helper->toolButtonColor( palette, mouseOver, hasFocus || sunken ) ); + const QColor color( _helper->toolButtonColor( palette, mouseOver, hasFocus || sunken, opacity, mode ) ); _helper->renderToolButtonFrame( painter, rect, color, sunken ); } @@ -2967,7 +2975,7 @@ namespace Breeze } //___________________________________________________________________________________ - bool Style::drawIndicatorButtonDropDownPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const + bool Style::drawIndicatorButtonDropDownPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check @@ -2992,10 +3000,18 @@ namespace Breeze const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool sunken( enabled && ( state & State_Sunken ) ); + // update animation state + // mouse over takes precedence over focus + _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); + _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver ); + + const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); + const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); + // render as push button const QColor shadow( _helper->shadowColor( palette ) ); - const QColor outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus ) ); - const QColor background( _helper->buttonBackgroundColor( palette, mouseOver, hasFocus ) ); + const QColor outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); + const QColor background( _helper->buttonBackgroundColor( palette, mouseOver, hasFocus, opacity, mode ) ); QRect frameRect( rect ); painter->setClipRect( rect );