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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/animations/oxygendatamap.h

  • 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
#ifndef oxygendatamap_h
 
2
#define oxygendatamap_h
 
3
 
 
4
//////////////////////////////////////////////////////////////////////////////
 
5
// oxygendatamap.h
 
6
// stores event filters and maps widgets to timelines for animations
 
7
// -------------------
 
8
//
 
9
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
10
//
 
11
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
12
// of this software and associated documentation files (the "Software"), to
 
13
// deal in the Software without restriction, including without limitation the
 
14
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
15
// sell copies of the Software, and to permit persons to whom the Software is
 
16
// furnished to do so, subject to the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be included in
 
19
// all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
24
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
27
// IN THE SOFTWARE.
 
28
//////////////////////////////////////////////////////////////////////////////
 
29
 
 
30
#include <QtCore/QObject>
 
31
#include <QtCore/QMap>
 
32
#include <QtCore/QWeakPointer>
 
33
 
 
34
#include <QtGui/QPaintDevice>
 
35
 
 
36
namespace Oxygen
 
37
{
 
38
 
 
39
    //! data map
 
40
    /*! it maps templatized data object to associated object */
 
41
    template< typename K, typename T > class BaseDataMap: public QMap< const K*, QWeakPointer<T> >
 
42
    {
 
43
 
 
44
        public:
 
45
 
 
46
        typedef const K* Key;
 
47
        typedef QWeakPointer<T> Value;
 
48
 
 
49
        //! constructor
 
50
        BaseDataMap( void ):
 
51
            QMap<Key, Value>(),
 
52
            _enabled( true ),
 
53
            _lastKey( NULL )
 
54
        {}
 
55
 
 
56
        //! destructor
 
57
        virtual ~BaseDataMap( void )
 
58
        {}
 
59
 
 
60
        //! insertion
 
61
        virtual typename QMap< Key, Value >::iterator insert( const Key& key, const Value& value, bool enabled = true )
 
62
        {
 
63
            if( value ) value.data()->setEnabled( enabled );
 
64
            return QMap< Key, Value >::insert( key, value );
 
65
        }
 
66
 
 
67
        //! find value
 
68
        Value find( Key key )
 
69
        {
 
70
            if( !( enabled() && key ) ) return Value();
 
71
            if( key == _lastKey ) return _lastValue;
 
72
            else {
 
73
                Value out;
 
74
                typename QMap<Key, Value>::iterator iter( QMap<Key, Value>::find( key ) );
 
75
                if( iter != QMap<Key, Value>::end() ) out = iter.value();
 
76
                _lastKey = key;
 
77
                _lastValue = out;
 
78
                return out;
 
79
            }
 
80
        }
 
81
 
 
82
        //! unregister widget
 
83
        bool unregisterWidget( Key key )
 
84
        {
 
85
 
 
86
            // check key
 
87
            if( !key ) return false;
 
88
 
 
89
            // clear last value if needed
 
90
            if( key == _lastKey )
 
91
            {
 
92
 
 
93
                if( _lastValue ) _lastValue.clear();
 
94
                _lastKey = NULL;
 
95
 
 
96
            }
 
97
 
 
98
            // find key in map
 
99
            typename QMap<Key, Value>::iterator iter( QMap<Key, Value>::find( key ) );
 
100
            if( iter == QMap<Key, Value>::end() ) return false;
 
101
 
 
102
            // delete value from map if found
 
103
            if( iter.value() ) iter.value().data()->deleteLater();
 
104
            QMap<Key, Value>::erase( iter );
 
105
 
 
106
            return true;
 
107
 
 
108
        }
 
109
 
 
110
        //! maxFrame
 
111
        void setEnabled( bool enabled )
 
112
        {
 
113
            _enabled = enabled;
 
114
            foreach( const Value& value, *this )
 
115
            { if( value ) value.data()->setEnabled( enabled ); }
 
116
        }
 
117
 
 
118
        //! enability
 
119
        bool enabled( void ) const
 
120
        { return _enabled; }
 
121
 
 
122
        //! duration
 
123
        void setDuration( int duration ) const
 
124
        {
 
125
            foreach( const Value& value, *this )
 
126
            { if( value ) value.data()->setDuration( duration ); }
 
127
        }
 
128
 
 
129
        private:
 
130
 
 
131
        //! enability
 
132
        bool _enabled;
 
133
 
 
134
        //! last key
 
135
        Key _lastKey;
 
136
 
 
137
        //! last value
 
138
        Value _lastValue;
 
139
 
 
140
    };
 
141
 
 
142
    //! standard data map, using QObject as a key
 
143
    template< typename T > class DataMap: public BaseDataMap< QObject, T >
 
144
    {
 
145
 
 
146
        public:
 
147
 
 
148
        //! constructor
 
149
        DataMap( void )
 
150
        {}
 
151
 
 
152
        //! destructor
 
153
        virtual ~DataMap( void )
 
154
        {}
 
155
 
 
156
    };
 
157
 
 
158
    //! QPaintDevice based dataMap
 
159
    template< typename T > class PaintDeviceDataMap: public BaseDataMap< QPaintDevice, T >
 
160
    {
 
161
 
 
162
        public:
 
163
 
 
164
        //! constructor
 
165
        PaintDeviceDataMap( void )
 
166
        {}
 
167
 
 
168
        //! destructor
 
169
        virtual ~PaintDeviceDataMap( void )
 
170
        {}
 
171
 
 
172
    };
 
173
 
 
174
}
 
175
 
 
176
#endif