Kirigami2

shadowedtexture.cpp
1/*
2 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "shadowedtexture.h"
8
9#include <QQuickWindow>
10#include <QSGRectangleNode>
11#include <QSGRendererInterface>
12
13#include "scenegraph/shadowedtexturenode.h"
14
15ShadowedTexture::ShadowedTexture(QQuickItem *parentItem)
16 : ShadowedRectangle(parentItem)
17{
18}
19
20ShadowedTexture::~ShadowedTexture()
21{
22}
23
25{
26 return m_source;
27}
28
29void ShadowedTexture::setSource(QQuickItem *newSource)
30{
31 if (newSource == m_source) {
32 return;
33 }
34
35 m_source = newSource;
36 m_sourceChanged = true;
37 if (m_source && !m_source->parentItem()) {
38 m_source->setParentItem(this);
39 }
40
41 if (!isSoftwareRendering()) {
42 update();
43 }
44 Q_EMIT sourceChanged();
45}
46
47QSGNode *ShadowedTexture::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *data)
48{
49 Q_UNUSED(data)
50
51 if (boundingRect().isEmpty()) {
52 delete node;
53 return nullptr;
54 }
55
56 auto shadowNode = static_cast<ShadowedRectangleNode *>(node);
57
58 if (!shadowNode || m_sourceChanged) {
59 m_sourceChanged = false;
60 delete shadowNode;
61 if (m_source) {
62 shadowNode = new ShadowedTextureNode{};
63 } else {
64 shadowNode = new ShadowedRectangleNode{};
65 }
66
67 if (qEnvironmentVariableIsSet("KIRIGAMI_LOWPOWER_HARDWARE")) {
68 shadowNode->setShaderType(ShadowedRectangleMaterial::ShaderType::LowPower);
69 }
70 }
71
72 shadowNode->setBorderEnabled(border()->isEnabled());
73 shadowNode->setRect(boundingRect());
74 shadowNode->setSize(shadow()->size());
75 shadowNode->setRadius(corners()->toVector4D(radius()));
76 shadowNode->setOffset(QVector2D{float(shadow()->xOffset()), float(shadow()->yOffset())});
77 shadowNode->setColor(color());
78 shadowNode->setShadowColor(shadow()->color());
79 shadowNode->setBorderWidth(border()->width());
80 shadowNode->setBorderColor(border()->color());
81
82 if (m_source) {
83 static_cast<ShadowedTextureNode *>(shadowNode)->setTextureSource(m_source->textureProvider());
84 }
85
86 shadowNode->updateGeometry();
87 return shadowNode;
88}
89
90#include "moc_shadowedtexture.cpp"
Scene graph node for a shadowed rectangle.
void setBorderEnabled(bool enabled)
Set whether to draw a border.
Scene graph node for a shadowed texture source.
QML_ELEMENTQQuickItem * source
This property holds the source item that will get rendered with the shadow.
Q_EMITQ_EMIT
virtual QRectF boundingRect() const const
bool isEnabled() const const
QQuickItem * parentItem() const const
QSizeF size() const const
virtual QSGTextureProvider * textureProvider() const const
void update()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:05:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.