KDecoration3

decoratedwindow.h
1/*
2 * SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6#pragma once
7
8#include "decoration.h"
9#include "decorationdefines.h"
10#include <kdecoration3/kdecoration3_export.h>
11
12#include <QFont>
13#include <QIcon>
14#include <QObject>
15#include <QPalette>
16#include <QPointer>
17#include <QtGui/qwindowdefs.h>
18
19#include <memory>
20
21namespace KDecoration3
22{
23class DecorationBridge;
24class DecoratedWindowPrivate;
25
26/**
27 * @brief The Client which gets decorated.
28 *
29 * The DecoratedWindow provides access to all the properties relevant for decorating the Client.
30 * Each DecoratedWindow is bound to one Decoration and each Decoration is bound to this one
31 * DecoratedWindow.
32 *
33 * The DecoratedWindow only exports properties, it does not provide any means to change the state.
34 * To change state one needs to call the methods on Decoration. This is as the backend might
35 * disallow state changes. Therefore any changes should be bound to the change signals of the
36 * DecoratedWindow and not be bound to state changes of input elements (such as a button).
37 */
38class KDECORATIONS3_EXPORT DecoratedWindow : public QObject
39{
40 Q_OBJECT
41 /**
42 * The Decoration of this DecoratedWindow
43 **/
44 Q_PROPERTY(KDecoration3::Decoration *decoration READ decoration CONSTANT)
45 /**
46 * Whether the DecoratedWindow is active (has focus) or is inactive.
47 **/
48 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
49 /**
50 * The caption of the DecoratedWindow.
51 **/
52 Q_PROPERTY(QString caption READ caption NOTIFY captionChanged)
53 /**
54 * Whether the DecoratedWindow is on all desktops or on just one.
55 **/
56 Q_PROPERTY(bool onAllDesktops READ isOnAllDesktops NOTIFY onAllDesktopsChanged)
57 /**
58 * Whether the DecoratedWindow is shaded. Shaded means that the actual content is
59 * not visible, only the Decoration is visible.
60 **/
61 Q_PROPERTY(bool shaded READ isShaded NOTIFY shadedChanged)
62 /**
63 * The icon of the DecoratedWindow. This can be used as the icon for the window menu button.
64 **/
65 Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
66 /**
67 * Whether the DecoratedWindow is maximized. A DecoratedWindow is maximized if it is both
68 * maximizedHorizontally and maximizedVertically. The Decoration of a maximized DecoratedWindow
69 * should only consist of the title bar area.
70 **/
71 Q_PROPERTY(bool maximized READ isMaximized NOTIFY maximizedChanged)
72 /**
73 * Whether the DecoratedWindow is maximized horizontally. A horizontally maximized DecoratedWindow
74 * uses the maximal possible width.
75 **/
76 Q_PROPERTY(bool maximizedHorizontally READ isMaximizedHorizontally NOTIFY maximizedHorizontallyChanged)
77 /**
78 * Whether the DecoratedWindow is maximized vertically. A vertically maximized DecoratedWindow
79 * uses the maximal possible height.
80 **/
81 Q_PROPERTY(bool maximizedVertically READ isMaximizedVertically NOTIFY maximizedVerticallyChanged)
82 /**
83 * Whether the DecoratedWindow is set to be kept above other DecoratedWindows. There can be multiple
84 * DecoratedWindows which are set to be kept above.
85 **/
86 Q_PROPERTY(bool keepAbove READ isKeepAbove NOTIFY keepAboveChanged)
87 /**
88 * Whether the DecoratedWindow is set to be kept below other DecoratedWindows. There can be multiple
89 * DecoratedWindows which are set to be kept below.
90 **/
91 Q_PROPERTY(bool keepBelow READ isKeepBelow NOTIFY keepBelowChanged)
92
93 /**
94 * Whether the DecoratedWindow can be closed. If this property is @c false a DecorationButton
95 * for closing the DecoratedWindow should be disabled.
96 **/
97 Q_PROPERTY(bool closeable READ isCloseable NOTIFY closeableChanged)
98 /**
99 * Whether the DecoratedWindow can be maximized. If this property is @c false a DecorationButton
100 * for maximizing the DecoratedWindow should be disabled.
101 **/
102 Q_PROPERTY(bool maximizeable READ isMaximizeable NOTIFY maximizeableChanged)
103 /**
104 * Whether the DecoratedWindow can be minimized. If this property is @c false a DecorationButton
105 * for minimizing the DecoratedWindow should be disabled.
106 **/
107 Q_PROPERTY(bool minimizeable READ isMinimizeable NOTIFY minimizeableChanged)
108 /**
109 * Whether the DecoratedWindow provides context help.
110 * The Decoration should only show a context help button if this property is @c true.
111 **/
112 Q_PROPERTY(bool providesContextHelp READ providesContextHelp NOTIFY providesContextHelpChanged)
113 /**
114 * Whether the DecoratedWindow is a modal dialog.
115 **/
116 Q_PROPERTY(bool modal READ isModal CONSTANT)
117 /**
118 * Whether the DecoratedWindow can be shaded. If this property is @c false a DecorationButton
119 * for shading the DecoratedWindow should be disabled.
120 **/
121 Q_PROPERTY(bool shadeable READ isShadeable NOTIFY shadeableChanged)
122 /**
123 * Whether the DecoratedWindow can be moved.
124 **/
125 Q_PROPERTY(bool moveable READ isMoveable NOTIFY moveableChanged)
126 /**
127 * Whether the DecoratedWindow can be resized.
128 **/
129 Q_PROPERTY(bool resizeable READ isResizeable NOTIFY resizeableChanged)
130
131 /**
132 * The width of the DecoratedWindow.
133 **/
134 Q_PROPERTY(qreal width READ width NOTIFY widthChanged)
135 /**
136 * The height of the DecoratedWindow.
137 **/
138 Q_PROPERTY(qreal height READ height NOTIFY heightChanged)
139 /**
140 * The size of the DecoratedWindow.
141 **/
142 Q_PROPERTY(QSizeF size READ size NOTIFY sizeChanged)
143 /**
144 * The palette this DecoratedWindow uses. The palette might be different for each
145 * DecoratedWindow and the Decoration should honor the palette.
146 **/
147 Q_PROPERTY(QPalette palette READ palette NOTIFY paletteChanged)
148 /**
149 * The Edges which are adjacent to a screen edge. E.g. for a maximized DecoratedWindow this
150 * will include all Edges. The Decoration can use this information to hide borders.
151 **/
152 Q_PROPERTY(Qt::Edges adjacentScreenEdges READ adjacentScreenEdges NOTIFY adjacentScreenEdgesChanged)
153 /**
154 * Whether the DecoratedWindow has an application menu
155 * @since 5.9
156 */
157 Q_PROPERTY(bool hasApplicationMenu READ hasApplicationMenu NOTIFY hasApplicationMenuChanged)
158 /**
159 * Whether the application menu for this DecoratedWindow is currently shown to the user
160 * The Decoration can use this information to highlight the respective button.
161 * @since 5.9
162 */
163 Q_PROPERTY(bool applicationMenuActive READ isApplicationMenuActive NOTIFY applicationMenuActiveChanged)
164
165 /**
166 * The current scale this decorated window is targeting.
167 * @since 6.3
168 */
169 Q_PROPERTY(qreal scale READ scale NOTIFY scaleChanged);
170
171 /**
172 * The next scale this decorated window is going to target.
173 * @since 6.3
174 */
175 Q_PROPERTY(qreal nextScale READ nextScale NOTIFY nextScaleChanged)
176
177public:
178 DecoratedWindow() = delete;
179 ~DecoratedWindow() override;
180 bool isActive() const;
181 QString caption() const;
182 bool isOnAllDesktops() const;
183 bool isShaded() const;
184 QIcon icon() const;
185 bool isMaximized() const;
186 bool isMaximizedHorizontally() const;
187 bool isMaximizedVertically() const;
188 bool isKeepAbove() const;
189 bool isKeepBelow() const;
190
191 bool isCloseable() const;
192 bool isMaximizeable() const;
193 bool isMinimizeable() const;
194 bool providesContextHelp() const;
195 bool isModal() const;
196 bool isShadeable() const;
197 bool isMoveable() const;
198 bool isResizeable() const;
199
200 Qt::Edges adjacentScreenEdges() const;
201
202 QString windowClass() const;
203
204 qreal width() const;
205 qreal height() const;
206 QSizeF size() const;
207
208 Decoration *decoration() const;
209 QPalette palette() const;
210 /**
211 * Used to get colors in QPalette.
212 * @param group The color group
213 * @param role The color role
214 * @return palette().color(group, role)
215 * @since 5.3
216 **/
217 QColor color(QPalette::ColorGroup group, QPalette::ColorRole role) const;
218 /**
219 * Used to get additional colors that are not in QPalette.
220 * @param group The color group
221 * @param role The color role
222 * @return The color if provided for combination of group and role, otherwise invalid QColor.
223 * @since 5.3
224 **/
225 QColor color(ColorGroup group, ColorRole role) const;
226
227 /**
228 * Whether the DecoratedWindow has an application menu
229 * @since 5.9
230 */
231 bool hasApplicationMenu() const;
232 /**
233 * Whether the application menu for this DecoratedWindow is currently shown to the user
234 * The Decoration can use this information to highlight the respective button.
235 * @since 5.9
236 */
237 bool isApplicationMenuActive() const;
238
239 /**
240 * Request the application menu to be shown to the user
241 * @param actionId The DBus menu ID of the action that should be highlighted, 0 for none.
242 */
243 void showApplicationMenu(int actionId);
244
245 /**
246 * Returns the current scale this decorated window is targeting
247 * @since 6.3
248 */
249 qreal scale() const;
250 /**
251 * Returns the next scale this decorated window is going to target.
252 */
253 qreal nextScale() const;
254 /**
255 * @returns the logical size of a device pixel with the current scale
256 * @since 6.3
257 */
258 qreal pixelSize() const;
259 /**
260 * snaps the logical geometry value to a fractional logical geometry value
261 * that aligns to the pixel grid with the current scale factor
262 * @since 6.3
263 */
264 qreal snapToPixelGrid(qreal value) const;
265 /**
266 * snaps the logical geometry value to a fractional logical geometry value
267 * that aligns to the pixel grid with the current scale factor
268 * @since 6.3
269 */
270 QPointF snapToPixelGrid(const QPointF &value) const;
271 /**
272 * snaps the logical geometry value to a fractional logical geometry value
273 * that aligns to the pixel grid with the current scale factor
274 * @since 6.3
275 */
276 QSizeF snapToPixelGrid(const QSizeF &value) const;
277 /**
278 * snaps the logical geometry value to a fractional logical geometry value
279 * that aligns to the pixel grid with the current scale factor
280 * @since 6.3
281 */
282 QRectF snapToPixelGrid(const QRectF &value) const;
283
284Q_SIGNALS:
285 void activeChanged(bool);
286 void captionChanged(QString);
287 void onAllDesktopsChanged(bool);
288 void shadedChanged(bool);
289 void iconChanged(QIcon);
290 void maximizedChanged(bool);
291 void maximizedHorizontallyChanged(bool);
292 void maximizedVerticallyChanged(bool);
293 void keepAboveChanged(bool);
294 void keepBelowChanged(bool);
295
296 void closeableChanged(bool);
297 void maximizeableChanged(bool);
298 void minimizeableChanged(bool);
299 void providesContextHelpChanged(bool);
300 void shadeableChanged(bool);
301 void moveableChanged(bool);
302 void resizeableChanged(bool);
303
304 void widthChanged(qreal);
305 void heightChanged(qreal);
306 void sizeChanged(const QSizeF &size);
307 void paletteChanged(const QPalette &palette);
308 void adjacentScreenEdgesChanged(Qt::Edges edges);
309
310 void hasApplicationMenuChanged(bool);
311 void applicationMenuActiveChanged(bool);
312 void scaleChanged();
313 void nextScaleChanged();
314
315private:
316 friend class Decoration;
317 DecoratedWindow(Decoration *parent, DecorationBridge *bridge);
318 const std::unique_ptr<DecoratedWindowPrivate> d;
319};
320
321} // namespace
The Client which gets decorated.
Base class for the Decoration.
Definition decoration.h:83
Framework for creating window decorations.
ColorGroup
Color groups are used for DecoratedWindow::color().
ColorRole
Color roles are used for DecoratedWindow::color().
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:55:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.