Kirigami2

shadowedrectanglenode.h
1/*
2 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#pragma once
8
9#include <QColor>
10#include <QSGGeometryNode>
11#include <QVector2D>
12#include <QVector4D>
13
14#include "shadowedrectanglematerial.h"
15
16struct QSGMaterialType;
18
19/**
20 * Scene graph node for a shadowed rectangle.
21 *
22 * This node will set up the geometry and materials for a shadowed rectangle,
23 * optionally with rounded corners.
24 *
25 * \note You must call updateGeometry() after setting properties of this node,
26 * otherwise the node's state will not correctly reflect all the properties.
27 *
28 * \sa ShadowedRectangle
29 */
31{
32public:
34
35 /**
36 * Set whether to draw a border.
37 *
38 * Note that this will switch between a material with or without border.
39 * This means this needs to be called before any other setters.
40 */
41 void setBorderEnabled(bool enabled);
42
43 void setRect(const QRectF &rect);
44 void setSize(qreal size);
45 void setRadius(const QVector4D &radius);
46 void setColor(const QColor &color);
47 void setShadowColor(const QColor &color);
48 void setOffset(const QVector2D &offset);
49 void setBorderWidth(qreal width);
50 void setBorderColor(const QColor &color);
51 void setShaderType(ShadowedRectangleMaterial::ShaderType type);
52
53 /**
54 * Update the geometry for this node.
55 *
56 * This is done as an explicit step to avoid the geometry being recreated
57 * multiple times while updating properties.
58 */
59 void updateGeometry();
60
61protected:
62 virtual ShadowedRectangleMaterial *createBorderlessMaterial();
63 virtual ShadowedBorderRectangleMaterial *createBorderMaterial();
64 virtual QSGMaterialType *borderMaterialType();
65 virtual QSGMaterialType *borderlessMaterialType();
66
67 QSGGeometry *m_geometry;
68 ShadowedRectangleMaterial *m_material = nullptr;
69 ShadowedRectangleMaterial::ShaderType m_shaderType = ShadowedRectangleMaterial::ShaderType::Standard;
70
71private:
72 QRectF m_rect;
73 qreal m_size = 0.0;
74 QVector4D m_radius = QVector4D{0.0, 0.0, 0.0, 0.0};
75 QVector2D m_offset = QVector2D{0.0, 0.0};
76 QVector2D m_aspect = QVector2D{1.0, 1.0};
77 qreal m_borderWidth = 0.0;
78 QColor m_borderColor;
79};
A material rendering a rectangle with a shadow and a border.
A material rendering a rectangle with a shadow.
Scene graph node for a shadowed rectangle.
void updateGeometry()
Update the geometry for this node.
void setBorderEnabled(bool enabled)
Set whether to draw a border.
NodeType type() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:46 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.