Changeset View
Changeset View
Standalone View
Standalone View
src/kwindowshadow.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Lesser General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Lesser General Public | ||||
15 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | */ | ||||
17 | | ||||
18 | #include "kwindowshadow.h" | ||||
19 | #include "kwindowshadow_dummy_p.h" | ||||
20 | #include "kwindowshadow_p.h" | ||||
21 | #include "kwindowsystem_debug.h" | ||||
22 | #include "pluginwrapper_p.h" | ||||
23 | | ||||
24 | KWindowShadowTile::KWindowShadowTile() | ||||
25 | : d(KWindowSystemPluginWrapper::self().createWindowShadowTile()) | ||||
26 | { | ||||
27 | } | ||||
28 | | ||||
29 | KWindowShadowTile::~KWindowShadowTile() | ||||
30 | { | ||||
31 | if (d->isCreated) { | ||||
32 | d->destroy(); | ||||
33 | } | ||||
34 | } | ||||
35 | | ||||
36 | QImage KWindowShadowTile::image() const | ||||
37 | { | ||||
38 | return d->image; | ||||
39 | } | ||||
40 | | ||||
41 | void KWindowShadowTile::setImage(const QImage &image) | ||||
42 | { | ||||
43 | if (d->isCreated) { | ||||
44 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot change the image on a tile that already has native " | ||||
45 | "platform resources allocated."); | ||||
46 | return; | ||||
47 | } | ||||
48 | d->image = image; | ||||
49 | } | ||||
50 | | ||||
51 | bool KWindowShadowTile::isCreated() const | ||||
52 | { | ||||
53 | return d->isCreated; | ||||
54 | } | ||||
55 | | ||||
56 | bool KWindowShadowTile::create() | ||||
57 | { | ||||
58 | if (d->isCreated) { | ||||
59 | return true; | ||||
60 | } | ||||
61 | d->isCreated = d->create(); | ||||
62 | return d->isCreated; | ||||
63 | } | ||||
64 | | ||||
65 | KWindowShadow::KWindowShadow(QObject *parent) | ||||
66 | : QObject(parent) | ||||
67 | , d(KWindowSystemPluginWrapper::self().createWindowShadow()) | ||||
68 | { | ||||
69 | } | ||||
70 | | ||||
71 | KWindowShadow::~KWindowShadow() | ||||
72 | { | ||||
73 | destroy(); | ||||
74 | } | ||||
75 | | ||||
76 | KWindowShadowTile::Ptr KWindowShadow::leftTile() const | ||||
77 | { | ||||
78 | return d->leftTile; | ||||
79 | } | ||||
80 | | ||||
81 | void KWindowShadow::setLeftTile(KWindowShadowTile::Ptr tile) | ||||
82 | { | ||||
83 | if (d->isCreated) { | ||||
84 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a left tile to a shadow that already has " | ||||
85 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
86 | "setLeftTile() and create()"); | ||||
87 | return; | ||||
88 | } | ||||
89 | d->leftTile = tile; | ||||
90 | } | ||||
91 | | ||||
92 | KWindowShadowTile::Ptr KWindowShadow::topLeftTile() const | ||||
93 | { | ||||
94 | return d->topLeftTile; | ||||
95 | } | ||||
96 | | ||||
97 | void KWindowShadow::setTopLeftTile(KWindowShadowTile::Ptr tile) | ||||
98 | { | ||||
99 | if (d->isCreated) { | ||||
100 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a top-left tile to a shadow that already has " | ||||
101 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
102 | "setTopLeftTile() and create()"); | ||||
103 | return; | ||||
104 | } | ||||
105 | d->topLeftTile = tile; | ||||
106 | } | ||||
107 | | ||||
108 | KWindowShadowTile::Ptr KWindowShadow::topTile() const | ||||
109 | { | ||||
110 | return d->topTile; | ||||
111 | } | ||||
112 | | ||||
113 | void KWindowShadow::setTopTile(KWindowShadowTile::Ptr tile) | ||||
114 | { | ||||
115 | if (d->isCreated) { | ||||
116 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a top tile to a shadow that already has " | ||||
117 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
118 | "setTopTile() and create()"); | ||||
119 | return; | ||||
120 | } | ||||
121 | d->topTile = tile; | ||||
122 | } | ||||
123 | | ||||
124 | KWindowShadowTile::Ptr KWindowShadow::topRightTile() const | ||||
125 | { | ||||
126 | return d->topRightTile; | ||||
127 | } | ||||
128 | | ||||
129 | void KWindowShadow::setTopRightTile(KWindowShadowTile::Ptr tile) | ||||
130 | { | ||||
131 | if (d->isCreated) { | ||||
132 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a top-right tile to a shadow that already " | ||||
133 | "has native platform resources allocated. To do so, destroy() the shadow and " | ||||
134 | "then setTopRightTile() and create()"); | ||||
135 | return; | ||||
136 | } | ||||
137 | d->topRightTile = tile; | ||||
138 | } | ||||
139 | | ||||
140 | KWindowShadowTile::Ptr KWindowShadow::rightTile() const | ||||
141 | { | ||||
142 | return d->rightTile; | ||||
143 | } | ||||
144 | | ||||
145 | void KWindowShadow::setRightTile(KWindowShadowTile::Ptr tile) | ||||
146 | { | ||||
147 | if (d->isCreated) { | ||||
148 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a right tile to a shadow that already has " | ||||
149 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
150 | "setRightTile() and create()"); | ||||
151 | return; | ||||
152 | } | ||||
153 | d->rightTile = tile; | ||||
154 | } | ||||
155 | | ||||
156 | KWindowShadowTile::Ptr KWindowShadow::bottomRightTile() const | ||||
157 | { | ||||
158 | return d->bottomRightTile; | ||||
159 | } | ||||
160 | | ||||
161 | void KWindowShadow::setBottomRightTile(KWindowShadowTile::Ptr tile) | ||||
162 | { | ||||
163 | if (d->isCreated) { | ||||
164 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a bottom-right tile to a shadow that already " | ||||
165 | "has native platform resources allocated. To do so, destroy() the shadow and " | ||||
166 | "then setBottomRightTile() and create()"); | ||||
167 | return; | ||||
168 | } | ||||
169 | d->bottomRightTile = tile; | ||||
170 | } | ||||
171 | | ||||
172 | KWindowShadowTile::Ptr KWindowShadow::bottomTile() const | ||||
173 | { | ||||
174 | return d->bottomTile; | ||||
175 | } | ||||
176 | | ||||
177 | void KWindowShadow::setBottomTile(KWindowShadowTile::Ptr tile) | ||||
178 | { | ||||
179 | if (d->isCreated) { | ||||
180 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a bottom tile to a shadow that already has " | ||||
181 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
182 | "setBottomTile() and create()"); | ||||
183 | return; | ||||
184 | } | ||||
185 | d->bottomTile = tile; | ||||
186 | } | ||||
187 | | ||||
188 | KWindowShadowTile::Ptr KWindowShadow::bottomLeftTile() const | ||||
189 | { | ||||
190 | return d->bottomLeftTile; | ||||
191 | } | ||||
192 | | ||||
193 | void KWindowShadow::setBottomLeftTile(KWindowShadowTile::Ptr tile) | ||||
194 | { | ||||
195 | if (d->isCreated) { | ||||
196 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a bottom-left tile to a shadow that already " | ||||
197 | "has native platform resources allocated. To do so, destroy() the shadow and " | ||||
198 | "then setBottomLeftTile() and create()"); | ||||
199 | return; | ||||
200 | } | ||||
201 | d->bottomLeftTile = tile; | ||||
202 | } | ||||
203 | | ||||
204 | QMargins KWindowShadow::padding() const | ||||
205 | { | ||||
206 | return d->padding; | ||||
207 | } | ||||
208 | | ||||
209 | void KWindowShadow::setPadding(const QMargins &padding) | ||||
210 | { | ||||
211 | if (d->isCreated) { | ||||
212 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot set the padding on a shadow that already has " | ||||
213 | "native platform resources allocated. To do so, destroy() the shadow and " | ||||
214 | "then setPadding() and create()"); | ||||
215 | return; | ||||
216 | } | ||||
217 | d->padding = padding; | ||||
218 | } | ||||
219 | | ||||
220 | QWindow *KWindowShadow::window() const | ||||
221 | { | ||||
222 | return d->window; | ||||
223 | } | ||||
224 | | ||||
225 | void KWindowShadow::setWindow(QWindow *window) | ||||
226 | { | ||||
227 | if (d->isCreated) { | ||||
228 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot set the target window on a shadow that already has " | ||||
229 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
230 | "setWindow() and create()"); | ||||
231 | return; | ||||
232 | } | ||||
233 | d->window = window; | ||||
234 | } | ||||
235 | | ||||
236 | bool KWindowShadow::isCreated() const | ||||
237 | { | ||||
238 | return d->isCreated; | ||||
239 | } | ||||
240 | | ||||
241 | bool KWindowShadow::create() | ||||
242 | { | ||||
243 | if (d->isCreated) { | ||||
244 | return true; | ||||
245 | } | ||||
246 | if (!d->window) { | ||||
247 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot allocate the native platform resources for the shadow " | ||||
248 | "because the target window is not specified."); | ||||
249 | return false; | ||||
250 | } | ||||
251 | if (!d->prepareTiles()) { | ||||
252 | return false; | ||||
253 | } | ||||
254 | d->isCreated = d->create(); | ||||
255 | return d->isCreated; | ||||
256 | } | ||||
257 | | ||||
258 | void KWindowShadow::destroy() | ||||
259 | { | ||||
260 | if (!d->isCreated) { | ||||
261 | return; | ||||
262 | } | ||||
263 | d->destroy(); | ||||
264 | d->isCreated = false; | ||||
265 | } | ||||
266 | | ||||
267 | KWindowShadowTilePrivate::~KWindowShadowTilePrivate() | ||||
268 | { | ||||
269 | } | ||||
270 | | ||||
271 | KWindowShadowTilePrivate *KWindowShadowTilePrivate::get(const KWindowShadowTile *tile) | ||||
272 | { | ||||
273 | return tile->d.data(); | ||||
274 | } | ||||
275 | | ||||
276 | KWindowShadowPrivate::~KWindowShadowPrivate() | ||||
277 | { | ||||
278 | } | ||||
279 | | ||||
280 | bool KWindowShadowPrivate::create() | ||||
281 | { | ||||
282 | return false; | ||||
283 | } | ||||
284 | | ||||
285 | void KWindowShadowPrivate::destroy() | ||||
286 | { | ||||
287 | } | ||||
288 | | ||||
289 | bool KWindowShadowPrivate::prepareTiles() | ||||
290 | { | ||||
291 | const std::array<KWindowShadowTile *, 8> tiles { | ||||
292 | leftTile.data(), | ||||
293 | topLeftTile.data(), | ||||
294 | topTile.data(), | ||||
295 | topRightTile.data(), | ||||
296 | rightTile.data(), | ||||
297 | bottomRightTile.data(), | ||||
298 | bottomTile.data(), | ||||
299 | bottomLeftTile.data(), | ||||
300 | }; | ||||
301 | | ||||
302 | for (KWindowShadowTile *tile : tiles) { | ||||
303 | if (!tile) { | ||||
304 | continue; | ||||
305 | } | ||||
306 | if (tile->isCreated()) { | ||||
307 | continue; | ||||
308 | } | ||||
309 | if (!tile->create()) { | ||||
310 | return false; | ||||
311 | } | ||||
312 | } | ||||
313 | | ||||
314 | return true; | ||||
315 | } | ||||
316 | | ||||
317 | bool KWindowShadowTilePrivateDummy::create() | ||||
318 | { | ||||
319 | return false; | ||||
320 | } | ||||
321 | | ||||
322 | void KWindowShadowTilePrivateDummy::destroy() | ||||
323 | { | ||||
324 | } | ||||
325 | | ||||
326 | bool KWindowShadowPrivateDummy::create() | ||||
327 | { | ||||
328 | return false; | ||||
329 | } | ||||
330 | | ||||
331 | void KWindowShadowPrivateDummy::destroy() | ||||
332 | { | ||||
333 | } |