parent
19ed1b2ee8
commit
744b6fd3c2
19 changed files with 1752 additions and 0 deletions
@ -0,0 +1,28 @@ |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezeanimation.h
|
||||
// stores event filters and maps widgets to animations for animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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" |
||||
@ -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 <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QPointer> |
||||
#include <QPropertyAnimation> |
||||
#include <QVariant> |
||||
|
||||
namespace Breeze |
||||
{ |
||||
|
||||
class Animation: public QPropertyAnimation |
||||
{ |
||||
|
||||
Q_OBJECT |
||||
|
||||
public: |
||||
|
||||
//! TimeLine shared pointer
|
||||
typedef QPointer<Animation> 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 |
||||
@ -0,0 +1,48 @@ |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezeanimationdata.cpp
|
||||
// base class data container needed for widget animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 ); |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -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 <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QEvent> |
||||
#include <QObject> |
||||
#include <QPointer> |
||||
#include <QWidget> |
||||
#include <cmath> |
||||
|
||||
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<QWidget>& 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<QWidget> _target; |
||||
|
||||
//! enability
|
||||
bool _enabled; |
||||
|
||||
//! steps
|
||||
static int _steps; |
||||
|
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,117 @@ |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezeanimations.cpp
|
||||
// container for all animation engines
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
|
||||
// Copyright (c) 2006, 2007 Casper Boemann <cbr@boemann.dk>
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QScrollBar> |
||||
|
||||
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<QScrollBar*>( 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<BaseEngine*>(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*)) ); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,85 @@ |
||||
#ifndef breezeanimations_h |
||||
#define breezeanimations_h |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezeanimations.h
|
||||
// container for all animation engines
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QObject> |
||||
#include <QList> |
||||
|
||||
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 |
||||
@ -0,0 +1,28 @@ |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezebaseengine.cpp
|
||||
// base engine
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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" |
||||
@ -0,0 +1,97 @@ |
||||
#ifndef breezebaseengine_h |
||||
#define breezebaseengine_h |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezebaseengine.h
|
||||
// base engine
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QObject> |
||||
#include <QSet> |
||||
#include <QPointer> |
||||
|
||||
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<BaseEngine> 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<QWidget*> WidgetList; |
||||
|
||||
//! returns registered widgets
|
||||
virtual WidgetList registeredWidgets( void ) const |
||||
{ return WidgetList(); } |
||||
|
||||
private: |
||||
|
||||
//! engine enability
|
||||
bool _enabled; |
||||
|
||||
//! animation duration
|
||||
int _duration; |
||||
|
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -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 <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QObject> |
||||
#include <QMap> |
||||
#include <QPaintDevice> |
||||
#include <QPointer> |
||||
|
||||
namespace Breeze |
||||
{ |
||||
|
||||
//! data map
|
||||
/*! it maps templatized data object to associated object */ |
||||
template< typename K, typename T > class BaseDataMap: public QMap< const K*, QPointer<T> > |
||||
{ |
||||
|
||||
public: |
||||
|
||||
typedef const K* Key; |
||||
typedef QPointer<T> Value; |
||||
|
||||
//! constructor
|
||||
BaseDataMap( void ): |
||||
QMap<Key, Value>(), |
||||
_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<Key, Value>::iterator iter( QMap<Key, Value>::find( key ) ); |
||||
if( iter != QMap<Key, Value>::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<Key, Value>::iterator iter( QMap<Key, Value>::find( key ) ); |
||||
if( iter == QMap<Key, Value>::end() ) return false; |
||||
|
||||
// delete value from map if found
|
||||
if( iter.value() ) iter.value().data()->deleteLater(); |
||||
QMap<Key, Value>::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 |
||||
@ -0,0 +1,42 @@ |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezegenericdata.cpp
|
||||
// generic data container for widget animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QTextStream> |
||||
|
||||
namespace Breeze |
||||
{ |
||||
|
||||
//______________________________________________
|
||||
GenericData::GenericData( QObject* parent, QWidget* target, int duration ): |
||||
AnimationData( parent, target ), |
||||
_animation( new Animation( duration, this ) ), |
||||
_opacity(0) |
||||
{ setupAnimation( _animation, "opacity" ); } |
||||
|
||||
} |
||||
@ -0,0 +1,93 @@ |
||||
#ifndef breezegeneric_datah |
||||
#define breezegeneric_datah |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezegenericdata.h
|
||||
// generic data container for animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QObject> |
||||
#include <QTextStream> |
||||
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 |
||||
@ -0,0 +1,224 @@ |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezescrollbardata.cpp
|
||||
// data container for QTabBar animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QHoverEvent> |
||||
#include <QScrollBar> |
||||
#include <QStyleOptionSlider> |
||||
|
||||
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<QScrollBar*>( object ) ); |
||||
if( !scrollBar || scrollBar->isSliderDown() ) return; |
||||
|
||||
// retrieve scrollbar option
|
||||
QStyleOptionSlider opt( qt_qscrollbarStyleOption( qobject_cast<QScrollBar*>( object ) ) ); |
||||
|
||||
// cast event
|
||||
QHoverEvent *hoverEvent = static_cast<QHoverEvent*>(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(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,243 @@ |
||||
#ifndef breezescrollbar_datah |
||||
#define breezescrollbar_datah |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezescrollbardata.h
|
||||
// data container for QScrollBar animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 |
||||
@ -0,0 +1,69 @@ |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezescrollbarengine.cpp
|
||||
// stores event filters and maps widgets to timelines for animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QEvent> |
||||
|
||||
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<ScrollBarData>::Value data = _data.find( object ) ) |
||||
{ |
||||
if( Animation::Pointer animation = data.data()->animation( control ) ) return animation.data()->isRunning(); |
||||
|
||||
} |
||||
|
||||
return false; |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -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 <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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<ScrollBarData>::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<ScrollBarData>::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<ScrollBarData>::Value data = _data.find( object ) ) |
||||
{ data.data()->setSubControlRect( control, rect ); } |
||||
} |
||||
|
||||
//! control rect
|
||||
virtual void updateState( const QObject* object, bool state ) |
||||
{ |
||||
if( DataMap<ScrollBarData>::Value data = _data.find( object ) ) |
||||
{ data.data()->updateState( state ); } |
||||
} |
||||
|
||||
//! mouse position
|
||||
virtual QPoint position( const QObject* object ) |
||||
{ |
||||
if( DataMap<ScrollBarData>::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<ScrollBarData>::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<ScrollBarData> _data; |
||||
|
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,79 @@ |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezesliderdata.cpp
|
||||
// data container for QSlider animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QHoverEvent> |
||||
#include <QSlider> |
||||
#include <QStyleOptionSlider> |
||||
|
||||
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(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,81 @@ |
||||
#ifndef breezeslider_datah |
||||
#define breezeslider_datah |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// breezesliderdata.h
|
||||
// data container for QSlider animations
|
||||
// -------------------
|
||||
//
|
||||
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
//
|
||||
// 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 <QStyle> |
||||
#include <QStyleOptionSlider> |
||||
|
||||
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 |
||||
Loading…
Reference in new issue