diff --git a/kstyle/animations/breezeanimations.cpp b/kstyle/animations/breezeanimations.cpp index 47eef7bf..6fe57c3e 100644 --- a/kstyle/animations/breezeanimations.cpp +++ b/kstyle/animations/breezeanimations.cpp @@ -33,12 +33,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -124,6 +126,10 @@ namespace Breeze _widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus ); + } else if( qobject_cast(widget) || qobject_cast(widget) ) { + + _widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus|AnimationPressed ); + } else if( qobject_cast(widget) ) { // register to toolbox engine if needed diff --git a/kstyle/animations/breezewidgetstateengine.cpp b/kstyle/animations/breezewidgetstateengine.cpp index 482ca196..88a725e7 100644 --- a/kstyle/animations/breezewidgetstateengine.cpp +++ b/kstyle/animations/breezewidgetstateengine.cpp @@ -41,6 +41,7 @@ namespace Breeze if( mode&AnimationHover && !_hoverData.contains( widget ) ) { _hoverData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); } if( mode&AnimationFocus && !_focusData.contains( widget ) ) { _focusData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); } if( mode&AnimationEnable && !_enableData.contains( widget ) ) { _enableData.insert( widget, new EnableData( this, widget, duration() ), enabled() ); } + if( mode&AnimationPressed && !_pressedData.contains( widget ) ) { _pressedData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); } // connect destruction signal connect( widget, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterWidget(QObject*)), Qt::UniqueConnection ); @@ -76,6 +77,12 @@ namespace Breeze { if( value ) out.insert( value.data()->target().data() ); } } + if( mode&AnimationPressed ) + { + foreach( const Value& value, _pressedData ) + { if( value ) out.insert( value.data()->target().data() ); } + } + return out; } @@ -105,6 +112,7 @@ namespace Breeze case AnimationHover: return _hoverData.find( object ).data(); case AnimationFocus: return _focusData.find( object ).data(); case AnimationEnable: return _enableData.find( object ).data(); + case AnimationPressed: return _pressedData.find( object ).data(); default: return DataMap::Value(); } diff --git a/kstyle/animations/breezewidgetstateengine.h b/kstyle/animations/breezewidgetstateengine.h index 04832cf4..6323bee8 100644 --- a/kstyle/animations/breezewidgetstateengine.h +++ b/kstyle/animations/breezewidgetstateengine.h @@ -126,6 +126,7 @@ namespace Breeze _hoverData.setDuration( value ); _focusData.setDuration( value ); _enableData.setDuration( value ); + _pressedData.setDuration( value/2 ); } public Q_SLOTS: @@ -138,6 +139,7 @@ namespace Breeze if( _hoverData.unregisterWidget( object ) ) found = true; if( _focusData.unregisterWidget( object ) ) found = true; if( _enableData.unregisterWidget( object ) ) found = true; + if( _pressedData.unregisterWidget( object ) ) found = true; return found; } @@ -152,6 +154,7 @@ namespace Breeze DataMap _hoverData; DataMap _focusData; DataMap _enableData; + DataMap _pressedData; }; diff --git a/kstyle/breeze.h b/kstyle/breeze.h index 00c5722f..61c6c91a 100644 --- a/kstyle/breeze.h +++ b/kstyle/breeze.h @@ -193,12 +193,21 @@ namespace Breeze Q_DECLARE_FLAGS( Corners, Corner ); - //! checkbox state (used for checkboxes _and_ radio buttons) + //! checkbox state enum CheckBoxState { CheckOff, CheckPartial, - CheckOn + CheckOn, + CheckAnimated + }; + + //! radio button state + enum RadioButtonState + { + RadioOff, + RadioOn, + RadioAnimated }; //! arrow orientation diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp index 027249da..9e829944 100644 --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -643,7 +643,7 @@ namespace Breeze void Helper::renderCheckBox( QPainter* painter, const QRect& rect, const QColor& color, const QColor& shadow, - bool sunken, CheckBoxState state ) const + bool sunken, CheckBoxState state, qreal animation ) const { // setup painter @@ -693,7 +693,7 @@ namespace Breeze pen.setJoinStyle( Qt::MiterJoin ); painter->setPen( pen ); - const QRectF markerRect( frameRect.adjusted( 5, 5, -5, -5 ) ); + const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) ); painter->drawRect( markerRect ); painter->setPen( Qt::NoPen ); @@ -706,6 +706,20 @@ namespace Breeze path.lineTo( 5, qreal( Metrics::CheckBox_Size ) - 6 ); painter->drawPath( path.translated( rect.topLeft() ) ); + } else if( state == CheckAnimated ) { + + const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) ); + QPainterPath path; + path.moveTo( markerRect.topRight() ); + path.lineTo( markerRect.center() + animation*( markerRect.topLeft() - markerRect.center() ) ); + path.lineTo( markerRect.bottomLeft() ); + path.lineTo( markerRect.center() + animation*( markerRect.bottomRight() - markerRect.center() ) ); + path.closeSubpath(); + + painter->setBrush( color ); + painter->setPen( Qt::NoPen ); + painter->drawPath( path ); + } } @@ -714,7 +728,7 @@ namespace Breeze void Helper::renderRadioButton( QPainter* painter, const QRect& rect, const QColor& color, const QColor& shadow, - bool sunken, bool checked ) const + bool sunken, RadioButtonState state, qreal animation ) const { // setup painter @@ -746,7 +760,7 @@ namespace Breeze } // mark - if( checked ) + if( state == RadioOn ) { painter->setBrush( color ); @@ -755,6 +769,19 @@ namespace Breeze const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) ); painter->drawEllipse( markerRect ); + } else if( state == RadioAnimated ) { + + painter->setBrush( color ); + painter->setPen( Qt::NoPen ); + QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) ); + + painter->translate( markerRect.center() ); + painter->rotate( 45 ); + + markerRect.setWidth( markerRect.width()*animation ); + markerRect.translate( -markerRect.center() ); + painter->drawEllipse( markerRect ); + } } diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h index f036620a..43ce8980 100644 --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -159,10 +159,10 @@ namespace Breeze void renderSeparator( QPainter*, const QRect&, const QColor&, bool vertical = false ) const; //! checkbox - void renderCheckBox( QPainter*, const QRect&, const QColor& color, const QColor& shadow, bool sunken, CheckBoxState state ) const; + void renderCheckBox( QPainter*, const QRect&, const QColor& color, const QColor& shadow, bool sunken, CheckBoxState state, qreal animation = AnimationData::OpacityInvalid ) const; //! radio button - void renderRadioButton( QPainter*, const QRect&, const QColor& color, const QColor& shadow, bool sunken, bool checked ) const; + void renderRadioButton( QPainter*, const QRect&, const QColor& color, const QColor& shadow, bool sunken, RadioButtonState state, qreal animation = AnimationData::OpacityInvalid ) const; //! slider groove void renderSliderGroove( QPainter*, const QRect&, const QColor& ) const; diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 52010f95..76139d50 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -3044,14 +3044,17 @@ namespace Breeze const AnimationMode mode( _animations->widgetStateEngine().isAnimated( widget, AnimationHover ) ? AnimationHover:AnimationNone ); const qreal opacity( _animations->widgetStateEngine().opacity( widget, AnimationHover ) ); + _animations->widgetStateEngine().updateState( widget, AnimationPressed, checkBoxState != CheckOff ); + if( _animations->widgetStateEngine().isAnimated( widget, AnimationPressed ) ) checkBoxState = CheckAnimated; + const qreal animation( _animations->widgetStateEngine().opacity( widget, AnimationPressed ) ); + // colors const QPalette& palette( option->palette ); const QColor color( _helper->checkBoxIndicatorColor( palette, mouseOver, enabled && active, opacity, mode ) ); const QColor shadow( _helper->shadowColor( palette ) ); // render - _helper->renderCheckBox( painter, option->rect, color, shadow, sunken, checkBoxState ); - + _helper->renderCheckBox( painter, option->rect, color, shadow, sunken, checkBoxState, animation ); return true; } @@ -3067,18 +3070,24 @@ namespace Breeze const bool sunken( state & State_Sunken ); const bool checked( state & State_On ); - // update only mouse over + RadioButtonState radioButtonState( state & State_On ? RadioOn:RadioOff ); + + // animation state _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); const AnimationMode mode( _animations->widgetStateEngine().isAnimated( widget, AnimationHover ) ? AnimationHover:AnimationNone ); const qreal opacity( _animations->widgetStateEngine().opacity( widget, AnimationHover ) ); + _animations->widgetStateEngine().updateState( widget, AnimationPressed, radioButtonState != RadioOff ); + if( _animations->widgetStateEngine().isAnimated( widget, AnimationPressed ) ) radioButtonState = RadioAnimated; + const qreal animation( _animations->widgetStateEngine().opacity( widget, AnimationPressed ) ); + // colors const QPalette& palette( option->palette ); const QColor color( _helper->checkBoxIndicatorColor( palette, mouseOver, enabled && checked, opacity, mode ) ); const QColor shadow( _helper->shadowColor( palette ) ); // render - _helper->renderRadioButton( painter, option->rect, color, shadow, sunken, checked ); + _helper->renderRadioButton( painter, option->rect, color, shadow, sunken, radioButtonState, animation ); return true; @@ -3717,7 +3726,7 @@ namespace Breeze const bool active( menuItemOption->checked ); const QColor color( _helper->checkBoxIndicatorColor( palette, enabled && selected, enabled && active ) ); const QColor shadow( _helper->shadowColor( palette ) ); - _helper->renderRadioButton( painter, checkBoxRect, color, shadow, sunken, active ); + _helper->renderRadioButton( painter, checkBoxRect, color, shadow, sunken, active ? RadioOn:RadioOff ); }