~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kstyles/oxygen/animations/oxygenmenuengine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
// oxygenmenuengine.cpp
 
3
// stores event filters and maps widgets to timelines for animations
 
4
// -------------------
 
5
//
 
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
7
//
 
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:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
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
 
24
// IN THE SOFTWARE.
 
25
//////////////////////////////////////////////////////////////////////////////
 
26
 
 
27
#include "oxygenmenuengine.h"
 
28
#include "oxygenmenuengine.moc"
 
29
 
 
30
namespace Oxygen
 
31
{
 
32
 
 
33
    //____________________________________________________________
 
34
    MenuEngineV1::MenuEngineV1( QObject* parent, MenuBaseEngine* other ):
 
35
        MenuBaseEngine( parent )
 
36
    {
 
37
        if( other )
 
38
        {
 
39
            foreach( QWidget* widget,  other->registeredWidgets() )
 
40
            { registerWidget( widget ); }
 
41
        }
 
42
    }
 
43
 
 
44
    //____________________________________________________________
 
45
    bool MenuEngineV1::registerWidget( QWidget* widget )
 
46
    {
 
47
 
 
48
        if( !widget ) return false;
 
49
 
 
50
        // create new data class
 
51
        if( !_data.contains( widget ) ) _data.insert( widget, new MenuDataV1( this, widget, duration() ), enabled() );
 
52
 
 
53
        // connect destruction signal
 
54
        connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
 
55
        return true;
 
56
    }
 
57
 
 
58
    //____________________________________________________________
 
59
    bool MenuEngineV1::isAnimated( const QObject* object, WidgetIndex index )
 
60
    {
 
61
        DataMap<MenuDataV1>::Value data( _data.find( object ) );
 
62
        if( !data )
 
63
        {
 
64
            return false;
 
65
        }
 
66
 
 
67
        if( Animation::Pointer animation = data.data()->animation( index ) ) {
 
68
 
 
69
            return animation.data()->isRunning();
 
70
 
 
71
        } else return false;
 
72
    }
 
73
 
 
74
    //____________________________________________________________
 
75
    BaseEngine::WidgetList MenuEngineV1::registeredWidgets( void ) const
 
76
    {
 
77
 
 
78
        WidgetList out;
 
79
 
 
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() ); }
 
84
 
 
85
        return out;
 
86
 
 
87
    }
 
88
 
 
89
    //____________________________________________________________
 
90
    MenuEngineV2::MenuEngineV2( QObject* parent, MenuBaseEngine* other ):
 
91
        MenuBaseEngine( parent ),
 
92
        _followMouseDuration( 150 )
 
93
    {
 
94
        if( other )
 
95
        {
 
96
            foreach( QWidget* widget, other->registeredWidgets() )
 
97
            { registerWidget( widget ); }
 
98
        }
 
99
    }
 
100
 
 
101
    //____________________________________________________________
 
102
    bool MenuEngineV2::registerWidget( QWidget* widget )
 
103
    {
 
104
 
 
105
        if( !widget ) return false;
 
106
 
 
107
        // create new data class
 
108
        if( !_data.contains( widget ) )
 
109
        {
 
110
            DataMap<MenuDataV2>::Value value( new MenuDataV2( this, widget, duration() ) );
 
111
            value.data()->setFollowMouseDuration( followMouseDuration() );
 
112
            _data.insert( widget, value, enabled() );
 
113
        }
 
114
 
 
115
        // connect destruction signal
 
116
        connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
 
117
 
 
118
        return true;
 
119
    }
 
120
 
 
121
    //____________________________________________________________
 
122
    QRect MenuEngineV2::currentRect( const QObject* object, WidgetIndex )
 
123
    {
 
124
        if( !enabled() ) return QRect();
 
125
        DataMap<MenuDataV2>::Value data( _data.find( object ) );
 
126
        return data ? data.data()->currentRect():QRect();
 
127
 
 
128
    }
 
129
 
 
130
    //____________________________________________________________
 
131
    bool MenuEngineV2::isAnimated( const QObject* object, WidgetIndex index )
 
132
    {
 
133
        DataMap<MenuDataV2>::Value data( _data.find( object ) );
 
134
        if( !data )
 
135
        {
 
136
            return false;
 
137
        }
 
138
 
 
139
        switch( index )
 
140
        {
 
141
            case Oxygen::Previous:
 
142
            {
 
143
                if( Animation::Pointer animation = data.data()->animation() )
 
144
                {
 
145
                    return animation.data()->direction() == Animation::Backward && animation.data()->isRunning();
 
146
                } else return false;
 
147
            }
 
148
 
 
149
            case Oxygen::Current:
 
150
            {
 
151
                if( data.data()->animation() && data.data()->animation().data()->isRunning() ) return true;
 
152
                else return false;
 
153
            }
 
154
 
 
155
            default: return false;
 
156
 
 
157
        }
 
158
 
 
159
    }
 
160
 
 
161
    //____________________________________________________________
 
162
    QRect MenuEngineV2::animatedRect( const QObject* object )
 
163
    {
 
164
        if( !enabled() ) return QRect();
 
165
        DataMap<MenuDataV2>::Value data( _data.find( object ) );
 
166
        return data ? data.data()->animatedRect():QRect();
 
167
 
 
168
    }
 
169
 
 
170
    //____________________________________________________________
 
171
    bool MenuEngineV2::isTimerActive( const QObject* object )
 
172
    {
 
173
        if( !enabled() ) return false;
 
174
        DataMap<MenuDataV2>::Value data( _data.find( object ) );
 
175
        return data ? data.data()->timer().isActive():false;
 
176
 
 
177
    }
 
178
 
 
179
    //____________________________________________________________
 
180
    BaseEngine::WidgetList MenuEngineV2::registeredWidgets( void ) const
 
181
    {
 
182
 
 
183
        WidgetList out;
 
184
 
 
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() ); }
 
189
 
 
190
        return out;
 
191
 
 
192
    }
 
193
 
 
194
}