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) {
63 } else {
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"
QML_ELEMENTqreal width
This property holds the border's width in pixels.
QColor color
This property holds the border's color.
QColor color
This property holds the shadow's color.
QML_ELEMENTqreal size
This property holds the shadow's approximate size in pixels.
Scene graph node for a shadowed rectangle.
A rectangle with a shadow behind it.
QColor color
This property holds the rectangle's color.
QML_ELEMENTqreal radius
This property holds the radii of the rectangle's corners.
BorderGroup * border
This property holds the border's grouped property.
ShadowGroup * shadow
This property holds the shadow's grouped property.
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
T qobject_cast(QObject *object)
virtual QRectF boundingRect() const const
QQuickItem * parentItem() 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 May 17 2024 11:49:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.