Differential D10811 Diff 35740 autotests/integration/fakes/org.kde.kdecoration2/fakedecoration_with_shadows.cpp
Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/fakes/org.kde.kdecoration2/fakedecoration_with_shadows.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | | ||||
21 | #include <QPainter> | ||||
22 | | ||||
23 | #include <KDecoration2/Decoration> | ||||
24 | #include <KPluginFactory> | ||||
25 | | ||||
26 | | ||||
27 | class FakeDecoWithShadows : public KDecoration2::Decoration | ||||
28 | { | ||||
29 | Q_OBJECT | ||||
30 | | ||||
31 | public: | ||||
32 | explicit FakeDecoWithShadows(QObject *parent = nullptr, const QVariantList &args = QVariantList()) | ||||
33 | : Decoration(parent, args) {} | ||||
34 | ~FakeDecoWithShadows() override {} | ||||
35 | | ||||
36 | void paint(QPainter *painter, const QRect &repaintRegion) override { | ||||
37 | Q_UNUSED(painter) | ||||
38 | Q_UNUSED(repaintRegion) | ||||
39 | } | ||||
40 | | ||||
41 | public Q_SLOTS: | ||||
42 | void init() override { | ||||
43 | const int shadowSize = 128; | ||||
44 | const int offsetTop = 64; | ||||
45 | const int offsetLeft = 48; | ||||
46 | const QRect shadowRect(0, 0, 4 * shadowSize + 1, 4 * shadowSize + 1); | ||||
47 | | ||||
48 | QImage shadowTexture(shadowRect.size(), QImage::Format_ARGB32_Premultiplied); | ||||
49 | shadowTexture.fill(Qt::transparent); | ||||
50 | | ||||
51 | const QMargins padding( | ||||
52 | shadowSize - offsetLeft, | ||||
53 | shadowSize - offsetTop, | ||||
54 | shadowSize + offsetLeft, | ||||
55 | shadowSize + offsetTop); | ||||
56 | | ||||
57 | auto decoShadow = QSharedPointer<KDecoration2::DecorationShadow>::create(); | ||||
58 | decoShadow->setPadding(padding); | ||||
59 | decoShadow->setInnerShadowRect(QRect(shadowRect.center(), QSize(1, 1))); | ||||
60 | decoShadow->setShadow(shadowTexture); | ||||
61 | | ||||
62 | setShadow(decoShadow); | ||||
63 | } | ||||
64 | }; | ||||
65 | | ||||
66 | K_PLUGIN_FACTORY_WITH_JSON( | ||||
67 | FakeDecoWithShadowsFactory, | ||||
68 | "fakedecoration_with_shadows.json", | ||||
69 | registerPlugin<FakeDecoWithShadows>(); | ||||
70 | ) | ||||
71 | | ||||
72 | #include "fakedecoration_with_shadows.moc" |