Kirigami2

shadowedtexture.cpp
1 /*
2  * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <[email protected]>
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 #if QT_CONFIG(opengl) || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
14 #include "scenegraph/shadowedtexturenode.h"
15 #endif
16 
17 ShadowedTexture::ShadowedTexture(QQuickItem *parentItem)
18  : ShadowedRectangle(parentItem)
19 {
20 }
21 
22 ShadowedTexture::~ShadowedTexture()
23 {
24 }
25 
27 {
28  return m_source;
29 }
30 
31 void ShadowedTexture::setSource(QQuickItem *newSource)
32 {
33  if (newSource == m_source) {
34  return;
35  }
36 
37  m_source = newSource;
38  m_sourceChanged = true;
39  if (m_source && !m_source->parentItem()) {
40  m_source->setParentItem(this);
41  }
42 
43  if (!isSoftwareRendering()) {
44  update();
45  }
46  Q_EMIT sourceChanged();
47 }
48 
49 QSGNode *ShadowedTexture::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *data)
50 {
51  Q_UNUSED(data)
52 #if QT_CONFIG(opengl) || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
53 
54  auto shadowNode = static_cast<ShadowedRectangleNode *>(node);
55 
56  if (!shadowNode || m_sourceChanged) {
57  m_sourceChanged = false;
58  delete shadowNode;
59  if (m_source) {
60  shadowNode = new ShadowedTextureNode{};
61  } else {
62  shadowNode = new ShadowedRectangleNode{};
63  }
64 
65  if (qEnvironmentVariableIsSet("KIRIGAMI_LOWPOWER_HARDWARE")) {
66  shadowNode->setShaderType(ShadowedRectangleMaterial::ShaderType::LowPower);
67  }
68  }
69 
70  shadowNode->setBorderEnabled(border()->isEnabled());
71  shadowNode->setRect(boundingRect());
72  shadowNode->setSize(shadow()->size());
73  shadowNode->setRadius(corners()->toVector4D(radius()));
74  shadowNode->setOffset(QVector2D{float(shadow()->xOffset()), float(shadow()->yOffset())});
75  shadowNode->setColor(color());
76  shadowNode->setShadowColor(shadow()->color());
77  shadowNode->setBorderWidth(border()->width());
78  shadowNode->setBorderColor(border()->color());
79 
80  if (m_source) {
81  static_cast<ShadowedTextureNode *>(shadowNode)->setTextureSource(m_source->textureProvider());
82  }
83 
84  shadowNode->updateGeometry();
85  return shadowNode;
86 #else
87  Q_UNUSED(node)
88  return nullptr;
89 #endif
90 }
Scene graph node for a shadowed rectangle.
qreal width
This property holds the border's width in pixels.
ShadowGroup shadow
This property holds the shadow's grouped property.
Q_EMITQ_EMIT
QColor color
This property holds the shadow's color.
virtual QSGTextureProvider * textureProvider() const const
A rectangle with a shadow behind it.
qreal size
This property holds the shadow's approximate size in pixels.
void update()
void updateGeometry()
Update the geometry for this node.
QQuickItem * parentItem() const const
QQuickItem source
This property holds the source item that will get rendered with the shadow.
QColor color
This property holds the border's color.
BorderGroup border
This property holds the border's grouped property.
Scene graph node for a shadowed texture source.
qreal radius
This property holds the radii of the rectangle's corners.
QColor color
This property holds the rectangle's color.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.