From a834482a5be6d255d1874757df930c2d37545f9e Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Thu, 31 Jul 2014 00:37:49 +0200 Subject: [PATCH] added spinbox arrow hover animation --- kstyle/CMakeLists.txt | 2 + kstyle/animations/breezeanimations.cpp | 5 +- kstyle/animations/breezeanimations.h | 8 + kstyle/animations/breezespinboxdata.cpp | 57 ++++++++ kstyle/animations/breezespinboxdata.h | 170 ++++++++++++++++++++++ kstyle/animations/breezespinboxengine.cpp | 50 +++++++ kstyle/animations/breezespinboxengine.h | 115 +++++++++++++++ kstyle/breezestyle.cpp | 23 ++- 8 files changed, 417 insertions(+), 13 deletions(-) create mode 100644 kstyle/animations/breezespinboxdata.cpp create mode 100644 kstyle/animations/breezespinboxdata.h create mode 100644 kstyle/animations/breezespinboxengine.cpp create mode 100644 kstyle/animations/breezespinboxengine.h diff --git a/kstyle/CMakeLists.txt b/kstyle/CMakeLists.txt index 85290190..26d9cd18 100644 --- a/kstyle/CMakeLists.txt +++ b/kstyle/CMakeLists.txt @@ -57,6 +57,8 @@ set(breeze_PART_SRCS animations/breezescrollbarengine.cpp animations/breezesliderengine.cpp animations/breezesliderdata.cpp + animations/breezespinboxengine.cpp + animations/breezespinboxdata.cpp animations/breezewidgetstateengine.cpp animations/breezewidgetstatedata.cpp breezeframeshadow.cpp diff --git a/kstyle/animations/breezeanimations.cpp b/kstyle/animations/breezeanimations.cpp index 6d7ae99d..c67e398e 100644 --- a/kstyle/animations/breezeanimations.cpp +++ b/kstyle/animations/breezeanimations.cpp @@ -52,6 +52,7 @@ namespace Breeze _widgetEnabilityEngine = new WidgetStateEngine( this ); _busyIndicatorEngine = new BusyIndicatorEngine( this ); _comboBoxEngine = new WidgetStateEngine( this ); + _spinBoxEngine = new SpinBoxEngine( this ); registerEngine( _widgetStateEngine = new WidgetStateEngine( this ) ); registerEngine( _lineEditEngine = new WidgetStateEngine( this ) ); @@ -74,6 +75,7 @@ namespace Breeze _widgetEnabilityEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _widgetStateEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _comboBoxEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); + _spinBoxEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _lineEditEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _scrollBarEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _sliderEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); @@ -90,6 +92,7 @@ namespace Breeze _widgetEnabilityEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _widgetStateEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _comboBoxEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); + _spinBoxEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _lineEditEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _scrollBarEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _sliderEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); @@ -155,7 +158,7 @@ namespace Breeze // spinbox else if( qobject_cast( widget ) ) { - // _spinBoxEngine->registerWidget( widget ); + _spinBoxEngine->registerWidget( widget ); _lineEditEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } diff --git a/kstyle/animations/breezeanimations.h b/kstyle/animations/breezeanimations.h index 32de8419..d0eee3d4 100644 --- a/kstyle/animations/breezeanimations.h +++ b/kstyle/animations/breezeanimations.h @@ -30,6 +30,7 @@ #include "breezebusyindicatorengine.h" #include "breezescrollbarengine.h" #include "breezesliderengine.h" +#include "breezespinboxengine.h" #include "breezewidgetstateengine.h" #include @@ -87,6 +88,10 @@ namespace Breeze SliderEngine& sliderEngine( void ) const { return *_sliderEngine; } + //! spinbox engine + SpinBoxEngine& spinBoxEngine( void ) const + { return *_spinBoxEngine; } + //! setup engines void setupEngines( void ); @@ -120,6 +125,9 @@ namespace Breeze //! slider engine SliderEngine* _sliderEngine; + //! spinbox engine + SpinBoxEngine* _spinBoxEngine; + //! keep list of existing engines QList< BaseEngine::Pointer > _engines; diff --git a/kstyle/animations/breezespinboxdata.cpp b/kstyle/animations/breezespinboxdata.cpp new file mode 100644 index 00000000..a569dd3f --- /dev/null +++ b/kstyle/animations/breezespinboxdata.cpp @@ -0,0 +1,57 @@ +////////////////////////////////////////////////////////////////////////////// +// breezespinboxdata.cpp +// spinbox data container for up/down arrow hover (mouse-over) animations +// ------------------- +// +// Copyright (c) 2009 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "breezespinboxdata.h" +#include "breezespinboxdata.moc" + +namespace Breeze +{ + + //________________________________________________ + SpinBoxData::SpinBoxData( QObject* parent, QWidget* target, int duration ): + AnimationData( parent, target ) + { + _upArrowData._animation = new Animation( duration, this ); + _downArrowData._animation = new Animation( duration, this ); + setupAnimation( upArrowAnimation(), "upArrowOpacity" ); + setupAnimation( downArrowAnimation(), "downArrowOpacity" ); + } + + //______________________________________________ + bool SpinBoxData::Data::updateState( bool value ) + { + if( _state == value ) return false; + else { + + _state = value; + _animation.data()->setDirection( _state ? Animation::Forward : Animation::Backward ); + if( !_animation.data()->isRunning() ) _animation.data()->start(); + return true; + + } + } + +} diff --git a/kstyle/animations/breezespinboxdata.h b/kstyle/animations/breezespinboxdata.h new file mode 100644 index 00000000..c0a93008 --- /dev/null +++ b/kstyle/animations/breezespinboxdata.h @@ -0,0 +1,170 @@ +#ifndef breezespinbox_datah +#define breezespinbox_datah + +////////////////////////////////////////////////////////////////////////////// +// breezespinboxdata.h +// spinbox data container for up/down arrow hover (mouse-over) animations +// ------------------- +// +// Copyright (c) 2009 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "breezeanimationdata.h" + +#include + +namespace Breeze +{ + + //! handles spinbox arrows hover + class SpinBoxData: public AnimationData + { + + Q_OBJECT + + //! declare opacity property + Q_PROPERTY( qreal upArrowOpacity READ upArrowOpacity WRITE setUpArrowOpacity ) + Q_PROPERTY( qreal downArrowOpacity READ downArrowOpacity WRITE setDownArrowOpacity ) + + public: + + //! constructor + SpinBoxData( QObject*, QWidget*, int ); + + //! destructor + virtual ~SpinBoxData( void ) + {} + + //! animation state + virtual bool updateState( QStyle::SubControl subControl, bool value ) + { + if( subControl == QStyle::SC_SpinBoxUp ) return _upArrowData.updateState( value ); + else if( subControl == QStyle::SC_SpinBoxDown ) return _downArrowData.updateState( value ); + else return false; + } + + //! animation state + virtual bool isAnimated( QStyle::SubControl subControl ) const + { + return( + ( subControl == QStyle::SC_SpinBoxUp && upArrowAnimation().data()->isRunning() ) || + ( subControl == QStyle::SC_SpinBoxDown && downArrowAnimation().data()->isRunning() ) ); + } + + //! opacity + virtual qreal opacity( QStyle::SubControl subControl ) const + { + if( subControl == QStyle::SC_SpinBoxUp ) return upArrowOpacity(); + else if( subControl == QStyle::SC_SpinBoxDown ) return downArrowOpacity(); + else return OpacityInvalid; + } + + //! duration + virtual void setDuration( int duration ) + { + upArrowAnimation().data()->setDuration( duration ); + downArrowAnimation().data()->setDuration( duration ); + } + + //!@name up arrow animation + //@{ + + //! opacity + qreal upArrowOpacity( void ) const + { return _upArrowData._opacity; } + + //! opacity + void setUpArrowOpacity( qreal value ) + { + value = digitize( value ); + if( _upArrowData._opacity == value ) return; + _upArrowData._opacity = value; + setDirty(); + } + + //! animation + Animation::Pointer upArrowAnimation( void ) const + { return _upArrowData._animation; } + + //@} + + //!@name down arrow animation + //@{ + + //! opacity + qreal downArrowOpacity( void ) const + { return _downArrowData._opacity; } + + //! opacity + void setDownArrowOpacity( qreal value ) + { + value = digitize( value ); + if( _downArrowData._opacity == value ) return; + _downArrowData._opacity = value; + setDirty(); + } + + //! animation + Animation::Pointer downArrowAnimation( void ) const + { return _downArrowData._animation; } + + //@} + + private: + + //! container for needed animation data + class Data + { + + public: + + //! default constructor + Data( void ): + _state( false ), + _opacity(0) + {} + + //! state + bool updateState( bool ); + + //! arrow state + bool _state; + + //! animation + Animation::Pointer _animation; + + //! opacity + qreal _opacity; + + }; + + //! up arrow data + Data _upArrowData; + + //! down arrow data + Data _downArrowData; + + }; + + +} + +#endif diff --git a/kstyle/animations/breezespinboxengine.cpp b/kstyle/animations/breezespinboxengine.cpp new file mode 100644 index 00000000..65db6b72 --- /dev/null +++ b/kstyle/animations/breezespinboxengine.cpp @@ -0,0 +1,50 @@ +////////////////////////////////////////////////////////////////////////////// +// breezespinboxengine.cpp +// stores event filters and maps widgets to timelines for animations +// ------------------- +// +// Copyright (c) 2009 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "breezespinboxengine.h" +#include "breezespinboxengine.moc" + +#include + +namespace Breeze +{ + + //____________________________________________________________ + bool SpinBoxEngine::registerWidget( QWidget* widget ) + { + + if( !widget ) return false; + + // create new data class + if( !_data.contains( widget ) ) _data.insert( widget, new SpinBoxData( this, widget, duration() ), enabled() ); + + // connect destruction signal + connect( widget, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterWidget(QObject*)), Qt::UniqueConnection ); + return true; + + } + +} diff --git a/kstyle/animations/breezespinboxengine.h b/kstyle/animations/breezespinboxengine.h new file mode 100644 index 00000000..fd4c385d --- /dev/null +++ b/kstyle/animations/breezespinboxengine.h @@ -0,0 +1,115 @@ +#ifndef breezespinboxengine_h +#define breezespinboxengine_h + +////////////////////////////////////////////////////////////////////////////// +// breezespinboxengine.h +// stores event filters and maps widgets to animations +// ------------------- +// +// Copyright (c) 2009 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "breezebaseengine.h" +#include "breezedatamap.h" +#include "breezespinboxdata.h" + +namespace Breeze +{ + + //! handle spinbox arrows hover effect + class SpinBoxEngine: public BaseEngine + { + + Q_OBJECT + + public: + + //! constructor + explicit SpinBoxEngine( QObject* parent ): + BaseEngine( parent ) + {} + + //! destructor + virtual ~SpinBoxEngine( void ) + {} + + //! register widget + virtual bool registerWidget( QWidget* ); + + //! state + virtual bool updateState( const QObject* object, QStyle::SubControl subControl, bool value ) + { + if( DataMap::Value data = _data.find( object ) ) + { + return data.data()->updateState( subControl, value ); + } else return false; + } + + //! true if widget is animated + virtual bool isAnimated( const QObject* object, QStyle::SubControl subControl ) + { + if( DataMap::Value data = _data.find( object ) ) + { + return data.data()->isAnimated( subControl ); + } else return false; + + } + + //! animation opacity + virtual qreal opacity( const QObject* object, QStyle::SubControl subControl ) + { + if( DataMap::Value data = _data.find( object ) ) + { + return data.data()->opacity( subControl ); + } else return AnimationData::OpacityInvalid; + } + + //! enability + virtual void setEnabled( bool value ) + { + BaseEngine::setEnabled( value ); + _data.setEnabled( value ); + } + + //! duration + virtual void setDuration( int value ) + { + BaseEngine::setDuration( value ); + _data.setDuration( value ); + } + + + public Q_SLOTS: + + //! remove widget from map + virtual bool unregisterWidget( QObject* object ) + { return _data.unregisterWidget( object ); } + + private: + + //! data map + DataMap _data; + + }; + +} + +#endif diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index fc02393e..3a86f725 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -2213,20 +2213,19 @@ namespace Breeze // check animation state const bool subControlHover( enabled && mouseOver && ( option->activeSubControls & subControl ) ); -// _animations->spinBoxEngine().updateState( widget, subControl, subControlHover ); -// -// const bool animated( enabled && _animations->spinBoxEngine().isAnimated( widget, subControl ) ); -// const qreal opacity( _animations->spinBoxEngine().opacity( widget, subControl ) ); + _animations->spinBoxEngine().updateState( widget, subControl, subControlHover ); + + const bool animated( enabled && _animations->spinBoxEngine().isAnimated( widget, subControl ) ); + const qreal opacity( _animations->spinBoxEngine().opacity( widget, subControl ) ); QColor color; -// if( animated ) -// { -// -// QColor highlight = _helper->viewHoverBrush().brush( palette ).color(); -// color = KColorUtils::mix( palette.color( QPalette::Text ), highlight, opacity ); -// -// } else if( subControlHover ) { - if( subControlHover ) { + if( animated ) + { + + QColor highlight = _helper->viewHoverBrush().brush( palette ).color(); + color = KColorUtils::mix( palette.color( QPalette::Text ), highlight, opacity ); + + } else if( subControlHover ) { color = _helper->viewHoverBrush().brush( palette ).color();