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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/animations/oxygenmenubarengine.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
// oxygenmenubarengine.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 "oxygenmenubarengine.h"
 
28
#include "oxygenmenubarengine.moc"
 
29
 
 
30
#include <QtCore/QEvent>
 
31
 
 
32
namespace Oxygen
 
33
{
 
34
 
 
35
    //____________________________________________________________
 
36
    MenuBarEngineV1::MenuBarEngineV1( QObject* parent, MenuBarBaseEngine* other ):
 
37
        MenuBarBaseEngine( parent )
 
38
    {
 
39
        if( other )
 
40
        {
 
41
            foreach( QWidget* widget,  other->registeredWidgets() )
 
42
            { registerWidget( widget ); }
 
43
        }
 
44
    }
 
45
 
 
46
    //____________________________________________________________
 
47
    bool MenuBarEngineV1::registerWidget( QWidget* widget )
 
48
    {
 
49
 
 
50
        if( !widget ) return false;
 
51
 
 
52
        // create new data class
 
53
        if( !_data.contains( widget ) ) _data.insert( widget, new MenuBarDataV1( this, widget, duration() ), enabled() );
 
54
 
 
55
        // connect destruction signal
 
56
        connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
 
57
        return true;
 
58
 
 
59
    }
 
60
 
 
61
    //____________________________________________________________
 
62
    bool MenuBarEngineV1::isAnimated( const QObject* object, const QPoint& position )
 
63
    {
 
64
        DataMap<MenuBarDataV1>::Value data( _data.find( object ) );
 
65
        if( !data ) return false;
 
66
        if( Animation::Pointer animation = data.data()->animation( position ) ) return animation.data()->isRunning();
 
67
        else return false;
 
68
    }
 
69
 
 
70
    //____________________________________________________________
 
71
    BaseEngine::WidgetList MenuBarEngineV1::registeredWidgets( void ) const
 
72
    {
 
73
 
 
74
        WidgetList out ;
 
75
 
 
76
        // the typedef is needed to make Krazy happy
 
77
        typedef DataMap<MenuBarDataV1>::Value Value;
 
78
        foreach( const Value& value, _data )
 
79
        { if( value ) out.insert( value.data()->target().data() ); }
 
80
 
 
81
        return out;
 
82
 
 
83
    }
 
84
 
 
85
    //____________________________________________________________
 
86
    MenuBarEngineV2::MenuBarEngineV2( QObject* parent, MenuBarBaseEngine* other ):
 
87
        MenuBarBaseEngine( parent ),
 
88
        _followMouseDuration( 150 )
 
89
    {
 
90
        if( other )
 
91
        {
 
92
            foreach( QWidget* widget, other->registeredWidgets() )
 
93
            { registerWidget( widget ); }
 
94
        }
 
95
    }
 
96
 
 
97
    //____________________________________________________________
 
98
    bool MenuBarEngineV2::registerWidget( QWidget* widget )
 
99
    {
 
100
 
 
101
        if( !widget ) return false;
 
102
 
 
103
        // create new data class
 
104
        if( !_data.contains( widget ) )
 
105
        {
 
106
            DataMap<MenuBarDataV2>::Value value( new MenuBarDataV2( this, widget, duration() ) );
 
107
            value.data()->setFollowMouseDuration( followMouseDuration() );
 
108
            _data.insert( widget, value, enabled() );
 
109
        }
 
110
 
 
111
        // connect destruction signal
 
112
        connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
 
113
        return true;
 
114
 
 
115
    }
 
116
 
 
117
 
 
118
    //____________________________________________________________
 
119
    bool MenuBarEngineV2::isAnimated( const QObject* object, const QPoint& )
 
120
    {
 
121
        if( !enabled() ) return false;
 
122
        DataMap<MenuBarDataV2>::Value data( _data.find( object ) );
 
123
        if( !data ) return false;
 
124
        if( data.data()->animation() && data.data()->animation().data()->isRunning() ) return true;
 
125
        else if( Animation::Pointer animation = data.data()->progressAnimation() ) return animation.data()->isRunning();
 
126
        else return false;
 
127
 
 
128
    }
 
129
 
 
130
    //____________________________________________________________
 
131
    QRect MenuBarEngineV2::currentRect( const QObject* object, const QPoint& )
 
132
    {
 
133
        if( !enabled() ) return QRect();
 
134
        DataMap<MenuBarDataV2>::Value data( _data.find( object ) );
 
135
        return data ? data.data()->currentRect():QRect();
 
136
    }
 
137
 
 
138
    //____________________________________________________________
 
139
    QRect MenuBarEngineV2::animatedRect( const QObject* object )
 
140
    {
 
141
        if( !enabled() ) return QRect();
 
142
        DataMap<MenuBarDataV2>::Value data( _data.find( object ) );
 
143
        return data ? data.data()->animatedRect():QRect();
 
144
 
 
145
    }
 
146
 
 
147
    //____________________________________________________________
 
148
    bool MenuBarEngineV2::isTimerActive( const QObject* object )
 
149
    {
 
150
        if( !enabled() ) return false;
 
151
        DataMap<MenuBarDataV2>::Value data( _data.find( object ) );
 
152
        return data ? data.data()->timer().isActive():false;
 
153
    }
 
154
 
 
155
    //____________________________________________________________
 
156
    BaseEngine::WidgetList MenuBarEngineV2::registeredWidgets( void ) const
 
157
    {
 
158
 
 
159
        WidgetList out;
 
160
 
 
161
        // the typedef is needed to make Krazy happy
 
162
        typedef DataMap<MenuBarDataV2>::Value Value;
 
163
        foreach( const Value& value, _data )
 
164
        { if( value ) out.insert( value.data()->target().data() ); }
 
165
 
 
166
        return out;
 
167
 
 
168
    }
 
169
 
 
170
}