1
//////////////////////////////////////////////////////////////////////////////
2
// oxygenmenuengine.cpp
3
// stores event filters and maps widgets to timelines for animations
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to
10
// deal in the Software without restriction, including without limitation the
11
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
// sell copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
//////////////////////////////////////////////////////////////////////////////
27
#include "oxygenmenuengine.h"
28
#include "oxygenmenuengine.moc"
33
//____________________________________________________________
34
MenuEngineV1::MenuEngineV1( QObject* parent, MenuBaseEngine* other ):
35
MenuBaseEngine( parent )
39
foreach( QWidget* widget, other->registeredWidgets() )
40
{ registerWidget( widget ); }
44
//____________________________________________________________
45
bool MenuEngineV1::registerWidget( QWidget* widget )
48
if( !widget ) return false;
50
// create new data class
51
if( !_data.contains( widget ) ) _data.insert( widget, new MenuDataV1( this, widget, duration() ), enabled() );
53
// connect destruction signal
54
connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
58
//____________________________________________________________
59
bool MenuEngineV1::isAnimated( const QObject* object, WidgetIndex index )
61
DataMap<MenuDataV1>::Value data( _data.find( object ) );
67
if( Animation::Pointer animation = data.data()->animation( index ) ) {
69
return animation.data()->isRunning();
74
//____________________________________________________________
75
BaseEngine::WidgetList MenuEngineV1::registeredWidgets( void ) const
80
// the typedef is needed to make Krazy happy
81
typedef DataMap<MenuDataV1>::Value Value;
82
foreach( const Value& value, _data )
83
{ if( value ) out.insert( value.data()->target().data() ); }
89
//____________________________________________________________
90
MenuEngineV2::MenuEngineV2( QObject* parent, MenuBaseEngine* other ):
91
MenuBaseEngine( parent ),
92
_followMouseDuration( 150 )
96
foreach( QWidget* widget, other->registeredWidgets() )
97
{ registerWidget( widget ); }
101
//____________________________________________________________
102
bool MenuEngineV2::registerWidget( QWidget* widget )
105
if( !widget ) return false;
107
// create new data class
108
if( !_data.contains( widget ) )
110
DataMap<MenuDataV2>::Value value( new MenuDataV2( this, widget, duration() ) );
111
value.data()->setFollowMouseDuration( followMouseDuration() );
112
_data.insert( widget, value, enabled() );
115
// connect destruction signal
116
connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
121
//____________________________________________________________
122
QRect MenuEngineV2::currentRect( const QObject* object, WidgetIndex )
124
if( !enabled() ) return QRect();
125
DataMap<MenuDataV2>::Value data( _data.find( object ) );
126
return data ? data.data()->currentRect():QRect();
130
//____________________________________________________________
131
bool MenuEngineV2::isAnimated( const QObject* object, WidgetIndex index )
133
DataMap<MenuDataV2>::Value data( _data.find( object ) );
141
case Oxygen::Previous:
143
if( Animation::Pointer animation = data.data()->animation() )
145
return animation.data()->direction() == Animation::Backward && animation.data()->isRunning();
149
case Oxygen::Current:
151
if( data.data()->animation() && data.data()->animation().data()->isRunning() ) return true;
155
default: return false;
161
//____________________________________________________________
162
QRect MenuEngineV2::animatedRect( const QObject* object )
164
if( !enabled() ) return QRect();
165
DataMap<MenuDataV2>::Value data( _data.find( object ) );
166
return data ? data.data()->animatedRect():QRect();
170
//____________________________________________________________
171
bool MenuEngineV2::isTimerActive( const QObject* object )
173
if( !enabled() ) return false;
174
DataMap<MenuDataV2>::Value data( _data.find( object ) );
175
return data ? data.data()->timer().isActive():false;
179
//____________________________________________________________
180
BaseEngine::WidgetList MenuEngineV2::registeredWidgets( void ) const
185
// the typedef is needed to make Krazy happy
186
typedef DataMap<MenuDataV2>::Value Value;
187
foreach( const Value& value, _data )
188
{ if( value ) out.insert( value.data()->target().data() ); }