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();
226void ShadowedRectangle::setRadius(qreal newRadius)
228 if (newRadius == m_radius) {
232 m_radius = newRadius;
233 if (!isSoftwareRendering()) {
244void ShadowedRectangle::setColor(
const QColor &newColor)
246 if (newColor == m_color) {
251 if (!isSoftwareRendering()) {
262void ShadowedRectangle::setRenderType(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)
309 auto shadowNode =
static_cast<ShadowedRectangleNode *
>(node);
312 shadowNode =
new ShadowedRectangleNode{};
315 static bool lowPower = QByteArrayList{
"1",
"true"}.contains(qgetenv(
"KIRIGAMI_LOWPOWER_HARDWARE").toLower());
317 shadowNode->setShaderType(ShadowedRectangleMaterial::ShaderType::LowPower);
321 shadowNode->setBorderEnabled(m_border->isEnabled());
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()) {
337 m_softwareItem =
new PaintedRectangleItem{
this};
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.
QColor color
This property holds the rectangle's color.
RenderType renderType
This property holds the rectangle's render mode.
RenderType
Available rendering types for ShadowedRectangle.
@ LowQuality
Use the lowest rendering quality, even if the hardware could handle higher quality rendering.
@ Software
Always use software rendering for this rectangle.
@ Auto
Automatically determine the optimal rendering type.
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.
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)
QQuickWindow * window() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)