1 | /******************************************************************** |
2 | KWin - the KDE window manager |
3 | This file is part of the KDE project. |
4 | |
5 | Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de> |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | *********************************************************************/ |
20 | |
21 | #ifndef KWIN_OUTLINE_H |
22 | #define KWIN_OUTLINE_H |
23 | #include "xcbutils.h" |
24 | #include <kwinglobals.h> |
25 | #include <QRect> |
26 | #include <QWidget> |
27 | |
28 | namespace Plasma { |
29 | class FrameSvg; |
30 | } |
31 | |
32 | namespace KWin { |
33 | class OutlineVisual; |
34 | |
35 | /** |
36 | * @short This class is used to show the outline of a given geometry. |
37 | * |
38 | * The class renders an outline by using four windows. One for each border of |
39 | * the geometry. It is possible to replace the outline with an effect. If an |
40 | * effect is available the effect will be used, otherwise the outline will be |
41 | * rendered by using the X implementation. |
42 | * |
43 | * @author Arthur Arlt |
44 | * @since 4.7 |
45 | */ |
46 | class Outline : public QObject { |
47 | Q_OBJECT |
48 | public: |
49 | ~Outline(); |
50 | |
51 | /** |
52 | * Set the outline geometry. |
53 | * To show the outline use @link showOutline. |
54 | * @param outlineGeometry The geometry of the outline to be shown |
55 | * @see showOutline |
56 | */ |
57 | void setGeometry(const QRect &outlineGeometry); |
58 | |
59 | /** |
60 | * Shows the outline of a window using either an effect or the X implementation. |
61 | * To stop the outline process use @link hideOutline. |
62 | * @see hideOutline |
63 | */ |
64 | void show(); |
65 | |
66 | /** |
67 | * Shows the outline for the given @p outlineGeometry. |
68 | * This is the same as setOutlineGeometry followed by showOutline directly. |
69 | * To stop the outline process use @link hideOutline. |
70 | * @param outlineGeometry The geometry of the outline to be shown |
71 | * @see hideOutline |
72 | */ |
73 | void show(const QRect &outlineGeometry); |
74 | |
75 | /** |
76 | * Hides shown outline. |
77 | * @see showOutline |
78 | */ |
79 | void hide(); |
80 | |
81 | const QRect &geometry() const; |
82 | |
83 | private Q_SLOTS: |
84 | void compositingChanged(); |
85 | |
86 | private: |
87 | void createHelper(); |
88 | QScopedPointer<OutlineVisual> m_visual; |
89 | QRect m_outlineGeometry; |
90 | bool m_active; |
91 | KWIN_SINGLETON(Outline) |
92 | }; |
93 | |
94 | class OutlineVisual |
95 | { |
96 | public: |
97 | OutlineVisual(Outline *outline); |
98 | virtual ~OutlineVisual(); |
99 | virtual void show() = 0; |
100 | virtual void hide() = 0; |
101 | protected: |
102 | Outline *outline(); |
103 | const Outline *outline() const; |
104 | private: |
105 | Outline *m_outline; |
106 | }; |
107 | |
108 | class CompositedOutlineVisual : public QWidget, public OutlineVisual |
109 | { |
110 | public: |
111 | CompositedOutlineVisual(Outline *outline); |
112 | virtual ~CompositedOutlineVisual(); |
113 | virtual void show(); |
114 | virtual void hide(); |
115 | protected: |
116 | virtual void paintEvent(QPaintEvent *); |
117 | private: |
118 | Plasma::FrameSvg *m_background; |
119 | }; |
120 | |
121 | class NonCompositedOutlineVisual : public OutlineVisual |
122 | { |
123 | public: |
124 | NonCompositedOutlineVisual(Outline *outline); |
125 | virtual ~NonCompositedOutlineVisual(); |
126 | virtual void show(); |
127 | virtual void hide(); |
128 | |
129 | private: |
130 | // TODO: variadic template arguments for adding method arguments |
131 | template <typename T> |
132 | void forEachWindow(T method); |
133 | bool m_initialized; |
134 | Xcb::Window m_topOutline; |
135 | Xcb::Window m_rightOutline; |
136 | Xcb::Window m_bottomOutline; |
137 | Xcb::Window m_leftOutline; |
138 | }; |
139 | |
140 | inline |
141 | const QRect &Outline::geometry() const |
142 | { |
143 | return m_outlineGeometry; |
144 | } |
145 | |
146 | inline |
147 | Outline *OutlineVisual::outline() |
148 | { |
149 | return m_outline; |
150 | } |
151 | |
152 | inline |
153 | const Outline *OutlineVisual::outline() const |
154 | { |
155 | return m_outline; |
156 | } |
157 | |
158 | template <typename T> |
159 | inline |
160 | void NonCompositedOutlineVisual::forEachWindow(T method) |
161 | { |
162 | (m_topOutline.*method)(); |
163 | (m_rightOutline.*method)(); |
164 | (m_bottomOutline.*method)(); |
165 | (m_leftOutline.*method)(); |
166 | } |
167 | |
168 | inline |
169 | Outline *outline() |
170 | { |
171 | return Outline::self(); |
172 | } |
173 | |
174 | } |
175 | |
176 | #endif |
177 | |