Changeset View
Changeset View
Standalone View
Standalone View
libbreezecommon/breezeboxshadowrenderer.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
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 | #pragma once | ||||
22 | | ||||
23 | // own | ||||
24 | #include "breezecommon_export.h" | ||||
25 | | ||||
26 | // Qt | ||||
27 | #include <QImage> | ||||
28 | #include <QPoint> | ||||
29 | #include <QSize> | ||||
30 | | ||||
31 | namespace Breeze | ||||
32 | { | ||||
33 | | ||||
34 | class BREEZECOMMON_EXPORT BoxShadowRenderer | ||||
35 | { | ||||
36 | public: | ||||
37 | // Compiler generated constructors & destructor are fine. | ||||
38 | | ||||
39 | /** | ||||
40 | * Set the size of the box | ||||
41 | * @param size The size of the box | ||||
42 | **/ | ||||
43 | void setBoxSize(const QSize &size); | ||||
44 | | ||||
45 | /** | ||||
46 | * Set the radius of box' corners | ||||
47 | * @param radius The border radius | ||||
48 | **/ | ||||
49 | void setBorderRadius(qreal radius); | ||||
50 | | ||||
51 | /** | ||||
52 | * Set the device pixel ratio of the resulting shadow texture | ||||
53 | * @param dpr The device pixel ratio | ||||
54 | **/ | ||||
55 | void setDevicePixelRatio(qreal dpr); | ||||
56 | | ||||
57 | /** | ||||
58 | * Add a shadow | ||||
59 | * @param offset The offset of the shadow | ||||
60 | * @param radius The blur radius | ||||
61 | * @param color The color of the shadow | ||||
62 | **/ | ||||
63 | void addShadow(const QPoint &offset, int radius, const QColor &color); | ||||
64 | | ||||
65 | /** | ||||
66 | * Render the shadow | ||||
67 | **/ | ||||
68 | QImage render() const; | ||||
69 | | ||||
70 | /** | ||||
71 | * Calculate minimum required size of the box | ||||
72 | * | ||||
73 | * @param radius The blur radius | ||||
74 | **/ | ||||
75 | static QSize minimumRequiredBoxSize(int radius); | ||||
76 | | ||||
77 | /** | ||||
78 | * | ||||
79 | * @param boxSize The size of the box | ||||
80 | * @param radius The blur radius | ||||
81 | * @param offset The offset of the shadow | ||||
82 | **/ | ||||
83 | static QSize minimumRequiredCanvasSize(const QSize &boxSize, int radius, const QPoint &offset); | ||||
84 | | ||||
85 | private: | ||||
86 | QSize m_boxSize; | ||||
87 | qreal m_borderRadius = 0.0; | ||||
88 | qreal m_dpr = 1.0; | ||||
89 | | ||||
90 | struct Shadow { | ||||
91 | QPoint offset; | ||||
92 | int radius; | ||||
93 | QColor color; | ||||
94 | }; | ||||
95 | | ||||
96 | QVector<Shadow> m_shadows; | ||||
97 | }; | ||||
98 | | ||||
99 | } // namespace Breeze |