KDecoration2

decorationshadow.cpp
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 #include "decorationshadow.h"
7 #include "decorationshadow_p.h"
8 
9 namespace KDecoration2
10 {
11 
12 DecorationShadow::Private::Private(DecorationShadow *parent)
13  : q(parent)
14 {
15 }
16 
17 DecorationShadow::Private::~Private() = default;
18 
19 DecorationShadow::DecorationShadow()
20  : QObject()
21  , d(new Private(this))
22 {
23 }
24 
25 DecorationShadow::~DecorationShadow() = default;
26 
27 QRect DecorationShadow::topLeftGeometry() const
28 {
29  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
30  return QRect();
31  }
32  return QRect(0, 0, d->innerShadowRect.left(), d->innerShadowRect.top());
33 }
34 
35 QRect DecorationShadow::topGeometry() const
36 {
37  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
38  return QRect();
39  }
40  return QRect(d->innerShadowRect.left(), 0, d->innerShadowRect.width(), d->innerShadowRect.top());
41 }
42 
43 QRect DecorationShadow::topRightGeometry() const
44 {
45  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
46  return QRect();
47  }
48  return QRect(d->innerShadowRect.left() + d->innerShadowRect.width(), 0,
49  d->shadow.width() - d->innerShadowRect.width() - d->innerShadowRect.left(),
50  d->innerShadowRect.top());
51 }
52 
53 QRect DecorationShadow::rightGeometry() const
54 {
55  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
56  return QRect();
57  }
58  return QRect(d->innerShadowRect.left() + d->innerShadowRect.width(),
59  d->innerShadowRect.top(),
60  d->shadow.width() - d->innerShadowRect.width() - d->innerShadowRect.left(),
61  d->innerShadowRect.height());
62 }
63 
64 QRect DecorationShadow::bottomRightGeometry() const
65 {
66  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
67  return QRect();
68  }
69  return QRect(d->innerShadowRect.left() + d->innerShadowRect.width(),
70  d->innerShadowRect.top() + d->innerShadowRect.height(),
71  d->shadow.width() - d->innerShadowRect.width() - d->innerShadowRect.left(),
72  d->shadow.height() - d->innerShadowRect.top() - d->innerShadowRect.height());
73 }
74 
75 QRect DecorationShadow::bottomGeometry() const
76 {
77  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
78  return QRect();
79  }
80  return QRect(d->innerShadowRect.left(),
81  d->innerShadowRect.top() + d->innerShadowRect.height(),
82  d->innerShadowRect.width(),
83  d->shadow.height() - d->innerShadowRect.top() - d->innerShadowRect.height());
84 }
85 
86 QRect DecorationShadow::bottomLeftGeometry() const
87 {
88  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
89  return QRect();
90  }
91  return QRect(0, d->innerShadowRect.top() + d->innerShadowRect.height(),
92  d->innerShadowRect.left(),
93  d->shadow.height() - d->innerShadowRect.top() - d->innerShadowRect.height());
94 }
95 
96 QRect DecorationShadow::leftGeometry() const
97 {
98  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
99  return QRect();
100  }
101  return QRect(0, d->innerShadowRect.top(), d->innerShadowRect.left(), d->innerShadowRect.height());
102 }
103 
104 #ifndef K_DOXYGEN
105 
106 #define DELEGATE(type, name) \
107  type DecorationShadow::name() const \
108  { \
109  return d->name; \
110  }
111 
112 DELEGATE(QImage, shadow)
113 DELEGATE(QMargins, padding)
114 DELEGATE(QRect, innerShadowRect)
115 
116 #define I(name, Name) \
117 int DecorationShadow::padding##Name() const \
118 { \
119  return d->padding.name(); \
120 }
121 I(top, Top)
122 I(bottom, Bottom)
123 I(right, Right)
124 I(left, Left)
125 #undef I
126 
127 #undef DELEGATE
128 
129 #define SETTER(type, setName, name) \
130  void DecorationShadow::setName(type arg) \
131  { \
132  if (d->name == arg) { \
133  return; \
134  } \
135  d->name = arg; \
136  emit name##Changed(d->name); \
137  }
138 
139 SETTER(const QImage&, setShadow, shadow)
140 
141 #undef SETTER
142 #endif
143 
144 void DecorationShadow::setPadding(const QMargins &margins)
145 {
146  if (d->padding == margins) {
147  return;
148  }
149  d->padding = margins;
150  emit paddingChanged();
151 }
152 
153 void DecorationShadow::setInnerShadowRect(const QRect &rect)
154 {
155  if (d->innerShadowRect == rect) {
156  return;
157  }
158  d->innerShadowRect = rect;
159  emit innerShadowRectChanged();
160 }
161 
162 }
Framework for creating window decorations.
Top
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.