KDecoration2

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

KDE's Doxygen guidelines are available online.