1/********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
28namespace Plasma {
29class FrameSvg;
30}
31
32namespace KWin {
33class 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 */
46class Outline : public QObject {
47 Q_OBJECT
48public:
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
83private Q_SLOTS:
84 void compositingChanged();
85
86private:
87 void createHelper();
88 QScopedPointer<OutlineVisual> m_visual;
89 QRect m_outlineGeometry;
90 bool m_active;
91 KWIN_SINGLETON(Outline)
92};
93
94class OutlineVisual
95{
96public:
97 OutlineVisual(Outline *outline);
98 virtual ~OutlineVisual();
99 virtual void show() = 0;
100 virtual void hide() = 0;
101protected:
102 Outline *outline();
103 const Outline *outline() const;
104private:
105 Outline *m_outline;
106};
107
108class CompositedOutlineVisual : public QWidget, public OutlineVisual
109{
110public:
111 CompositedOutlineVisual(Outline *outline);
112 virtual ~CompositedOutlineVisual();
113 virtual void show();
114 virtual void hide();
115protected:
116 virtual void paintEvent(QPaintEvent *);
117private:
118 Plasma::FrameSvg *m_background;
119};
120
121class NonCompositedOutlineVisual : public OutlineVisual
122{
123public:
124 NonCompositedOutlineVisual(Outline *outline);
125 virtual ~NonCompositedOutlineVisual();
126 virtual void show();
127 virtual void hide();
128
129private:
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
140inline
141const QRect &Outline::geometry() const
142{
143 return m_outlineGeometry;
144}
145
146inline
147Outline *OutlineVisual::outline()
148{
149 return m_outline;
150}
151
152inline
153const Outline *OutlineVisual::outline() const
154{
155 return m_outline;
156}
157
158template <typename T>
159inline
160void NonCompositedOutlineVisual::forEachWindow(T method)
161{
162 (m_topOutline.*method)();
163 (m_rightOutline.*method)();
164 (m_bottomOutline.*method)();
165 (m_leftOutline.*method)();
166}
167
168inline
169Outline *outline()
170{
171 return Outline::self();
172}
173
174}
175
176#endif
177