2
//////////////////////////////////////////////////////////////////////////////
3
// oxygenwidgetstateengine.h
4
// stores event filters and maps widgets to timelines for animations
7
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to
11
// deal in the Software without restriction, including without limitation the
12
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13
// sell copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26
//////////////////////////////////////////////////////////////////////////////
28
#include "oxygenwidgetstateengine.h"
29
#include "oxygenwidgetstateengine.moc"
31
#include "oxygenenabledata.h"
36
//____________________________________________________________
37
bool WidgetStateEngine::registerWidget( QWidget* widget, AnimationModes mode )
40
if( !widget ) return false;
41
if( mode&AnimationHover && !_hoverData.contains( widget ) ) { _hoverData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); }
42
if( mode&AnimationFocus && !_focusData.contains( widget ) ) { _focusData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); }
43
if( mode&AnimationEnable && !_enableData.contains( widget ) ) { _enableData.insert( widget, new EnableData( this, widget, duration() ), enabled() ); }
45
// connect destruction signal
46
connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
52
//____________________________________________________________
53
BaseEngine::WidgetList WidgetStateEngine::registeredWidgets( AnimationModes mode ) const
58
// the typedef is needed to make Krazy happy
59
typedef DataMap<WidgetStateData>::Value Value;
61
if( mode&AnimationHover )
63
foreach( const Value& value, _hoverData )
64
{ if( value ) out.insert( value.data()->target().data() ); }
67
if( mode&AnimationFocus )
69
foreach( const Value& value, _focusData )
70
{ if( value ) out.insert( value.data()->target().data() ); }
73
if( mode&AnimationEnable )
75
foreach( const Value& value, _enableData )
76
{ if( value ) out.insert( value.data()->target().data() ); }
83
//____________________________________________________________
84
bool WidgetStateEngine::updateState( const QObject* object, AnimationMode mode, bool value )
86
DataMap<WidgetStateData>::Value data( WidgetStateEngine::data( object, mode ) );
87
return ( data && data.data()->updateState( value ) );
90
//____________________________________________________________
91
bool WidgetStateEngine::isAnimated( const QObject* object, AnimationMode mode )
94
DataMap<WidgetStateData>::Value data( WidgetStateEngine::data( object, mode ) );
95
return ( data && data.data()->animation() && data.data()->animation().data()->isRunning() );
99
//____________________________________________________________
100
DataMap<WidgetStateData>::Value WidgetStateEngine::data( const QObject* object, AnimationMode mode )
105
case AnimationHover: return _hoverData.find( object ).data();
106
case AnimationFocus: return _focusData.find( object ).data();
107
case AnimationEnable: return _enableData.find( object ).data();
108
default: return DataMap<WidgetStateData>::Value();