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 DecorationShadow::Private::Private(DecorationShadow *parent)
12  : q(parent)
13 {
14 }
15 
16 DecorationShadow::Private::~Private() = default;
17 
18 DecorationShadow::DecorationShadow()
19  : QObject()
20  , d(new Private(this))
21 {
22 }
23 
24 DecorationShadow::~DecorationShadow() = default;
25 
26 QRect DecorationShadow::topLeftGeometry() const
27 {
28  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
29  return QRect();
30  }
31  return QRect(0, 0, d->innerShadowRect.left(), d->innerShadowRect.top());
32 }
33 
34 QRect DecorationShadow::topGeometry() const
35 {
36  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
37  return QRect();
38  }
39  return QRect(d->innerShadowRect.left(), 0, d->innerShadowRect.width(), d->innerShadowRect.top());
40 }
41 
42 QRect DecorationShadow::topRightGeometry() const
43 {
44  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
45  return QRect();
46  }
47  return QRect(d->innerShadowRect.left() + d->innerShadowRect.width(),
48  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,
92  d->innerShadowRect.top() + d->innerShadowRect.height(),
93  d->innerShadowRect.left(),
94  d->shadow.height() - d->innerShadowRect.top() - d->innerShadowRect.height());
95 }
96 
97 QRect DecorationShadow::leftGeometry() const
98 {
99  if (d->innerShadowRect.isNull() || d->shadow.isNull()) {
100  return QRect();
101  }
102  return QRect(0, d->innerShadowRect.top(), d->innerShadowRect.left(), d->innerShadowRect.height());
103 }
104 
105 #ifndef K_DOXYGEN
106 
107 #define DELEGATE(type, name) \
108  type DecorationShadow::name() const \
109  { \
110  return d->name; \
111  }
112 
113 DELEGATE(QImage, shadow)
114 DELEGATE(QMargins, padding)
115 DELEGATE(QRect, innerShadowRect)
116 
117 #define I(name, Name) \
118  int DecorationShadow::padding##Name() const \
119  { \
120  return d->padding.name(); \
121  }
122 I(top, Top)
123 I(bottom, Bottom)
124 I(right, Right)
125 I(left, Left)
126 #undef I
127 
128 #undef DELEGATE
129 
130 #define SETTER(type, setName, name) \
131  void DecorationShadow::setName(type arg) \
132  { \
133  if (d->name == arg) { \
134  return; \
135  } \
136  d->name = arg; \
137  Q_EMIT name##Changed(d->name); \
138  }
139 
140 SETTER(const QImage &, setShadow, shadow)
141 
142 #undef SETTER
143 #endif
144 
145 void DecorationShadow::setPadding(const QMargins &margins)
146 {
147  if (d->padding == margins) {
148  return;
149  }
150  d->padding = margins;
151  Q_EMIT paddingChanged();
152 }
153 
154 void DecorationShadow::setInnerShadowRect(const QRect &rect)
155 {
156  if (d->innerShadowRect == rect) {
157  return;
158  }
159  d->innerShadowRect = rect;
160  Q_EMIT innerShadowRectChanged();
161 }
162 
163 }
Framework for creating window decorations.
Top
Q_EMITQ_EMIT
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.