4
//////////////////////////////////////////////////////////////////////////////
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>
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:
19
// The above copyright notice and this permission notice shall be included in
20
// all copies or substantial portions of the Software.
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
29
//////////////////////////////////////////////////////////////////////////////
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"
39
#include <kcommondecoration.h>
40
#include <QtCore/QBasicTimer>
41
#include <QtCore/QTextStream>
42
#include <QtCore/QTimerEvent>
44
#include <X11/Xdefs.h>
50
class Client : public KCommonDecorationUnstable
55
//! declare glow intensity property
56
Q_PROPERTY( qreal glowIntensity READ glowIntensityUnbiased WRITE setGlowIntensity )
61
Client(KDecorationBridge *b, Factory *f);
67
virtual QString visibleName() const;
70
virtual KCommonDecorationButton *createButton(::ButtonType type);
75
//! true if decoration has iquired behavior
76
virtual bool decorationBehaviour(DecorationBehaviour behaviour) const;
78
//! true if window is maximized
79
virtual bool isMaximized( void ) const
80
{ return maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows(); }
83
//! true if animations are used
84
bool useAnimations( void ) const
85
{ return configuration().useAnimations(); }
87
//! true if glow is animated
88
bool glowIsAnimated( void ) const
89
{ return _glowAnimation->isRunning(); }
91
//! true when decoration is forced active
92
bool isForcedActive( void ) const
93
{ return _forceActive && clientGroupItems().count() > 1; }
95
//! true when separator is to be drawn
96
bool drawSeparator( void ) const
98
if( configuration().drawTitleOutline() ) return false;
99
switch( configuration().separatorMode() )
101
case Configuration::SeparatorAlways:
104
case Configuration::SeparatorActive:
105
return ( glowIsAnimated() || isActive() );
108
case Configuration::SeparatorNever:
114
//! true if titlebar is hidden
115
bool hideTitleBar( void ) const
118
configuration().hideTitleBar() &&
120
clientGroupItems().count() == 1;
126
virtual void updateWindowShape();
132
virtual void reset( unsigned long changed );
134
//! return associated configuration
135
const Configuration& configuration( void ) const
136
{ return _configuration; }
138
//!@name glow animation
141
void setGlowIntensity( qreal value )
143
if( _glowIntensity == value ) return;
144
_glowIntensity = value;
148
//! unbiased glow intensity
149
qreal glowIntensityUnbiased( void ) const
150
{ return _glowIntensity; }
153
static qreal glowBias( void )
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(); }
164
DecoHelper& helper( void ) const
165
{ return _factory->helper(); }
168
ShadowCache& shadowCache( void ) const
169
{ return _factory->shadowCache(); }
171
//!@name metrics and color definitions
175
virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton * = 0) const;
177
//! get title rect for untabbed window
178
virtual QRect defaultTitleRect( bool active = true ) const;
180
//! get title bounding rect
181
virtual QRect titleBoundingRect( const QFont& font, const QString& caption ) const
182
{ return titleBoundingRect( font, titleRect(), caption ); }
184
//! get title bounding rect
185
virtual QRect titleBoundingRect( const QFont&, QRect, const QString& ) const;
187
//! palette background
188
QPalette backgroundPalette( const QWidget*, QPalette ) const;
191
QColor backgroundColor( const QWidget* widget, QPalette palette ) const
192
{ return backgroundColor( widget, palette, isActive() || isForcedActive() ); }
195
QColor backgroundColor( const QWidget*, QPalette, bool ) const;
199
//! default buttons located on the left
200
virtual QString defaultButtonsLeft() const;
202
//! default buttons located on the right
203
virtual QString defaultButtonsRight() const;
205
//!@name status change methods (overloaded from KCommonDecorationUnstable)
208
//! triggered when window activity is changed
209
virtual void activeChange();
211
//! triggered when maximize state changed
212
virtual void maximizeChange();
214
//! triggered when window shade is changed
215
virtual void shadeChange();
217
//! triggered when window shade is changed
218
virtual void captionChange();
223
virtual bool eventFilter( QObject*, QEvent* );
226
virtual void resizeEvent(QResizeEvent *e);
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 ) ); }
237
//! return shadow cache key associated to this client
238
ShadowCache::Key key( void ) const
240
ShadowCache::Key key;
241
key.active = ( isActive() || isForcedActive() ) && configuration().useOxygenShadows();
242
key.isShade = isShade();
243
key.hasBorder = ( configuration().frameBorder() > Configuration::BorderNone );
247
//! true when decoration is forced active
248
void setForceActive( bool value )
249
{ _forceActive = value; }
251
//!@name event filters
255
virtual void paintEvent( QPaintEvent* );
257
//! mouse press event
258
virtual bool mousePressEvent( QMouseEvent* );
260
//! mouse release event
261
virtual bool mouseReleaseEvent( QMouseEvent* );
264
virtual bool mouseMoveEvent( QMouseEvent* );
267
virtual bool dragEnterEvent( QDragEnterEvent* );
270
virtual bool dragMoveEvent( QDragMoveEvent* );
273
virtual bool dragLeaveEvent( QDragLeaveEvent* );
276
virtual bool dropEvent( QDropEvent* );
279
virtual void timerEvent( QTimerEvent* );
283
//!@name rendering methods (called in paintEvent)
286
//! window background
287
virtual void renderWindowBackground( QPainter*, const QRect&, const QWidget*, const QPalette& ) const;
290
// this draws a "blue" border around active window
291
virtual void renderWindowBorder( QPainter*, const QRect&, const QWidget*, const QPalette& ) const;
294
virtual void renderSeparator( QPainter*, const QRect&, const QWidget*, const QColor& ) const;
297
virtual void renderTitleOutline( QPainter*, const QRect&, const QPalette& ) const;
300
/*! second color, if valid, is for contrast pixel */
301
virtual void renderTitleText( QPainter*, const QRect&, const QColor&, const QColor& = QColor() ) const;
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;
308
virtual QPixmap renderTitleText( const QRect&, const QString&, const QColor&, bool elide = true ) const;
311
virtual void renderItem( QPainter*, int, const QPalette& );
313
//! tabbing target rect
314
virtual void renderTargetRect( QPainter*, const QPalette& );
317
virtual void renderCorners( QPainter*, const QRect&, const QPalette& ) const;
319
//! render float frame
320
virtual void renderFloatFrame( QPainter*, const QRect&, const QPalette& ) const;
323
virtual void renderDots( QPainter*, const QRect&, const QColor& ) const;
327
//! close tab matching give button
328
virtual bool closeItem( const Button* );
330
//! index of item matching point
331
int itemClicked( const QPoint& position, bool between = false ) const
332
{ return _itemData.itemAt( position , between ); }
334
//! return pixmap corresponding to a given tab, for dragging
335
QPixmap itemDragPixmap( int, const QRect& );
337
//! return true when activity change are animated
338
bool animateActiveChange( void ) const
339
{ return ( useAnimations() && !isPreview() ); }
341
//! return true when activity change are animated
342
bool animateTitleChange( void ) const
346
configuration().animateTitleChange() &&
347
!configuration().drawTitleOutline() &&
352
//! true if some title outline is rendered
353
bool hasTitleOutline( void ) const
356
clientGroupItems().count() >= 2 ||
357
_itemData.isAnimated() ||
358
( isActive() && configuration().drawTitleOutline() );
362
QRegion calcMask( void ) const;
365
QColor titlebarTextColor(const QPalette&) const;
368
QColor titlebarTextColor(const QPalette& palette, bool active) const
371
palette.color(QPalette::Active, QPalette::WindowText):
372
helper().inactiveTitleBarTextColor( palette );
376
QColor titlebarContrastColor(const QPalette& palette ) const
377
{ return titlebarContrastColor( palette.color( widget()->window()->backgroundRole() ) ); }
380
QColor titlebarContrastColor(const QColor& color ) const
381
{ return helper().calcLightColor( color ); }
387
void createSizeGrip( void );
390
void deleteSizeGrip( void );
393
bool hasSizeGrip( void ) const
394
{ return (bool)_sizeGrip; }
397
SizeGrip& sizeGrip( void ) const
398
{ return *_sizeGrip; }
402
//! remove shadow hint
403
void removeShadowHint( void );
407
//! set target item to -1
408
void clearTargetItem( void );
410
//! clear force active flag
411
void clearForceActive( void )
412
{ if( isActive() ) setForceActive( false ); }
414
//! title bounding rects
415
/*! calculate and return title bounding rects in case of tabbed window */
416
void updateItemBoundingRects( bool alsoUpdate = true );
418
//! bound one rect to another
419
void boundRectTo( QRect&, const QRect& ) const;
430
Configuration _configuration;
433
Animation* _glowAnimation;
435
//! title animation data
436
TitleAnimationData* _titleAnimationData;
439
qreal _glowIntensity;
441
//! true when initialized
444
//! true when decoration is forced active
448
Qt::MouseButton _mouseButton;
450
//! tab bounding rects
451
ClientGroupItemDataList _itemData;
453
//! index of tab being dragged if any, -1 otherwise
459
//! drag start timer.
461
it is needed to activate animations when this was not done via either
462
dragMoveEvent or dragLeaveEvent
464
QBasicTimer _dragStartTimer;
471
} // namespace Oxygen
473
#endif // EXAMPLECLIENT_H