7#include "shadowedrectangle.h"
10#include <QSGRectangleNode>
11#include <QSGRendererInterface>
13#include "scenegraph/paintedrectangleitem.h"
14#include "scenegraph/shadowedrectanglenode.h"
16BorderGroup::BorderGroup(
QObject *parent)
26void BorderGroup::setWidth(qreal newWidth)
28 if (newWidth == m_width) {
41void BorderGroup::setColor(
const QColor &newColor)
43 if (newColor == m_color) {
51ShadowGroup::ShadowGroup(
QObject *parent)
61void ShadowGroup::setSize(qreal newSize)
63 if (newSize == m_size) {
76void ShadowGroup::setXOffset(qreal newXOffset)
78 if (newXOffset == m_xOffset) {
82 m_xOffset = newXOffset;
91void ShadowGroup::setYOffset(qreal newYOffset)
93 if (newYOffset == m_yOffset) {
97 m_yOffset = newYOffset;
106void ShadowGroup::setColor(
const QColor &newColor)
108 if (newColor == m_color) {
116CornersGroup::CornersGroup(
QObject *parent)
121qreal CornersGroup::topLeft()
const
126void CornersGroup::setTopLeft(qreal newTopLeft)
128 if (newTopLeft == m_topLeft) {
132 m_topLeft = newTopLeft;
136qreal CornersGroup::topRight()
const
141void CornersGroup::setTopRight(qreal newTopRight)
143 if (newTopRight == m_topRight) {
147 m_topRight = newTopRight;
151qreal CornersGroup::bottomLeft()
const
156void CornersGroup::setBottomLeft(qreal newBottomLeft)
158 if (newBottomLeft == m_bottomLeft) {
162 m_bottomLeft = newBottomLeft;
166qreal CornersGroup::bottomRight()
const
168 return m_bottomRight;
171void CornersGroup::setBottomRight(qreal newBottomRight)
173 if (newBottomRight == m_bottomRight) {
177 m_bottomRight = newBottomRight;
181QVector4D CornersGroup::toVector4D(
float all)
const
183 return QVector4D{m_bottomRight < 0.0 ? all : m_bottomRight,
184 m_topRight < 0.0 ? all : m_topRight,
185 m_bottomLeft < 0.0 ? all : m_bottomLeft,
186 m_topLeft < 0.0 ? all : m_topLeft};
189ShadowedRectangle::ShadowedRectangle(
QQuickItem *parentItem)
202ShadowedRectangle::~ShadowedRectangle()
208 return m_border.get();
213 return m_shadow.get();
218 return m_corners.get();
221qreal ShadowedRectangle::radius()
const
226void ShadowedRectangle::setRadius(qreal newRadius)
228 if (newRadius == m_radius) {
232 m_radius = newRadius;
233 if (!isSoftwareRendering()) {
239QColor ShadowedRectangle::color()
const
244void ShadowedRectangle::setColor(
const QColor &newColor)
246 if (newColor == m_color) {
251 if (!isSoftwareRendering()) {
257ShadowedRectangle::RenderType ShadowedRectangle::renderType()
const
262void ShadowedRectangle::setRenderType(RenderType renderType)
264 if (renderType == m_renderType) {
267 m_renderType = renderType;
269 Q_EMIT renderTypeChanged();
272void ShadowedRectangle::componentComplete()
279bool ShadowedRectangle::isSoftwareRendering()
const
286 return m_softwareItem;
294 Q_EMIT softwareRenderingChanged();
300QSGNode *ShadowedRectangle::updatePaintNode(
QSGNode *node, QQuickItem::UpdatePaintNodeData *data)
315 static bool lowPower =
QByteArrayList{
"1",
"true"}.
contains(qgetenv(
"KIRIGAMI_LOWPOWER_HARDWARE").toLower());
316 if (m_renderType == RenderType::LowQuality || (m_renderType == RenderType::Auto && lowPower)) {
317 shadowNode->setShaderType(ShadowedRectangleMaterial::ShaderType::LowPower);
323 shadowNode->setSize(m_shadow->size());
324 shadowNode->setRadius(m_corners->toVector4D(m_radius));
325 shadowNode->setOffset(
QVector2D{float(m_shadow->xOffset()), float(m_shadow->yOffset())});
326 shadowNode->setColor(m_color);
327 shadowNode->setShadowColor(m_shadow->color());
328 shadowNode->setBorderWidth(m_border->width());
329 shadowNode->setBorderColor(m_border->color());
330 shadowNode->updateGeometry();
334void ShadowedRectangle::checkSoftwareItem()
336 if (!m_softwareItem && isSoftwareRendering()) {
342 m_softwareItem->
setZ(-99.0);
344 auto updateItem = [
this]() {
345 auto borderWidth = m_border->width();
347 m_softwareItem->
setSize(rect.size());
348 m_softwareItem->setColor(m_color);
349 m_softwareItem->setRadius(m_radius);
350 m_softwareItem->setBorderWidth(borderWidth);
351 m_softwareItem->setBorderColor(m_border->color());
358 connect(
this, &ShadowedRectangle::colorChanged, m_softwareItem, updateItem);
359 connect(
this, &ShadowedRectangle::radiusChanged, m_softwareItem, updateItem);
360 connect(m_border.get(), &BorderGroup::changed, m_softwareItem, updateItem);
365#include "moc_shadowedrectangle.cpp"
Grouped property for rectangle border.
QML_ELEMENTqreal width
This property holds the border's width in pixels.
QColor color
This property holds the border's color.
Grouped property for corner radius.
A rectangle with a border and rounded corners, rendered through QPainter.
Grouped property for the rectangle's shadow.
qreal xOffset
This property holds the shadow's offset in pixels on the X axis.
QColor color
This property holds the shadow's color.
qreal yOffset
This property holds the shadow's offset in pixels on the Y axis.
QML_ELEMENTqreal size
This property holds the shadow's approximate size in pixels.
Scene graph node for a shadowed rectangle.
void setBorderEnabled(bool enabled)
Set whether to draw a border.
bool contains(const AT &value) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual QRectF boundingRect() const const
virtual void componentComplete() override
virtual void itemChange(ItemChange change, const ItemChangeData &value)
void setFlag(Flag flag, bool enabled)
void setSize(const QSizeF &size)
QQuickWindow * window() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)