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

« back to all changes in this revision

Viewing changes to kwin/clients/oxygen/oxygenclient.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 oxygenclient_h
 
2
#define oxygenclient_h
 
3
 
 
4
//////////////////////////////////////////////////////////////////////////////
 
5
// oxygenclient.h
 
6
// -------------------
 
7
//
 
8
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
9
// Copyright (c) 2003, 2004 David Johnson <david@usermode.org>
 
10
// Copyright (c) 2006, 2007 Riccardo Iaconelli <ruphy@fsfe.org>
 
11
//
 
12
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
13
// of this software and associated documentation files (the "Software"), to
 
14
// deal in the Software without restriction, including without limitation the
 
15
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
16
// sell copies of the Software, and to permit persons to whom the Software is
 
17
// furnished to do so, subject to the following conditions:
 
18
//
 
19
// The above copyright notice and this permission notice shall be included in
 
20
// all copies or substantial portions of the Software.
 
21
//
 
22
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
23
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
24
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
25
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
26
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
27
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
28
// IN THE SOFTWARE.
 
29
//////////////////////////////////////////////////////////////////////////////
 
30
 
 
31
#include "oxygenanimation.h"
 
32
#include "oxygenclientgroupitemdata.h"
 
33
#include "oxygenconfiguration.h"
 
34
#include "oxygendecohelper.h"
 
35
#include "oxygenfactory.h"
 
36
#include "oxygenshadowcache.h"
 
37
#include "oxygentitleanimationdata.h"
 
38
 
 
39
#include <kcommondecoration.h>
 
40
#include <QtCore/QBasicTimer>
 
41
#include <QtCore/QTextStream>
 
42
#include <QtCore/QTimerEvent>
 
43
 
 
44
#include <X11/Xdefs.h>
 
45
 
 
46
namespace Oxygen
 
47
{
 
48
 
 
49
    class SizeGrip;
 
50
    class Client : public KCommonDecorationUnstable
 
51
    {
 
52
 
 
53
        Q_OBJECT
 
54
 
 
55
        //! declare glow intensity property
 
56
        Q_PROPERTY( qreal glowIntensity READ glowIntensityUnbiased WRITE setGlowIntensity )
 
57
 
 
58
        public:
 
59
 
 
60
        //! constructor
 
61
        Client(KDecorationBridge *b, Factory *f);
 
62
 
 
63
        //! destructor
 
64
        virtual ~Client();
 
65
 
 
66
        //! decoration name
 
67
        virtual QString visibleName() const;
 
68
 
 
69
        //! buttons
 
70
        virtual KCommonDecorationButton *createButton(::ButtonType type);
 
71
 
 
72
        //!@name flags
 
73
        //@{
 
74
 
 
75
        //! true if decoration has iquired behavior
 
76
        virtual bool decorationBehaviour(DecorationBehaviour behaviour) const;
 
77
 
 
78
        //! true if window is maximized
 
79
        virtual bool isMaximized( void ) const
 
80
        { return maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows();  }
 
81
 
 
82
 
 
83
        //! true if animations are used
 
84
        bool useAnimations( void ) const
 
85
        { return configuration().useAnimations(); }
 
86
 
 
87
        //! true if glow is animated
 
88
        bool glowIsAnimated( void ) const
 
89
        { return _glowAnimation->isRunning(); }
 
90
 
 
91
        //! true when decoration is forced active
 
92
        bool isForcedActive( void ) const
 
93
        { return _forceActive && clientGroupItems().count() > 1; }
 
94
 
 
95
        //! true when separator is to be drawn
 
96
        bool drawSeparator( void ) const
 
97
        {
 
98
            if( configuration().drawTitleOutline() ) return false;
 
99
            switch( configuration().separatorMode() )
 
100
            {
 
101
                case Configuration::SeparatorAlways:
 
102
                return true;
 
103
 
 
104
                case Configuration::SeparatorActive:
 
105
                return ( glowIsAnimated() || isActive() );
 
106
 
 
107
                default:
 
108
                case Configuration::SeparatorNever:
 
109
                return false;
 
110
            }
 
111
 
 
112
        }
 
113
 
 
114
        //! true if titlebar is hidden
 
115
        bool hideTitleBar( void ) const
 
116
        {
 
117
            return
 
118
                configuration().hideTitleBar() &&
 
119
                !isShade() &&
 
120
                clientGroupItems().count() == 1;
 
121
        }
 
122
 
 
123
        //@}
 
124
 
 
125
        //! window shape
 
126
        virtual void updateWindowShape();
 
127
 
 
128
        //! initialization
 
129
        virtual void init();
 
130
 
 
131
        // reset
 
132
        virtual void reset( unsigned long changed );
 
133
 
 
134
        //! return associated configuration
 
135
        const Configuration& configuration( void ) const
 
136
        { return _configuration; }
 
137
 
 
138
        //!@name glow animation
 
139
        //@{
 
140
 
 
141
        void setGlowIntensity( qreal value )
 
142
        {
 
143
            if( _glowIntensity == value ) return;
 
144
            _glowIntensity = value;
 
145
            widget()->update();
 
146
        }
 
147
 
 
148
        //! unbiased glow intensity
 
149
        qreal glowIntensityUnbiased( void ) const
 
150
        { return _glowIntensity; }
 
151
 
 
152
        //! glow bias
 
153
        static qreal glowBias( void )
 
154
        { return 0.2; }
 
155
 
 
156
        //! true (biased) intensity
 
157
        /*! this is needed to have glow go from either 0.2->1 or 0.8->0 depending on the animation direction */
 
158
        qreal glowIntensity( void ) const
 
159
        { return _glowAnimation->direction() == Animation::Forward ? _glowIntensity : _glowIntensity-glowBias(); }
 
160
 
 
161
        //@}
 
162
 
 
163
        //! helper class
 
164
        DecoHelper& helper( void ) const
 
165
        { return _factory->helper(); }
 
166
 
 
167
        //! helper class
 
168
        ShadowCache& shadowCache( void ) const
 
169
        { return _factory->shadowCache(); }
 
170
 
 
171
        //!@name metrics and color definitions
 
172
        //@{
 
173
 
 
174
        //! dimensions
 
175
        virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton * = 0) const;
 
176
 
 
177
        //! get title rect for untabbed window
 
178
        virtual QRect defaultTitleRect( bool active = true ) const;
 
179
 
 
180
        //! get title bounding rect
 
181
        virtual QRect titleBoundingRect( const QFont& font, const QString& caption ) const
 
182
        { return titleBoundingRect( font, titleRect(), caption ); }
 
183
 
 
184
        //! get title bounding rect
 
185
        virtual QRect titleBoundingRect( const QFont&, QRect, const QString& ) const;
 
186
 
 
187
        //! palette background
 
188
        QPalette backgroundPalette( const QWidget*, QPalette ) const;
 
189
 
 
190
        //! background
 
191
        QColor backgroundColor( const QWidget* widget, QPalette palette ) const
 
192
        { return backgroundColor( widget, palette, isActive() || isForcedActive() ); }
 
193
 
 
194
        //! background
 
195
        QColor backgroundColor( const QWidget*, QPalette, bool ) const;
 
196
 
 
197
        //@}
 
198
 
 
199
        //! default buttons located on the left
 
200
        virtual QString defaultButtonsLeft() const;
 
201
 
 
202
        //! default buttons located on the right
 
203
        virtual QString defaultButtonsRight() const;
 
204
 
 
205
        //!@name status change methods (overloaded from KCommonDecorationUnstable)
 
206
        //@{
 
207
 
 
208
        //! triggered when window activity is changed
 
209
        virtual void activeChange();
 
210
 
 
211
        //! triggered when maximize state changed
 
212
        virtual void maximizeChange();
 
213
 
 
214
        //! triggered when window shade is changed
 
215
        virtual void shadeChange();
 
216
 
 
217
        //! triggered when window shade is changed
 
218
        virtual void captionChange();
 
219
 
 
220
        //@}
 
221
 
 
222
        //! event filter
 
223
        virtual bool eventFilter( QObject*, QEvent* );
 
224
 
 
225
        //! resize event
 
226
        virtual void resizeEvent(QResizeEvent *e);
 
227
 
 
228
        public slots:
 
229
 
 
230
        //! triggers widget update in titleRect only
 
231
        /*! one needs to add the title top margin to avoid some clipping glitches */
 
232
        void updateTitleRect( void )
 
233
        { widget()->update( titleRect().adjusted( 0, -layoutMetric( LM_TitleEdgeTop ), 0, 1 ) ); }
 
234
 
 
235
        protected:
 
236
 
 
237
        //! return shadow cache key associated to this client
 
238
        ShadowCache::Key key( void ) const
 
239
        {
 
240
            ShadowCache::Key key;
 
241
            key.active = ( isActive() || isForcedActive() ) && configuration().useOxygenShadows();
 
242
            key.isShade = isShade();
 
243
            key.hasBorder = ( configuration().frameBorder() > Configuration::BorderNone );
 
244
            return key;
 
245
        }
 
246
 
 
247
        //! true when decoration is forced active
 
248
        void setForceActive( bool value )
 
249
        { _forceActive = value; }
 
250
 
 
251
        //!@name event filters
 
252
        //@{
 
253
 
 
254
        //! paint
 
255
        virtual void paintEvent( QPaintEvent* );
 
256
 
 
257
        //! mouse press event
 
258
        virtual bool mousePressEvent( QMouseEvent* );
 
259
 
 
260
        //! mouse release event
 
261
        virtual bool mouseReleaseEvent( QMouseEvent* );
 
262
 
 
263
        //! mouse move event
 
264
        virtual bool mouseMoveEvent( QMouseEvent* );
 
265
 
 
266
        //! drag enter event
 
267
        virtual bool dragEnterEvent( QDragEnterEvent* );
 
268
 
 
269
        //! drag move event
 
270
        virtual bool dragMoveEvent( QDragMoveEvent* );
 
271
 
 
272
        //! drag leave event
 
273
        virtual bool dragLeaveEvent( QDragLeaveEvent* );
 
274
 
 
275
        //! drop event
 
276
        virtual bool dropEvent( QDropEvent* );
 
277
 
 
278
        //! timer event
 
279
        virtual void timerEvent( QTimerEvent* );
 
280
 
 
281
        //@}
 
282
 
 
283
        //!@name rendering methods (called in paintEvent)
 
284
        //@{
 
285
 
 
286
        //! window background
 
287
        virtual void renderWindowBackground( QPainter*, const QRect&, const QWidget*, const QPalette& ) const;
 
288
 
 
289
        //! window border
 
290
        // this draws a "blue" border around active window
 
291
        virtual void renderWindowBorder( QPainter*, const QRect&, const QWidget*, const QPalette& ) const;
 
292
 
 
293
        //! separator
 
294
        virtual void renderSeparator( QPainter*, const QRect&, const QWidget*, const QColor& ) const;
 
295
 
 
296
        //! title outline
 
297
        virtual void renderTitleOutline( QPainter*, const QRect&, const QPalette& ) const;
 
298
 
 
299
        //! title text
 
300
        /*! second color, if valid, is for contrast pixel */
 
301
        virtual void renderTitleText( QPainter*, const QRect&, const QColor&, const QColor& = QColor() ) const;
 
302
 
 
303
        //! title text
 
304
        /*! second color, if valid, is for contrast pixel */
 
305
        virtual void renderTitleText( QPainter*, const QRect&, const QString&, const QColor&, const QColor& = QColor(), bool elide = true ) const;
 
306
 
 
307
        //! title text
 
308
        virtual QPixmap renderTitleText( const QRect&, const QString&, const QColor&, bool elide = true ) const;
 
309
 
 
310
        //! GroupItem
 
311
        virtual void renderItem( QPainter*, int, const QPalette& );
 
312
 
 
313
        //! tabbing target rect
 
314
        virtual void renderTargetRect( QPainter*, const QPalette& );
 
315
 
 
316
        //! render corners
 
317
        virtual void renderCorners( QPainter*, const QRect&, const QPalette& ) const;
 
318
 
 
319
        //! render float frame
 
320
        virtual void renderFloatFrame( QPainter*, const QRect&, const QPalette& ) const;
 
321
 
 
322
        //! render dots
 
323
        virtual void renderDots( QPainter*, const QRect&, const QColor& ) const;
 
324
 
 
325
        //@}
 
326
 
 
327
        //! close tab matching give button
 
328
        virtual bool closeItem( const Button* );
 
329
 
 
330
        //! index of item matching point
 
331
        int itemClicked( const QPoint& position, bool between = false ) const
 
332
        { return _itemData.itemAt( position , between ); }
 
333
 
 
334
        //! return pixmap corresponding to a given tab, for dragging
 
335
        QPixmap itemDragPixmap( int, const QRect& );
 
336
 
 
337
        //! return true when activity change are animated
 
338
        bool animateActiveChange( void ) const
 
339
        { return ( useAnimations() && !isPreview() ); }
 
340
 
 
341
        //! return true when activity change are animated
 
342
        bool animateTitleChange( void ) const
 
343
        {
 
344
            return
 
345
                useAnimations() &&
 
346
                configuration().animateTitleChange() &&
 
347
                !configuration().drawTitleOutline() &&
 
348
                !hideTitleBar() &&
 
349
                !isPreview();
 
350
        }
 
351
 
 
352
        //! true if some title outline is rendered
 
353
        bool hasTitleOutline( void ) const
 
354
        {
 
355
            return
 
356
                clientGroupItems().count() >= 2 ||
 
357
                _itemData.isAnimated() ||
 
358
                ( isActive() && configuration().drawTitleOutline() );
 
359
        }
 
360
 
 
361
        //! calculate mask
 
362
        QRegion calcMask( void ) const;
 
363
 
 
364
        //! text color
 
365
        QColor titlebarTextColor(const QPalette&) const;
 
366
 
 
367
        //! text color
 
368
        QColor titlebarTextColor(const QPalette& palette, bool active) const
 
369
        {
 
370
            return active ?
 
371
                palette.color(QPalette::Active, QPalette::WindowText):
 
372
                helper().inactiveTitleBarTextColor( palette );
 
373
        }
 
374
 
 
375
        //! text color
 
376
        QColor titlebarContrastColor(const QPalette& palette ) const
 
377
        { return titlebarContrastColor( palette.color( widget()->window()->backgroundRole() ) ); }
 
378
 
 
379
        //! text color
 
380
        QColor titlebarContrastColor(const QColor& color ) const
 
381
        { return helper().calcLightColor( color ); }
 
382
 
 
383
        //!@name size grip
 
384
        //@{
 
385
 
 
386
        //! create size grip
 
387
        void createSizeGrip( void );
 
388
 
 
389
        //! delete size grip
 
390
        void deleteSizeGrip( void );
 
391
 
 
392
        // size grip
 
393
        bool hasSizeGrip( void ) const
 
394
        { return (bool)_sizeGrip; }
 
395
 
 
396
        //! size grip
 
397
        SizeGrip& sizeGrip( void ) const
 
398
        { return *_sizeGrip; }
 
399
 
 
400
        //@}
 
401
 
 
402
        //! remove shadow hint
 
403
        void removeShadowHint( void );
 
404
 
 
405
        protected slots:
 
406
 
 
407
        //! set target item to -1
 
408
        void clearTargetItem( void );
 
409
 
 
410
        //! clear force active flag
 
411
        void clearForceActive( void )
 
412
        { if( isActive() ) setForceActive( false ); }
 
413
 
 
414
        //! title bounding rects
 
415
        /*! calculate and return title bounding rects in case of tabbed window */
 
416
        void updateItemBoundingRects( bool alsoUpdate = true );
 
417
 
 
418
        //! bound one rect to another
 
419
        void boundRectTo( QRect&, const QRect& ) const;
 
420
 
 
421
        private:
 
422
 
 
423
        //! factory
 
424
        Factory* _factory;
 
425
 
 
426
        //! size grip widget
 
427
        SizeGrip* _sizeGrip;
 
428
 
 
429
        //! configuration
 
430
        Configuration _configuration;
 
431
 
 
432
        //! glow animation
 
433
        Animation* _glowAnimation;
 
434
 
 
435
        //! title animation data
 
436
        TitleAnimationData* _titleAnimationData;
 
437
 
 
438
        //! glow intensity
 
439
        qreal _glowIntensity;
 
440
 
 
441
        //! true when initialized
 
442
        bool _initialized;
 
443
 
 
444
        //! true when decoration is forced active
 
445
        bool _forceActive;
 
446
 
 
447
        //! mouse button
 
448
        Qt::MouseButton _mouseButton;
 
449
 
 
450
        //! tab bounding rects
 
451
        ClientGroupItemDataList _itemData;
 
452
 
 
453
        //! index of tab being dragged if any, -1 otherwise
 
454
        int _sourceItem;
 
455
 
 
456
        //! drag start point
 
457
        QPoint _dragPoint;
 
458
 
 
459
        //! drag start timer.
 
460
        /*!
 
461
        it is needed to activate animations when this was not done via either
 
462
        dragMoveEvent or dragLeaveEvent
 
463
        */
 
464
        QBasicTimer _dragStartTimer;
 
465
 
 
466
        //! shadow atom
 
467
        Atom _shadowAtom;
 
468
 
 
469
    };
 
470
 
 
471
} // namespace Oxygen
 
472
 
 
473
#endif // EXAMPLECLIENT_H