Changeset View
Changeset View
Standalone View
Standalone View
src/kwindowshadow.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2019 Vlad Zahorodnii <vladzzag@gmail.com> | ||||
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() | ||||
66 | : d(KWindowSystemPluginWrapper::self().createWindowShadow()) | ||||
67 | { | ||||
68 | } | ||||
69 | | ||||
70 | KWindowShadow::~KWindowShadow() | ||||
71 | { | ||||
72 | destroy(); | ||||
73 | } | ||||
74 | | ||||
75 | KWindowShadowTile::Ptr KWindowShadow::leftTile() const | ||||
76 | { | ||||
77 | return d->leftTile; | ||||
78 | } | ||||
79 | | ||||
80 | void KWindowShadow::setLeftTile(KWindowShadowTile::Ptr tile) | ||||
81 | { | ||||
82 | if (d->isCreated) { | ||||
83 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a left tile to a shadow that already has " | ||||
84 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
85 | "setLeftTile() and create()"); | ||||
86 | return; | ||||
87 | } | ||||
88 | d->leftTile = tile; | ||||
89 | } | ||||
90 | | ||||
91 | KWindowShadowTile::Ptr KWindowShadow::topLeftTile() const | ||||
92 | { | ||||
93 | return d->topLeftTile; | ||||
94 | } | ||||
95 | | ||||
96 | void KWindowShadow::setTopLeftTile(KWindowShadowTile::Ptr tile) | ||||
97 | { | ||||
98 | if (d->isCreated) { | ||||
99 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a top-left tile to a shadow that already has " | ||||
100 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
101 | "setTopLeftTile() and create()"); | ||||
102 | return; | ||||
103 | } | ||||
104 | d->topLeftTile = tile; | ||||
105 | } | ||||
106 | | ||||
107 | KWindowShadowTile::Ptr KWindowShadow::topTile() const | ||||
108 | { | ||||
109 | return d->topTile; | ||||
110 | } | ||||
111 | | ||||
112 | void KWindowShadow::setTopTile(KWindowShadowTile::Ptr tile) | ||||
113 | { | ||||
114 | if (d->isCreated) { | ||||
115 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a top tile to a shadow that already has " | ||||
116 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
117 | "setTopTile() and create()"); | ||||
118 | return; | ||||
119 | } | ||||
120 | d->topTile = tile; | ||||
121 | } | ||||
122 | | ||||
123 | KWindowShadowTile::Ptr KWindowShadow::topRightTile() const | ||||
124 | { | ||||
125 | return d->topRightTile; | ||||
126 | } | ||||
127 | | ||||
128 | void KWindowShadow::setTopRightTile(KWindowShadowTile::Ptr tile) | ||||
129 | { | ||||
130 | if (d->isCreated) { | ||||
131 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a top-right tile to a shadow that already " | ||||
132 | "has native platform resources allocated. To do so, destroy() the shadow and " | ||||
133 | "then setTopRightTile() and create()"); | ||||
134 | return; | ||||
135 | } | ||||
136 | d->topRightTile = tile; | ||||
137 | } | ||||
138 | | ||||
139 | KWindowShadowTile::Ptr KWindowShadow::rightTile() const | ||||
140 | { | ||||
141 | return d->rightTile; | ||||
142 | } | ||||
143 | | ||||
144 | void KWindowShadow::setRightTile(KWindowShadowTile::Ptr tile) | ||||
145 | { | ||||
146 | if (d->isCreated) { | ||||
147 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a right tile to a shadow that already has " | ||||
148 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
149 | "setRightTile() and create()"); | ||||
150 | return; | ||||
151 | } | ||||
152 | d->rightTile = tile; | ||||
153 | } | ||||
154 | | ||||
155 | KWindowShadowTile::Ptr KWindowShadow::bottomRightTile() const | ||||
156 | { | ||||
157 | return d->bottomRightTile; | ||||
158 | } | ||||
159 | | ||||
160 | void KWindowShadow::setBottomRightTile(KWindowShadowTile::Ptr tile) | ||||
161 | { | ||||
162 | if (d->isCreated) { | ||||
163 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a bottom-right tile to a shadow that already " | ||||
164 | "has native platform resources allocated. To do so, destroy() the shadow and " | ||||
165 | "then setBottomRightTile() and create()"); | ||||
166 | return; | ||||
167 | } | ||||
168 | d->bottomRightTile = tile; | ||||
169 | } | ||||
170 | | ||||
171 | KWindowShadowTile::Ptr KWindowShadow::bottomTile() const | ||||
172 | { | ||||
173 | return d->bottomTile; | ||||
174 | } | ||||
175 | | ||||
176 | void KWindowShadow::setBottomTile(KWindowShadowTile::Ptr tile) | ||||
177 | { | ||||
178 | if (d->isCreated) { | ||||
179 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a bottom tile to a shadow that already has " | ||||
180 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
181 | "setBottomTile() and create()"); | ||||
182 | return; | ||||
183 | } | ||||
184 | d->bottomTile = tile; | ||||
185 | } | ||||
186 | | ||||
187 | KWindowShadowTile::Ptr KWindowShadow::bottomLeftTile() const | ||||
188 | { | ||||
189 | return d->bottomLeftTile; | ||||
190 | } | ||||
191 | | ||||
192 | void KWindowShadow::setBottomLeftTile(KWindowShadowTile::Ptr tile) | ||||
193 | { | ||||
194 | if (d->isCreated) { | ||||
195 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot attach a bottom-left tile to a shadow that already " | ||||
196 | "has native platform resources allocated. To do so, destroy() the shadow and " | ||||
197 | "then setBottomLeftTile() and create()"); | ||||
198 | return; | ||||
199 | } | ||||
200 | d->bottomLeftTile = tile; | ||||
201 | } | ||||
202 | | ||||
203 | QMargins KWindowShadow::padding() const | ||||
204 | { | ||||
205 | return d->padding; | ||||
206 | } | ||||
207 | | ||||
208 | void KWindowShadow::setPadding(const QMargins &padding) | ||||
209 | { | ||||
210 | if (d->isCreated) { | ||||
211 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot set the padding on a shadow that already has " | ||||
212 | "native platform resources allocated. To do so, destroy() the shadow and " | ||||
213 | "then setPadding() and create()"); | ||||
214 | return; | ||||
215 | } | ||||
216 | d->padding = padding; | ||||
217 | } | ||||
218 | | ||||
219 | QWindow *KWindowShadow::window() const | ||||
220 | { | ||||
221 | return d->window; | ||||
222 | } | ||||
223 | | ||||
224 | void KWindowShadow::setWindow(QWindow *window) | ||||
225 | { | ||||
226 | if (d->isCreated) { | ||||
227 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot set the target window on a shadow that already has " | ||||
228 | "native platform resources allocated. To do so, destroy() the shadow and then " | ||||
229 | "setWindow() and create()"); | ||||
230 | return; | ||||
231 | } | ||||
232 | d->window = window; | ||||
233 | } | ||||
234 | | ||||
235 | bool KWindowShadow::isCreated() const | ||||
236 | { | ||||
237 | return d->isCreated; | ||||
238 | } | ||||
239 | | ||||
240 | bool KWindowShadow::create() | ||||
241 | { | ||||
242 | if (d->isCreated) { | ||||
243 | return true; | ||||
244 | } | ||||
245 | if (!d->window) { | ||||
246 | qCWarning(LOG_KWINDOWSYSTEM, "Cannot allocate the native platform resources for the shadow " | ||||
247 | "because the target window is not specified."); | ||||
248 | return false; | ||||
249 | } | ||||
250 | if (!d->prepareTiles()) { | ||||
251 | return false; | ||||
252 | } | ||||
253 | d->isCreated = d->create(); | ||||
254 | return d->isCreated; | ||||
255 | } | ||||
256 | | ||||
257 | void KWindowShadow::destroy() | ||||
258 | { | ||||
259 | if (!d->isCreated) { | ||||
260 | return; | ||||
261 | } | ||||
262 | d->destroy(); | ||||
263 | d->isCreated = false; | ||||
264 | } | ||||
265 | | ||||
266 | KWindowShadowTilePrivate::~KWindowShadowTilePrivate() | ||||
267 | { | ||||
268 | } | ||||
269 | | ||||
270 | KWindowShadowTilePrivate *KWindowShadowTilePrivate::get(const KWindowShadowTile *tile) | ||||
271 | { | ||||
272 | return tile->d.data(); | ||||
273 | } | ||||
274 | | ||||
275 | KWindowShadowPrivate::~KWindowShadowPrivate() | ||||
276 | { | ||||
277 | } | ||||
278 | | ||||
279 | bool KWindowShadowPrivate::create() | ||||
280 | { | ||||
281 | return false; | ||||
282 | } | ||||
283 | | ||||
284 | void KWindowShadowPrivate::destroy() | ||||
285 | { | ||||
286 | } | ||||
287 | | ||||
288 | bool KWindowShadowPrivate::prepareTiles() | ||||
289 | { | ||||
290 | const std::array<KWindowShadowTile *, 8> tiles { | ||||
291 | leftTile.data(), | ||||
292 | topLeftTile.data(), | ||||
293 | topTile.data(), | ||||
294 | topRightTile.data(), | ||||
295 | rightTile.data(), | ||||
296 | bottomRightTile.data(), | ||||
297 | bottomTile.data(), | ||||
298 | bottomLeftTile.data(), | ||||
299 | }; | ||||
300 | | ||||
301 | for (KWindowShadowTile *tile : tiles) { | ||||
302 | if (!tile) { | ||||
303 | continue; | ||||
304 | } | ||||
305 | if (tile->isCreated()) { | ||||
306 | continue; | ||||
307 | } | ||||
308 | if (!tile->create()) { | ||||
309 | return false; | ||||
310 | } | ||||
311 | } | ||||
312 | | ||||
313 | return true; | ||||
314 | } | ||||
315 | | ||||
316 | bool KWindowShadowTilePrivateDummy::create() | ||||
317 | { | ||||
318 | return false; | ||||
319 | } | ||||
320 | | ||||
321 | void KWindowShadowTilePrivateDummy::destroy() | ||||
322 | { | ||||
323 | } | ||||
324 | | ||||
325 | bool KWindowShadowPrivateDummy::create() | ||||
326 | { | ||||
327 | return false; | ||||
328 | } | ||||
329 | | ||||
330 | void KWindowShadowPrivateDummy::destroy() | ||||
331 | { | ||||
332 | } |