From 744b6fd3c25ccaadbbeee2ade7c09a0c36b447c7 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Mon, 28 Jul 2014 20:56:18 +0200 Subject: [PATCH] added base classes for animations and scrollbar animations --- kstyle/CMakeLists.txt | 8 + kstyle/animations/breezeanimation.cpp | 28 +++ kstyle/animations/breezeanimation.h | 70 ++++++ kstyle/animations/breezeanimationdata.cpp | 48 ++++ kstyle/animations/breezeanimationdata.h | 113 +++++++++ kstyle/animations/breezeanimations.cpp | 117 ++++++++++ kstyle/animations/breezeanimations.h | 85 +++++++ kstyle/animations/breezebaseengine.cpp | 28 +++ kstyle/animations/breezebaseengine.h | 97 ++++++++ kstyle/animations/breezedatamap.h | 175 ++++++++++++++ kstyle/animations/breezegenericdata.cpp | 42 ++++ kstyle/animations/breezegenericdata.h | 93 ++++++++ kstyle/animations/breezescrollbardata.cpp | 224 ++++++++++++++++++ kstyle/animations/breezescrollbardata.h | 243 ++++++++++++++++++++ kstyle/animations/breezescrollbarengine.cpp | 69 ++++++ kstyle/animations/breezescrollbarengine.h | 135 +++++++++++ kstyle/animations/breezesliderdata.cpp | 79 +++++++ kstyle/animations/breezesliderdata.h | 81 +++++++ kstyle/breeze.kcfg | 17 ++ 19 files changed, 1752 insertions(+) create mode 100644 kstyle/animations/breezeanimation.cpp create mode 100644 kstyle/animations/breezeanimation.h create mode 100644 kstyle/animations/breezeanimationdata.cpp create mode 100644 kstyle/animations/breezeanimationdata.h create mode 100644 kstyle/animations/breezeanimations.cpp create mode 100644 kstyle/animations/breezeanimations.h create mode 100644 kstyle/animations/breezebaseengine.cpp create mode 100644 kstyle/animations/breezebaseengine.h create mode 100644 kstyle/animations/breezedatamap.h create mode 100644 kstyle/animations/breezegenericdata.cpp create mode 100644 kstyle/animations/breezegenericdata.h create mode 100644 kstyle/animations/breezescrollbardata.cpp create mode 100644 kstyle/animations/breezescrollbardata.h create mode 100644 kstyle/animations/breezescrollbarengine.cpp create mode 100644 kstyle/animations/breezescrollbarengine.h create mode 100644 kstyle/animations/breezesliderdata.cpp create mode 100644 kstyle/animations/breezesliderdata.h diff --git a/kstyle/CMakeLists.txt b/kstyle/CMakeLists.txt index 9b866e7e..5ec8f158 100644 --- a/kstyle/CMakeLists.txt +++ b/kstyle/CMakeLists.txt @@ -44,6 +44,14 @@ include(GenerateExportHeader) ########### next target ############### set(breeze_PART_SRCS + animations/breezeanimation.cpp + animations/breezeanimations.cpp + animations/breezeanimationdata.cpp + animations/breezebaseengine.cpp + animations/breezegenericdata.cpp + animations/breezescrollbardata.cpp + animations/breezescrollbarengine.cpp + animations/breezesliderdata.cpp breezehelper.cpp breezepropertynames.cpp breezestyle.cpp diff --git a/kstyle/animations/breezeanimation.cpp b/kstyle/animations/breezeanimation.cpp new file mode 100644 index 00000000..3cddbeb7 --- /dev/null +++ b/kstyle/animations/breezeanimation.cpp @@ -0,0 +1,28 @@ +////////////////////////////////////////////////////////////////////////////// +// breezeanimation.h +// stores event filters and maps widgets to animations 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 "breezeanimation.h" +#include "breezeanimation.moc" diff --git a/kstyle/animations/breezeanimation.h b/kstyle/animations/breezeanimation.h new file mode 100644 index 00000000..b4b9d110 --- /dev/null +++ b/kstyle/animations/breezeanimation.h @@ -0,0 +1,70 @@ +#ifndef breezeanimation_h +#define breezeanimation_h +////////////////////////////////////////////////////////////////////////////// +// breezeanimation.h +// stores event filters and maps widgets to animations 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 +#include +#include + +namespace Breeze +{ + + class Animation: public QPropertyAnimation + { + + Q_OBJECT + + public: + + //! TimeLine shared pointer + typedef QPointer Pointer; + + //! constructor + Animation( int duration, QObject* parent ): + QPropertyAnimation( parent ) + { setDuration( duration ); } + + //! destructor + virtual ~Animation( void ) + {} + + //! true if running + bool isRunning( void ) const + { return state() == Animation::Running; } + + //! restart + void restart( void ) + { + if( isRunning() ) stop(); + start(); + } + + }; + +} + +#endif diff --git a/kstyle/animations/breezeanimationdata.cpp b/kstyle/animations/breezeanimationdata.cpp new file mode 100644 index 00000000..540e1c65 --- /dev/null +++ b/kstyle/animations/breezeanimationdata.cpp @@ -0,0 +1,48 @@ +////////////////////////////////////////////////////////////////////////////// +// breezeanimationdata.cpp +// base class data container needed for widget 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 "breezeanimationdata.moc" + +namespace Breeze +{ + + qreal AnimationData::OpacityInvalid = -1; + int AnimationData::_steps = 0; + + //_________________________________________________________________________________ + void AnimationData::setupAnimation( const Animation::Pointer& animation, const QByteArray& property ) + { + + // setup animation + animation.data()->setStartValue( 0.0 ); + animation.data()->setEndValue( 1.0 ); + animation.data()->setTargetObject( this ); + animation.data()->setPropertyName( property ); + + } + +} diff --git a/kstyle/animations/breezeanimationdata.h b/kstyle/animations/breezeanimationdata.h new file mode 100644 index 00000000..76d7eb57 --- /dev/null +++ b/kstyle/animations/breezeanimationdata.h @@ -0,0 +1,113 @@ +#ifndef breeze_animationdatah +#define breeze_animationdatah + +////////////////////////////////////////////////////////////////////////////// +// breezeanimationdata.h +// base class data container needed for widget 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 "breezeanimation.h" + +#include +#include +#include +#include +#include + +namespace Breeze +{ + + //! base class + class AnimationData: public QObject + { + + Q_OBJECT + + public: + + //! constructor + AnimationData( QObject* parent, QWidget* target ): + QObject( parent ), + _target( target ), + _enabled( true ) + { Q_ASSERT( _target ); } + + //! destructor + virtual ~AnimationData( void ) + {} + + //! duration + virtual void setDuration( int ) = 0; + + //! steps + static void setSteps( int value ) + { _steps = value; } + + //! enability + virtual bool enabled( void ) const + { return _enabled; } + + //! enability + virtual void setEnabled( bool value ) + { _enabled = value; } + + //! target + const QPointer& target( void ) const + { return _target; } + + //! invalid opacity + static qreal OpacityInvalid; + + protected: + + //! setup animation + virtual void setupAnimation( const Animation::Pointer& animation, const QByteArray& property ); + + //! apply step + virtual qreal digitize( const qreal& value ) const + { + if( _steps > 0 ) return std::floor( value*_steps )/_steps; + else return value; + } + + //! trigger target update + virtual void setDirty( void ) const + { if( _target ) _target.data()->update(); } + + private: + + //! guarded target + QPointer _target; + + //! enability + bool _enabled; + + //! steps + static int _steps; + + }; + +} + +#endif diff --git a/kstyle/animations/breezeanimations.cpp b/kstyle/animations/breezeanimations.cpp new file mode 100644 index 00000000..3d0501d0 --- /dev/null +++ b/kstyle/animations/breezeanimations.cpp @@ -0,0 +1,117 @@ +////////////////////////////////////////////////////////////////////////////// +// breezeanimations.cpp +// container for all animation engines +// ------------------- +// +// Copyright (c) 2006, 2007 Riccardo Iaconelli +// Copyright (c) 2006, 2007 Casper Boemann +// 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 "breezeanimations.h" +#include "breezeanimations.moc" +#include "breezepropertynames.h" +#include "breezestyleconfigdata.h" + +#include + +namespace Breeze +{ + + //____________________________________________________________ + Animations::Animations( QObject* parent ): + QObject( parent ) + { + registerEngine( _scrollBarEngine = new ScrollBarEngine( this ) ); + } + + //____________________________________________________________ + void Animations::setupEngines( void ) + { + + // animation steps + AnimationData::setSteps( StyleConfigData::animationSteps() ); + + { + // default enability, duration and maxFrame + bool animationsEnabled( StyleConfigData::animationsEnabled() ); + + // enability + _scrollBarEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); + + } + + + { + + // durations + _scrollBarEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); + + } + + } + + //____________________________________________________________ + void Animations::registerWidget( QWidget* widget ) const + { + + if( !widget ) return; + + // check against noAnimations propery + QVariant propertyValue( widget->property( PropertyNames::noAnimations ) ); + if( propertyValue.isValid() && propertyValue.toBool() ) return; + + // scrollbar + if( qobject_cast( widget ) ) { _scrollBarEngine->registerWidget( widget ); } + + return; + + } + + //____________________________________________________________ + void Animations::unregisterWidget( QWidget* widget ) const + { + + if( !widget ) return; + + // the following allows some optimization of widget unregistration + // it assumes that a widget can be registered atmost in one of the + // engines stored in the list. + foreach( const BaseEngine::Pointer& engine, _engines ) + { if( engine && engine.data()->unregisterWidget( widget ) ) break; } + + } + + //_______________________________________________________________ + void Animations::unregisterEngine( QObject* object ) + { + int index( _engines.indexOf( qobject_cast(object) ) ); + if( index >= 0 ) _engines.removeAt( index ); + } + + //_______________________________________________________________ + void Animations::registerEngine( BaseEngine* engine ) + { + _engines.push_back( engine ); + connect( engine, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterEngine(QObject*)) ); + } + +} diff --git a/kstyle/animations/breezeanimations.h b/kstyle/animations/breezeanimations.h new file mode 100644 index 00000000..8fab6799 --- /dev/null +++ b/kstyle/animations/breezeanimations.h @@ -0,0 +1,85 @@ +#ifndef breezeanimations_h +#define breezeanimations_h + +////////////////////////////////////////////////////////////////////////////// +// breezeanimations.h +// container for all animation engines +// ------------------- +// +// 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 "breezescrollbarengine.h" + +#include +#include + +namespace Breeze +{ + + //! stores engines + class Animations: public QObject + { + + Q_OBJECT + + public: + + //! constructor + explicit Animations( QObject* ); + + //! destructor + virtual ~Animations( void ) + {} + + //! register animations corresponding to given widget, depending on its type. + void registerWidget( QWidget* widget ) const; + + /*! unregister all animations associated to a widget */ + void unregisterWidget( QWidget* widget ) const; + + //! scrollbar engine + ScrollBarEngine& scrollBarEngine( void ) const + { return *_scrollBarEngine; } + + //! setup engines + void setupEngines( void ); + + protected Q_SLOTS: + + //! enregister engine + void unregisterEngine( QObject* ); + private: + + //! register new engine + void registerEngine( BaseEngine* engine ); + + //! scrollbar engine + ScrollBarEngine* _scrollBarEngine; + + //! keep list of existing engines + QList< BaseEngine::Pointer > _engines; + + }; + +} + +#endif diff --git a/kstyle/animations/breezebaseengine.cpp b/kstyle/animations/breezebaseengine.cpp new file mode 100644 index 00000000..d0e95914 --- /dev/null +++ b/kstyle/animations/breezebaseengine.cpp @@ -0,0 +1,28 @@ +////////////////////////////////////////////////////////////////////////////// +// breezebaseengine.cpp +// base engine +// ------------------- +// +// 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 "breezebaseengine.moc" diff --git a/kstyle/animations/breezebaseengine.h b/kstyle/animations/breezebaseengine.h new file mode 100644 index 00000000..43d2a85f --- /dev/null +++ b/kstyle/animations/breezebaseengine.h @@ -0,0 +1,97 @@ +#ifndef breezebaseengine_h +#define breezebaseengine_h + +////////////////////////////////////////////////////////////////////////////// +// breezebaseengine.h +// base engine +// ------------------- +// +// 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 +#include +#include + +namespace Breeze +{ + + //! base class for all animation engines + /*! it is used to store configuration values used by all animations stored in the engine */ + class BaseEngine: public QObject + { + + Q_OBJECT + + public: + + typedef QPointer Pointer; + + //! constructor + explicit BaseEngine( QObject* parent ): + QObject( parent ), + _enabled( true ), + _duration( 200 ) + {} + + //! destructor + virtual ~BaseEngine( void ) + {} + + //! enability + virtual void setEnabled( bool value ) + { _enabled = value; } + + //! enability + virtual bool enabled( void ) const + { return _enabled; } + + //! duration + virtual void setDuration( int value ) + { _duration = value; } + + //! duration + virtual int duration( void ) const + { return _duration; } + + //! unregister widget + virtual bool unregisterWidget( QObject* object ) = 0; + + //! list of widgets + typedef QSet WidgetList; + + //! returns registered widgets + virtual WidgetList registeredWidgets( void ) const + { return WidgetList(); } + + private: + + //! engine enability + bool _enabled; + + //! animation duration + int _duration; + + }; + +} + +#endif diff --git a/kstyle/animations/breezedatamap.h b/kstyle/animations/breezedatamap.h new file mode 100644 index 00000000..c89515d6 --- /dev/null +++ b/kstyle/animations/breezedatamap.h @@ -0,0 +1,175 @@ +#ifndef breezedatamap_h +#define breezedatamap_h + +////////////////////////////////////////////////////////////////////////////// +// breezedatamap.h +// 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 +#include +#include +#include + +namespace Breeze +{ + + //! data map + /*! it maps templatized data object to associated object */ + template< typename K, typename T > class BaseDataMap: public QMap< const K*, QPointer > + { + + public: + + typedef const K* Key; + typedef QPointer Value; + + //! constructor + BaseDataMap( void ): + QMap(), + _enabled( true ), + _lastKey( NULL ) + {} + + //! destructor + virtual ~BaseDataMap( void ) + {} + + //! insertion + virtual typename QMap< Key, Value >::iterator insert( const Key& key, const Value& value, bool enabled = true ) + { + if( value ) value.data()->setEnabled( enabled ); + return QMap< Key, Value >::insert( key, value ); + } + + //! find value + Value find( Key key ) + { + if( !( enabled() && key ) ) return Value(); + if( key == _lastKey ) return _lastValue; + else { + Value out; + typename QMap::iterator iter( QMap::find( key ) ); + if( iter != QMap::end() ) out = iter.value(); + _lastKey = key; + _lastValue = out; + return out; + } + } + + //! unregister widget + bool unregisterWidget( Key key ) + { + + // check key + if( !key ) return false; + + // clear last value if needed + if( key == _lastKey ) + { + + if( _lastValue ) _lastValue.clear(); + _lastKey = NULL; + + } + + // find key in map + typename QMap::iterator iter( QMap::find( key ) ); + if( iter == QMap::end() ) return false; + + // delete value from map if found + if( iter.value() ) iter.value().data()->deleteLater(); + QMap::erase( iter ); + + return true; + + } + + //! maxFrame + void setEnabled( bool enabled ) + { + _enabled = enabled; + foreach( const Value& value, *this ) + { if( value ) value.data()->setEnabled( enabled ); } + } + + //! enability + bool enabled( void ) const + { return _enabled; } + + //! duration + void setDuration( int duration ) const + { + foreach( const Value& value, *this ) + { if( value ) value.data()->setDuration( duration ); } + } + + private: + + //! enability + bool _enabled; + + //! last key + Key _lastKey; + + //! last value + Value _lastValue; + + }; + + //! standard data map, using QObject as a key + template< typename T > class DataMap: public BaseDataMap< QObject, T > + { + + public: + + //! constructor + DataMap( void ) + {} + + //! destructor + virtual ~DataMap( void ) + {} + + }; + + //! QPaintDevice based dataMap + template< typename T > class PaintDeviceDataMap: public BaseDataMap< QPaintDevice, T > + { + + public: + + //! constructor + PaintDeviceDataMap( void ) + {} + + //! destructor + virtual ~PaintDeviceDataMap( void ) + {} + + }; + +} + +#endif diff --git a/kstyle/animations/breezegenericdata.cpp b/kstyle/animations/breezegenericdata.cpp new file mode 100644 index 00000000..090f24c7 --- /dev/null +++ b/kstyle/animations/breezegenericdata.cpp @@ -0,0 +1,42 @@ +////////////////////////////////////////////////////////////////////////////// +// breezegenericdata.cpp +// generic data container for widget 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 "breezegenericdata.h" +#include "breezegenericdata.moc" + +#include + +namespace Breeze +{ + + //______________________________________________ + GenericData::GenericData( QObject* parent, QWidget* target, int duration ): + AnimationData( parent, target ), + _animation( new Animation( duration, this ) ), + _opacity(0) + { setupAnimation( _animation, "opacity" ); } + +} diff --git a/kstyle/animations/breezegenericdata.h b/kstyle/animations/breezegenericdata.h new file mode 100644 index 00000000..7b3ffd5e --- /dev/null +++ b/kstyle/animations/breezegenericdata.h @@ -0,0 +1,93 @@ +#ifndef breezegeneric_datah +#define breezegeneric_datah + +////////////////////////////////////////////////////////////////////////////// +// breezegenericdata.h +// generic data container 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 "breezeanimationdata.h" +#include "breezeanimation.h" + +#include +#include +namespace Breeze +{ + + + //! generic data + class GenericData: public AnimationData + { + + Q_OBJECT + + //! declare opacity property + Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) + + public: + + //! constructor + GenericData( QObject* parent, QWidget* widget, int duration ); + + //! destructor + virtual ~GenericData( void ) + {} + + //! return animation object + virtual const Animation::Pointer& animation() const + { return _animation; } + + //! duration + virtual void setDuration( int duration ) + { _animation.data()->setDuration( duration ); } + + //! opacity + virtual qreal opacity( void ) const + { return _opacity; } + + //! opacity + virtual void setOpacity( qreal value ) + { + + value = digitize( value ); + if( _opacity == value ) return; + + _opacity = value; + setDirty(); + + } + + private: + + //! animation handling + Animation::Pointer _animation; + + //! opacity variable + qreal _opacity; + + }; + +} + +#endif diff --git a/kstyle/animations/breezescrollbardata.cpp b/kstyle/animations/breezescrollbardata.cpp new file mode 100644 index 00000000..2ddcd5c1 --- /dev/null +++ b/kstyle/animations/breezescrollbardata.cpp @@ -0,0 +1,224 @@ +////////////////////////////////////////////////////////////////////////////// +// breezescrollbardata.cpp +// data container for QTabBar 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 "breezescrollbardata.h" +#include "breezescrollbardata.moc" + +#include +#include +#include + +Q_GUI_EXPORT QStyleOptionSlider qt_qscrollbarStyleOption(QScrollBar*); + +namespace Breeze +{ + + //______________________________________________ + ScrollBarData::ScrollBarData( QObject* parent, QWidget* target, int duration ): + SliderData( parent, target, duration ), + _position( -1, -1 ) + { + + target->installEventFilter( this ); + + _addLineData._animation = new Animation( duration, this ); + _subLineData._animation = new Animation( duration, this ); + + connect( addLineAnimation().data(), SIGNAL(finished()), SLOT(clearAddLineRect()) ); + connect( subLineAnimation().data(), SIGNAL(finished()), SLOT(clearSubLineRect()) ); + + // setup animation + setupAnimation( addLineAnimation(), "addLineOpacity" ); + setupAnimation( subLineAnimation(), "subLineOpacity" ); + + } + + //______________________________________________ + bool ScrollBarData::eventFilter( QObject* object, QEvent* event ) + { + + if( object != target().data() ) + { return SliderData::eventFilter( object, event ); } + + // check event type + switch( event->type() ) + { + + case QEvent::HoverEnter: + case QEvent::HoverMove: + hoverMoveEvent( object, event ); + break; + + case QEvent::HoverLeave: + hoverLeaveEvent( object, event ); + break; + + default: break; + + } + + return SliderData::eventFilter( object, event ); + + } + + //______________________________________________ + const Animation::Pointer& ScrollBarData::animation( QStyle::SubControl subcontrol ) const + { + switch( subcontrol ) + { + default: + case QStyle::SC_ScrollBarSlider: + return animation(); + + case QStyle::SC_ScrollBarAddLine: + return addLineAnimation(); + + case QStyle::SC_ScrollBarSubLine: + return subLineAnimation(); + } + + } + + //______________________________________________ + qreal ScrollBarData::opacity( QStyle::SubControl subcontrol ) const + { + switch( subcontrol ) + { + default: + case QStyle::SC_ScrollBarSlider: + return opacity(); + + case QStyle::SC_ScrollBarAddLine: + return addLineOpacity(); + + case QStyle::SC_ScrollBarSubLine: + return subLineOpacity(); + } + + } + + //______________________________________________ + void ScrollBarData::hoverMoveEvent( QObject* object, QEvent* event ) + { + + // try cast object to scrollbar + QScrollBar* scrollBar( qobject_cast( object ) ); + if( !scrollBar || scrollBar->isSliderDown() ) return; + + // retrieve scrollbar option + QStyleOptionSlider opt( qt_qscrollbarStyleOption( qobject_cast( object ) ) ); + + // cast event + QHoverEvent *hoverEvent = static_cast(event); + QStyle::SubControl hoverControl = scrollBar->style()->hitTestComplexControl(QStyle::CC_ScrollBar, &opt, hoverEvent->pos(), scrollBar); + + // update hover state + updateAddLineArrow( hoverControl ); + updateSubLineArrow( hoverControl ); + + // store position + _position = hoverEvent->pos(); + + } + + + //______________________________________________ + void ScrollBarData::hoverLeaveEvent( QObject* object, QEvent* event ) + { + Q_UNUSED( object ); + Q_UNUSED( event ); + + // reset hover state + updateSubLineArrow( QStyle::SC_None ); + updateAddLineArrow( QStyle::SC_None ); + + // reset mouse position + _position = QPoint( -1, -1 ); + } + + //_____________________________________________________________________ + void ScrollBarData::updateSubLineArrow( QStyle::SubControl hoverControl ) + { + if( hoverControl == QStyle::SC_ScrollBarSubLine ) + { + + if( !subLineArrowHovered() ) + { + setSubLineArrowHovered( true ); + if( enabled() ) + { + subLineAnimation().data()->setDirection( Animation::Forward ); + if( !subLineAnimation().data()->isRunning() ) subLineAnimation().data()->start(); + } else setDirty(); + } + + } else { + + if( subLineArrowHovered() ) + { + setSubLineArrowHovered( false ); + if( enabled() ) + { + subLineAnimation().data()->setDirection( Animation::Backward ); + if( !subLineAnimation().data()->isRunning() ) subLineAnimation().data()->start(); + } else setDirty(); + } + + } + } + + //_____________________________________________________________________ + void ScrollBarData::updateAddLineArrow( QStyle::SubControl hoverControl ) + { + if( hoverControl == QStyle::SC_ScrollBarAddLine ) + { + + if( !addLineArrowHovered() ) + { + setAddLineArrowHovered( true ); + if( enabled() ) + { + addLineAnimation().data()->setDirection( Animation::Forward ); + if( !addLineAnimation().data()->isRunning() ) addLineAnimation().data()->start(); + } else setDirty(); + } + + } else { + + if( addLineArrowHovered() ) + { + setAddLineArrowHovered( false ); + if( enabled() ) + { + addLineAnimation().data()->setDirection( Animation::Backward ); + if( !addLineAnimation().data()->isRunning() ) addLineAnimation().data()->start(); + } else setDirty(); + } + + } + } + +} diff --git a/kstyle/animations/breezescrollbardata.h b/kstyle/animations/breezescrollbardata.h new file mode 100644 index 00000000..e2bcd2a3 --- /dev/null +++ b/kstyle/animations/breezescrollbardata.h @@ -0,0 +1,243 @@ +#ifndef breezescrollbar_datah +#define breezescrollbar_datah + +////////////////////////////////////////////////////////////////////////////// +// breezescrollbardata.h +// data container for QScrollBar 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 "breezesliderdata.h" + +namespace Breeze +{ + + //! scrollbar data + class ScrollBarData: public SliderData + { + + Q_OBJECT + Q_PROPERTY( qreal addLineOpacity READ addLineOpacity WRITE setAddLineOpacity ) + Q_PROPERTY( qreal subLineOpacity READ subLineOpacity WRITE setSubLineOpacity ) + + public: + + //! constructor + ScrollBarData( QObject* parent, QWidget* target, int ); + + //! destructor + virtual ~ScrollBarData( void ) + {} + + //! event filter + virtual bool eventFilter( QObject*, QEvent* ); + + //! needed to avoid warning about virtual function being hidden + using SliderData::animation; + using SliderData::opacity; + + //! return animation for a given subcontrol + virtual const Animation::Pointer& animation( QStyle::SubControl ) const; + + //! return default opacity for a given subcontrol + virtual qreal opacity( QStyle::SubControl ) const; + + //! return default opacity for a given subcontrol + virtual bool isHovered( QStyle::SubControl control ) const + { + switch( control ) + { + case QStyle::SC_ScrollBarAddLine: return addLineArrowHovered(); + case QStyle::SC_ScrollBarSubLine: return subLineArrowHovered(); + default: return false; + } + + + } + + //! subControlRect + virtual QRect subControlRect( QStyle::SubControl control ) const + { + switch( control ) + { + case QStyle::SC_ScrollBarAddLine: return _addLineData._rect; + case QStyle::SC_ScrollBarSubLine: return _subLineData._rect; + default: return QRect(); + } + } + + + //! subcontrol rect + virtual void setSubControlRect( QStyle::SubControl control, const QRect& rect ) + { + switch( control ) + { + case QStyle::SC_ScrollBarAddLine: + _addLineData._rect = rect; + break; + + case QStyle::SC_ScrollBarSubLine: + _subLineData._rect = rect; + break; + + default: break; + } + } + + //! duration + virtual void setDuration( int duration ) + { + SliderData::setDuration( duration ); + addLineAnimation().data()->setDuration( duration ); + subLineAnimation().data()->setDuration( duration ); + } + + //! addLine opacity + virtual void setAddLineOpacity( qreal value ) + { + value = digitize( value ); + if( _addLineData._opacity == value ) return; + _addLineData._opacity = value; + setDirty(); + } + + //! addLine opacity + virtual qreal addLineOpacity( void ) const + { return _addLineData._opacity; } + + //! subLine opacity + virtual void setSubLineOpacity( qreal value ) + { + value = digitize( value ); + if( _subLineData._opacity == value ) return; + _subLineData._opacity = value; + setDirty(); + } + + //! subLine opacity + virtual qreal subLineOpacity( void ) const + { return _subLineData._opacity; } + + //! mouse position + QPoint position( void ) const + { return _position; } + + protected Q_SLOTS: + + //! clear addLineRect + void clearAddLineRect( void ) + { + if( addLineAnimation().data()->direction() == Animation::Backward ) + { _addLineData._rect = QRect(); } + } + + //! clear subLineRect + void clearSubLineRect( void ) + { + if( subLineAnimation().data()->direction() == Animation::Backward ) + { _subLineData._rect = QRect(); } + } + + protected: + + //! hoverMoveEvent + virtual void hoverMoveEvent( QObject*, QEvent* ); + + //! hoverMoveEvent + virtual void hoverLeaveEvent( QObject*, QEvent* ); + + //!@name hover flags + //@{ + + virtual bool addLineArrowHovered( void ) const + { return _addLineData._hovered; } + + virtual void setAddLineArrowHovered( bool value ) + { _addLineData._hovered = value; } + + virtual bool subLineArrowHovered( void ) const + { return _subLineData._hovered; } + + virtual void setSubLineArrowHovered( bool value ) + { _subLineData._hovered = value; } + + //@} + + //! update add line arrow + virtual void updateAddLineArrow( QStyle::SubControl ); + + //! update sub line arrow + virtual void updateSubLineArrow( QStyle::SubControl ); + + //!@name timelines + //@{ + + virtual const Animation::Pointer& addLineAnimation( void ) const + { return _addLineData._animation; } + + virtual const Animation::Pointer& subLineAnimation( void ) const + { return _subLineData._animation; } + + private: + + //! stores arrow data + class Data + { + + public: + + //! constructor + Data( void ): + _hovered( false ), + _opacity( AnimationData::OpacityInvalid ) + {} + + //! true if hovered + bool _hovered; + + //! animation + Animation::Pointer _animation; + + //! opacity + qreal _opacity; + + //! rect + QRect _rect; + + }; + + + //! add line data (down arrow) + Data _addLineData; + + //! subtract line data (up arrow) + Data _subLineData; + + //! mouse position + QPoint _position; + + }; + +} + +#endif diff --git a/kstyle/animations/breezescrollbarengine.cpp b/kstyle/animations/breezescrollbarengine.cpp new file mode 100644 index 00000000..85938838 --- /dev/null +++ b/kstyle/animations/breezescrollbarengine.cpp @@ -0,0 +1,69 @@ +////////////////////////////////////////////////////////////////////////////// +// breezescrollbarengine.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 "breezescrollbarengine.h" +#include "breezescrollbarengine.moc" + +#include + +namespace Breeze +{ + + //____________________________________________________________ + bool ScrollBarEngine::registerWidget( QWidget* widget ) + { + + // check widget + /* + note: widget is registered even if animation is disabled because BreezeScrollBarData + is also used in non-animated mode to store arrow rect for hover highlight + */ + if( !widget ) return false; + + // create new data class + if( !_data.contains( widget ) ) _data.insert( widget, new ScrollBarData( this, widget, duration() ), enabled() ); + + // connect destruction signal + connect( widget, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterWidget(QObject*)), Qt::UniqueConnection ); + return true; + } + + + //____________________________________________________________ + bool ScrollBarEngine::isAnimated( const QObject* object, QStyle::SubControl control ) + { + + if( DataMap::Value data = _data.find( object ) ) + { + if( Animation::Pointer animation = data.data()->animation( control ) ) return animation.data()->isRunning(); + + } + + return false; + + } + +} diff --git a/kstyle/animations/breezescrollbarengine.h b/kstyle/animations/breezescrollbarengine.h new file mode 100644 index 00000000..ba75539c --- /dev/null +++ b/kstyle/animations/breezescrollbarengine.h @@ -0,0 +1,135 @@ +#ifndef breezescrollbarengine_h +#define breezescrollbarengine_h + +////////////////////////////////////////////////////////////////////////////// +// breezescrollbarengine.h +// 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 "breezebaseengine.h" +#include "breezedatamap.h" +#include "breezescrollbardata.h" + +namespace Breeze +{ + + //! stores scrollbar hovered action and timeLine + class ScrollBarEngine: public BaseEngine + { + + Q_OBJECT + + public: + + //! constructor + explicit ScrollBarEngine( QObject* parent ): + BaseEngine( parent ) + {} + + //! destructor + virtual ~ScrollBarEngine( void ) + {} + + //! register scrollbar + virtual bool registerWidget( QWidget* ); + + //! true if widget is animated + virtual bool isAnimated( const QObject* object, QStyle::SubControl control ); + + //! animation opacity + virtual qreal opacity( const QObject* object, QStyle::SubControl control ) + { return isAnimated( object, control ) ? _data.find( object ).data()->opacity( control ):AnimationData::OpacityInvalid; } + + //! return true if given subcontrol is hovered + virtual bool isHovered( const QObject* object, QStyle::SubControl control ) + { + if( DataMap::Value data = _data.find( object ) ) return data.data()->isHovered( control ); + else return false; + } + + //! control rect associated to object + virtual QRect subControlRect( const QObject* object, QStyle::SubControl control ) + { + if( DataMap::Value data = _data.find( object ) ) return data.data()->subControlRect( control ); + else return QRect(); + } + + //! control rect + virtual void setSubControlRect( const QObject* object, QStyle::SubControl control, const QRect& rect ) + { + if( DataMap::Value data = _data.find( object ) ) + { data.data()->setSubControlRect( control, rect ); } + } + + //! control rect + virtual void updateState( const QObject* object, bool state ) + { + if( DataMap::Value data = _data.find( object ) ) + { data.data()->updateState( state ); } + } + + //! mouse position + virtual QPoint position( const QObject* object ) + { + if( DataMap::Value data = _data.find( object ) ) return data.data()->position(); + else return QPoint( -1, -1 ); + } + + //! enability + virtual void setEnabled( bool value ) + { + BaseEngine::setEnabled( value ); + /* + do not disable the map directly, because the contained BreezeScrollbarData + are also used in non animated mode to store scrollbar arrows rect. However + do disable all contains DATA object, in order to prevent actual animations + */ + foreach( const DataMap::Value data, _data ) + { if( data ) data.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/animations/breezesliderdata.cpp b/kstyle/animations/breezesliderdata.cpp new file mode 100644 index 00000000..f5a4d8f7 --- /dev/null +++ b/kstyle/animations/breezesliderdata.cpp @@ -0,0 +1,79 @@ +////////////////////////////////////////////////////////////////////////////// +// breezesliderdata.cpp +// data container for QSlider 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 "breezesliderdata.h" +#include "breezesliderdata.moc" + +#include +#include +#include + +Q_GUI_EXPORT QStyleOptionSlider qt_qsliderStyleOption(QSlider*); + + +namespace Breeze +{ + + //______________________________________________ + bool SliderData::updateState( bool state ) + { + if( state == _sliderHovered ) return false; + updateSlider( state ? QStyle::SC_SliderHandle : QStyle::SC_None ); + return true; + } + + //_____________________________________________________________________ + void SliderData::updateSlider( QStyle::SubControl hoverControl ) + { + + if( hoverControl == QStyle::SC_SliderHandle ) + { + + if( !sliderHovered() ) { + setSliderHovered( true ); + if( enabled() ) + { + animation().data()->setDirection( Animation::Forward ); + if( !animation().data()->isRunning() ) animation().data()->start(); + } else setDirty(); + } + + } else { + + if( sliderHovered() ) + { + setSliderHovered( false ); + if( enabled() ) + { + animation().data()->setDirection( Animation::Backward ); + if( !animation().data()->isRunning() ) animation().data()->start(); + } else setDirty(); + } + + } + } + +} diff --git a/kstyle/animations/breezesliderdata.h b/kstyle/animations/breezesliderdata.h new file mode 100644 index 00000000..2d9499cb --- /dev/null +++ b/kstyle/animations/breezesliderdata.h @@ -0,0 +1,81 @@ +#ifndef breezeslider_datah +#define breezeslider_datah + +////////////////////////////////////////////////////////////////////////////// +// breezesliderdata.h +// data container for QSlider 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 "breezegenericdata.h" + +#include +#include + +namespace Breeze +{ + + //! scrollbar data + class SliderData: public GenericData + { + + Q_OBJECT + + public: + + //! constructor + SliderData( QObject* parent, QWidget* target, int duration ): + GenericData( parent, target, duration ), + _sliderHovered( false ) + {} + + //! destructor + virtual ~SliderData( void ) + {} + + //! update state + virtual bool updateState( bool ); + + protected: + + //! hover + virtual bool sliderHovered( void ) const + { return _sliderHovered; } + + //! hover + virtual void setSliderHovered( bool value ) + { _sliderHovered = value; } + + //! update slider + virtual void updateSlider( QStyle::SubControl ); + + private: + + //! true when slider is hovered + bool _sliderHovered; + + }; + +} + +#endif diff --git a/kstyle/breeze.kcfg b/kstyle/breeze.kcfg index f278aec9..b2aa1a11 100644 --- a/kstyle/breeze.kcfg +++ b/kstyle/breeze.kcfg @@ -8,6 +8,23 @@ + + + true + + + + 10 + + + + true + + + + 150 + + true