MauiKit Controls

windows/shadowhelper/boxshadowrenderer.h
1/*
2 * Copyright (C) 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#pragma once
20
21// Qt
22#include <QColor>
23#include <QImage>
24#include <QPoint>
25#include <QSize>
26
27class BoxShadowRenderer
28{
29public:
30 // Compiler generated constructors & destructor are fine.
31
32 /**
33 * Set the size of the box.
34 * @param size The size of the box.
35 **/
36 void setBoxSize(const QSize &size);
37
38 /**
39 * Set the radius of box' corners.
40 * @param radius The border radius, in pixels.
41 **/
42 void setBorderRadius(qreal radius);
43
44 /**
45 * Set the device pixel ratio of the resulting shadow texture.
46 * @param dpr The device pixel ratio.
47 **/
48 void setDevicePixelRatio(qreal dpr);
49
50 /**
51 * Add a shadow.
52 * @param offset The offset of the shadow.
53 * @param radius The blur radius.
54 * @param color The color of the shadow.
55 **/
56 void addShadow(const QPoint &offset, int radius, const QColor &color);
57
58 /**
59 * Render the shadow.
60 **/
61 QImage render() const;
62
63 /**
64 * Calculate the minimum size of the box.
65 *
66 * This helper computes the minimum size of the box so the shadow behind it has
67 * full its strength.
68 *
69 * @param radius The blur radius of the shadow.
70 **/
71 static QSize calculateMinimumBoxSize(int radius);
72
73 /**
74 * Calculate the minimum size of the shadow texture.
75 *
76 * This helper computes the minimum size of the resulting texture so the shadow
77 * is not clipped.
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 calculateMinimumShadowTextureSize(const QSize &boxSize, int radius, const QPoint &offset);
84
85private:
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};
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.