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

« back to all changes in this revision

Viewing changes to kwin/clients/oxygen/oxygenclientgroupitemdata.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 oxygenclientgroupitemdata_h
 
2
#define oxygenclientgroupitemdata_h
 
3
 
 
4
//////////////////////////////////////////////////////////////////////////////
 
5
// oxygenclientgroupitemdata.h
 
6
// handles tabs' geometry and 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 "oxygenbutton.h"
 
31
#include "oxygenanimation.h"
 
32
 
 
33
#include <QtCore/QList>
 
34
#include <QtCore/QWeakPointer>
 
35
#include <QtCore/QRect>
 
36
 
 
37
namespace Oxygen
 
38
{
 
39
 
 
40
    class Client;
 
41
 
 
42
    //! animation type
 
43
    enum AnimationType {
 
44
        AnimationNone = 0,
 
45
        AnimationEnter = 1<<0,
 
46
        AnimationMove = 1<<1,
 
47
        AnimationLeave = 1<<2,
 
48
        AnimationSameTarget = 1<<3
 
49
    };
 
50
 
 
51
    Q_DECLARE_FLAGS(AnimationTypes, AnimationType)
 
52
 
 
53
    //! tab data
 
54
    class ClientGroupItemData
 
55
    {
 
56
 
 
57
        public:
 
58
 
 
59
        //! constructor
 
60
        explicit ClientGroupItemData( void )
 
61
        {}
 
62
 
 
63
        //! destructor
 
64
        virtual ~ClientGroupItemData( void )
 
65
        {}
 
66
 
 
67
        //! reset all rects to argument
 
68
        void reset( const QRect& rect )
 
69
        {
 
70
            _refBoundingRect = rect;
 
71
            _startBoundingRect = rect;
 
72
            _endBoundingRect = rect;
 
73
            _boundingRect = rect;
 
74
        }
 
75
 
 
76
        //! tab active rect
 
77
        QRect _activeRect;
 
78
 
 
79
        //! reference bounding rect
 
80
        /*! it is usually identical to activeRect unless there is only one tab in window */
 
81
        QRect _refBoundingRect;
 
82
 
 
83
        //! tab drawing rect
 
84
        QRect _startBoundingRect;
 
85
 
 
86
        //! tab drawing rect
 
87
        QRect _endBoundingRect;
 
88
 
 
89
        //! tab drawing rect
 
90
        QRect _boundingRect;
 
91
 
 
92
        //! tab button
 
93
        typedef QWeakPointer<Button> ButtonPointer;
 
94
        ButtonPointer _closeButton;
 
95
 
 
96
    };
 
97
 
 
98
    class ClientGroupItemDataList: public QObject, public QList<ClientGroupItemData>
 
99
    {
 
100
 
 
101
        Q_OBJECT
 
102
 
 
103
        //! declare animation progress property
 
104
        Q_PROPERTY( qreal progress READ progress WRITE setProgress )
 
105
 
 
106
        public:
 
107
 
 
108
        //! invalid item index
 
109
        enum { NoItem = -1 };
 
110
 
 
111
        //! constructor
 
112
        ClientGroupItemDataList( Client* parent );
 
113
 
 
114
        //! dirty state
 
115
        void setDirty( const bool& value )
 
116
        { _dirty = value; }
 
117
 
 
118
        //! dirty state
 
119
        bool isDirty( void ) const
 
120
        { return _dirty; }
 
121
 
 
122
        //! enable animations
 
123
        void setAnimationsEnabled( bool value )
 
124
        { animationsEnabled_ = value; }
 
125
 
 
126
        //! animations enabled
 
127
        bool animationsEnabled( void ) const
 
128
        { return animationsEnabled_; }
 
129
 
 
130
        //! true if being animated
 
131
        bool isAnimated( void ) const
 
132
        { return animationType_ != AnimationNone; }
 
133
 
 
134
        //! animation type
 
135
        AnimationTypes animationType( void ) const
 
136
        { return animationType_; }
 
137
 
 
138
        //! return item index matching QPoint, or -1 if none
 
139
        int itemAt( const QPoint&, bool ) const;
 
140
 
 
141
        //! returns true if index is target
 
142
        bool isTarget( int index ) const
 
143
        { return index == targetItem_; }
 
144
 
 
145
        //! start animation
 
146
        /* might need to add the side of the target here */
 
147
        void animate( AnimationTypes, int = NoItem );
 
148
 
 
149
        //! true if animation is in progress
 
150
        bool isAnimationRunning( void ) const
 
151
        { return animation().data()->isRunning(); }
 
152
 
 
153
        //! update button activity
 
154
        void updateButtonActivity( int visibleItem ) const;
 
155
 
 
156
        //! update buttons
 
157
        void updateButtons( bool alsoUpdate ) const;
 
158
 
 
159
        //! target rect
 
160
        const QRect& targetRect( void ) const
 
161
        { return targetRect_; }
 
162
 
 
163
        //!@name animation progress
 
164
        //@{
 
165
 
 
166
        //! return animation object
 
167
        virtual const Animation::Pointer& animation() const
 
168
        { return _animation; }
 
169
 
 
170
        void setProgress( qreal value )
 
171
        {
 
172
            if( progress_ == value ) return;
 
173
            progress_ = value;
 
174
            updateBoundingRects();
 
175
        }
 
176
 
 
177
        qreal progress( void ) const
 
178
        { return progress_; }
 
179
 
 
180
        //@}
 
181
 
 
182
        protected:
 
183
 
 
184
        //! update bounding rects
 
185
        void updateBoundingRects( bool alsoUpdate = true );
 
186
 
 
187
        private:
 
188
 
 
189
        //! client
 
190
        Client& _client;
 
191
 
 
192
        //! dirty flag
 
193
        /* used to trigger update at next paintEvent */
 
194
        bool _dirty;
 
195
 
 
196
        //! true if animations are enabled
 
197
        bool animationsEnabled_;
 
198
 
 
199
        //! animation
 
200
        Animation::Pointer _animation;
 
201
 
 
202
        //! last animation type
 
203
        AnimationTypes animationType_;
 
204
 
 
205
        //! animation progress
 
206
        qreal progress_;
 
207
 
 
208
        //! dragged item
 
209
        int draggedItem_;
 
210
 
 
211
        //! target item
 
212
        int targetItem_;
 
213
 
 
214
        //! target rect
 
215
        QRect targetRect_;
 
216
 
 
217
    };
 
218
 
 
219
    Q_DECLARE_OPERATORS_FOR_FLAGS(Oxygen::AnimationTypes)
 
220
 
 
221
}
 
222
 
 
223
#endif