1#ifndef oxygenblurhelper_h
2#define oxygenblurhelper_h
3
4//////////////////////////////////////////////////////////////////////////////
5// oxygenblurhelper.h
6// handle regions passed to kwin for blurring
7// -------------------
8//
9// Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
10//
11// Loosely inspired (and largely rewritten) from BeSpin style
12// Copyright (C) 2007 Thomas Luebking <thomas.luebking@web.de>
13//
14// Permission is hereby granted, free of charge, to any person obtaining a copy
15// of this software and associated documentation files (the "Software"), to
16// deal in the Software without restriction, including without limitation the
17// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18// sell copies of the Software, and to permit persons to whom the Software is
19// furnished to do so, subject to the following conditions:
20//
21// The above copyright notice and this permission notice shall be included in
22// all copies or substantial portions of the Software.
23//
24// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30// IN THE SOFTWARE.
31//////////////////////////////////////////////////////////////////////////////
32
33#include "oxygenstylehelper.h"
34
35#include <QtCore/QBasicTimer>
36#include <QtCore/QHash>
37#include <QtCore/QObject>
38#include <QtCore/QPointer>
39#include <QtCore/QSet>
40#include <QtCore/QTimerEvent>
41
42#include <QtGui/QDockWidget>
43#include <QtGui/QMenu>
44#include <QtGui/QRegion>
45#include <QtGui/QToolBar>
46
47#ifdef Q_WS_X11
48#include <X11/Xdefs.h>
49#endif
50
51namespace Oxygen
52{
53 class BlurHelper: public QObject
54 {
55
56 Q_OBJECT
57
58 public:
59
60 //! constructor
61 BlurHelper( QObject*, StyleHelper& );
62
63 //! destructor
64 virtual ~BlurHelper( void )
65 {}
66
67 //! enable state
68 void setEnabled( bool value )
69 { _enabled = value; }
70
71 //! enabled
72 bool enabled( void ) const
73 { return _enabled; }
74
75 //! register widget
76 void registerWidget( QWidget* );
77
78 //! register widget
79 void unregisterWidget( QWidget* );
80
81 //! event filter
82 virtual bool eventFilter( QObject*, QEvent* );
83
84 protected:
85
86 //! timer event
87 /*! used to perform delayed blur region update of pending widgets */
88 virtual void timerEvent( QTimerEvent* event )
89 {
90
91 if( event->timerId() == _timer.timerId() )
92 {
93 _timer.stop();
94 update();
95 } else QObject::timerEvent( event );
96
97 }
98
99 //! install event filter to object, in a unique way
100 void addEventFilter( QObject* object )
101 {
102 object->removeEventFilter( this );
103 object->installEventFilter( this );
104 }
105
106 //! get list of blur-behind regions matching a given widget
107 QRegion blurRegion( QWidget* ) const;
108
109 //! trim blur region to remove unnecessary areas (recursive)
110 void trimBlurRegion( QWidget*, QWidget*, QRegion& ) const;
111
112 //! update blur region for all pending widgets
113 void update( void )
114 {
115
116 foreach( const WidgetPointer& widget, _pendingWidgets )
117 { if( widget ) update( widget.data() ); }
118
119 _pendingWidgets.clear();
120
121 }
122
123 //! update blur regions for given widget
124 void update( QWidget* ) const;
125
126 //! clear blur regions for given widget
127 void clear( QWidget* ) const;
128
129 //! returns true if a given widget is opaque
130 bool isOpaque( const QWidget* widget ) const;
131
132 //! true if widget is a transparent window
133 /*! some additional checks are performed to make sure stuff like plasma tooltips
134 don't get their blur region overwritten */
135 bool isTransparent( const QWidget* widget ) const;
136
137 protected slots:
138
139 //! wiget destroyed
140 void widgetDestroyed( QObject* object )
141 { _widgets.remove( object ); }
142
143 private:
144
145 //! helper
146 StyleHelper& _helper;
147
148 //! enability
149 bool _enabled;
150
151 //! list of widgets for which blur region must be updated
152 typedef QPointer<QWidget> WidgetPointer;
153 typedef QHash<QWidget*, WidgetPointer> WidgetSet;
154 WidgetSet _pendingWidgets;
155
156 //! set of registered widgets
157 QSet<const QObject*> _widgets;
158
159 //! delayed update timer
160 QBasicTimer _timer;
161
162 #ifdef Q_WS_X11
163 //! blur atom
164 Atom _blurAtom;
165 Atom _opaqueAtom;
166 #endif
167
168 };
169
170}
171
172#endif
173