KDecoration2

decorationshadow.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 <kdecoration2/kdecoration2_export.h>
9
10#include <QImage>
11#include <QMargins>
12#include <QObject>
13
14namespace KDecoration2
15{
16class DecorationShadowPrivate;
17
18/**
19 * @brief A wrapper to define the shadow around the Decoration.
20 *
21 * The shadow around the Decoration should not be rendered as part of the Decoration.
22 * Instead a DecorationShadow should be used. That way a backend can optimize the
23 * rendering of the shadow in a better way. If the shadow were part of the Decoration
24 * directly it would need to be updated when the rendering changes. By using a dedicated
25 * DecorationShadow the same shadow can be shared between multiple DecoratedClients.
26 *
27 * The DecorationShadow consists of a shadow QImage which is composed of multiple parts:
28 * @li topLeft: rendered as it is
29 * @li top: stretched in x direction
30 * @li topRight: rendered as it is
31 * @li right: stretched in y direction
32 * @li bottomRight: rendered as it is
33 * @li bottom: stretched in x direction
34 * @li bottomLeft: rendered as it is
35 * @li left: stretched in y direction
36 *
37 * The sizes of these parts is denoted in the property innerShadowRect and the layout is the
38 * following:
39 * #######################################
40 * # topLeft # top # topRight #
41 * #######################################
42 * # left # # right #
43 * #######################################
44 * # bottomLeft # bottom # bottomRight #
45 * #######################################
46 *
47 * The innerShadowRect property is a QRect of the geometry of the areas not covered by any of the
48 * elements. This means that:
49 * @li x/y of the rect is the same as the size of the topLeft element
50 * @li width of the rect is the same as the width of the top and bottom element
51 * @li height of the rect is the same as the height of the left and the right element
52 * By that the actual sizes of all elements can be derived out of the size of the shadow image
53 * and the innerShadowRect.
54 *
55 * The position of the rendering depends on the values;
56 * @li paddingTop
57 * @li paddingRight
58 * @li paddingBottom
59 * @li paddingLeft
60 *
61 * The top left element is rendered with an offset of paddingLeft and paddingTop.
62 * The non-stretched elements are rendered in the size as specified, the area
63 * between two non-stretched elements (e.g. between topLeft and topRight) is filled
64 * by the element with one direction stretched and the other direction fixed at the
65 * corresponding padding value. E.g. the top element is stretched in x direction and
66 * fixed at paddingTop value. If stretching the side elements is not wanted one needs
67 * to provide a shadow image with those elements at a size that stretching is not
68 * required.
69 *
70 * If the padding values are smaller than the sizes of the shadow elements the shadow
71 * will overlap with the Decoration and be rendered behind the Decoration.
72 *
73 **/
74class KDECORATIONS2_EXPORT DecorationShadow : public QObject
75{
76 Q_OBJECT
77 Q_PROPERTY(QImage shadow READ shadow WRITE setShadow NOTIFY shadowChanged)
78 Q_PROPERTY(QRect innerShadowRect READ innerShadowRect WRITE setInnerShadowRect NOTIFY innerShadowRectChanged)
79 Q_PROPERTY(QRect topLeftGeometry READ topLeftGeometry NOTIFY innerShadowRectChanged)
80 Q_PROPERTY(QRect topGeometry READ topGeometry NOTIFY innerShadowRectChanged)
81 Q_PROPERTY(QRect topRightGeometry READ topRightGeometry NOTIFY innerShadowRectChanged)
82 Q_PROPERTY(QRect rightGeometry READ rightGeometry NOTIFY innerShadowRectChanged)
83 Q_PROPERTY(QRect bottomRightGeometry READ bottomRightGeometry NOTIFY innerShadowRectChanged)
84 Q_PROPERTY(QRect bottomGeometry READ bottomGeometry NOTIFY innerShadowRectChanged)
85 Q_PROPERTY(QRect bottomLeftGeometry READ bottomLeftGeometry NOTIFY innerShadowRectChanged)
86 Q_PROPERTY(QRect leftGeometry READ leftGeometry NOTIFY innerShadowRectChanged)
87 Q_PROPERTY(int paddingTop READ paddingTop NOTIFY paddingChanged)
88 Q_PROPERTY(int paddingRight READ paddingRight NOTIFY paddingChanged)
89 Q_PROPERTY(int paddingBottom READ paddingBottom NOTIFY paddingChanged)
90 Q_PROPERTY(int paddingLeft READ paddingLeft NOTIFY paddingChanged)
91 Q_PROPERTY(QMargins padding READ padding WRITE setPadding NOTIFY paddingChanged)
92public:
93 explicit DecorationShadow();
94 ~DecorationShadow() override;
95
96 QImage shadow() const;
97 QRect innerShadowRect() const;
98 QRect topLeftGeometry() const;
99 QRect topGeometry() const;
100 QRect topRightGeometry() const;
101 QRect rightGeometry() const;
102 QRect bottomRightGeometry() const;
103 QRect bottomGeometry() const;
104 QRect bottomLeftGeometry() const;
105 QRect leftGeometry() const;
106 int paddingTop() const;
107 int paddingRight() const;
108 int paddingBottom() const;
109 int paddingLeft() const;
110 QMargins padding() const;
111
112 void setShadow(const QImage &image);
113 void setInnerShadowRect(const QRect &rect);
114 void setPadding(const QMargins &margins);
115
116Q_SIGNALS:
117 void shadowChanged(const QImage &);
118 void innerShadowRectChanged();
119 void paddingChanged();
120
121private:
122 class Private;
123 std::unique_ptr<Private> d;
124};
125
126}
127
128Q_DECLARE_METATYPE(KDecoration2::DecorationShadow *)
A wrapper to define the shadow around the Decoration.
Framework for creating window decorations.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.