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

KDE's Doxygen guidelines are available online.