File indexing completed on 2024-04-28 03:56:00
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QColor> 0010 #include <QSGGeometryNode> 0011 #include <QVector2D> 0012 #include <QVector4D> 0013 0014 #include "shadowedrectanglematerial.h" 0015 0016 struct QSGMaterialType; 0017 class ShadowedBorderRectangleMaterial; 0018 0019 /** 0020 * Scene graph node for a shadowed rectangle. 0021 * 0022 * This node will set up the geometry and materials for a shadowed rectangle, 0023 * optionally with rounded corners. 0024 * 0025 * \note You must call updateGeometry() after setting properties of this node, 0026 * otherwise the node's state will not correctly reflect all the properties. 0027 * 0028 * \sa ShadowedRectangle 0029 */ 0030 class ShadowedRectangleNode : public QSGGeometryNode 0031 { 0032 public: 0033 ShadowedRectangleNode(); 0034 0035 /** 0036 * Set whether to draw a border. 0037 * 0038 * Note that this will switch between a material with or without border. 0039 * This means this needs to be called before any other setters. 0040 */ 0041 void setBorderEnabled(bool enabled); 0042 0043 void setRect(const QRectF &rect); 0044 void setSize(qreal size); 0045 void setRadius(const QVector4D &radius); 0046 void setColor(const QColor &color); 0047 void setShadowColor(const QColor &color); 0048 void setOffset(const QVector2D &offset); 0049 void setBorderWidth(qreal width); 0050 void setBorderColor(const QColor &color); 0051 void setShaderType(ShadowedRectangleMaterial::ShaderType type); 0052 0053 /** 0054 * Update the geometry for this node. 0055 * 0056 * This is done as an explicit step to avoid the geometry being recreated 0057 * multiple times while updating properties. 0058 */ 0059 void updateGeometry(); 0060 0061 protected: 0062 virtual ShadowedRectangleMaterial *createBorderlessMaterial(); 0063 virtual ShadowedBorderRectangleMaterial *createBorderMaterial(); 0064 virtual QSGMaterialType *borderMaterialType(); 0065 virtual QSGMaterialType *borderlessMaterialType(); 0066 0067 QSGGeometry *m_geometry; 0068 ShadowedRectangleMaterial *m_material = nullptr; 0069 ShadowedRectangleMaterial::ShaderType m_shaderType = ShadowedRectangleMaterial::ShaderType::Standard; 0070 0071 private: 0072 QRectF m_rect; 0073 qreal m_size = 0.0; 0074 QVector4D m_radius = QVector4D{0.0, 0.0, 0.0, 0.0}; 0075 QVector2D m_offset = QVector2D{0.0, 0.0}; 0076 QVector2D m_aspect = QVector2D{1.0, 1.0}; 0077 qreal m_borderWidth = 0.0; 0078 QColor m_borderColor; 0079 };