5#include <private/qquickpath_p_p.h>
11 if (m_sp.size() != totalCount) {
12 m_sp.resize(totalCount);
16 *countChanged =
false;
22 ShapePathGuiData &d(m_sp[index]);
30 ShapePathGuiData &d(m_sp[index]);
31 d.pen.setColor(color);
38 ShapePathGuiData &d(m_sp[index]);
48 ShapePathGuiData &d(m_sp[index]);
56 ShapePathGuiData &d(m_sp[index]);
58 d.brush.setColor(color);
65 ShapePathGuiData &d(m_sp[index]);
66 d.fillRule = Qt::FillRule(fillRule);
73 ShapePathGuiData &d(m_sp[index]);
74 d.pen.setJoinStyle(Qt::PenJoinStyle(joinStyle));
75 d.pen.setMiterLimit(miterLimit);
82 ShapePathGuiData &d(m_sp[index]);
83 d.pen.setCapStyle(Qt::PenCapStyle(capStyle));
89 qreal dashOffset,
const QVector<qreal> &dashPattern)
91 ShapePathGuiData &d(m_sp[index]);
92 switch (strokeStyle) {
93 case QQuickShapePath::SolidLine:
94 d.pen.setStyle(Qt::SolidLine);
96 case QQuickShapePath::DashLine:
97 d.pen.setStyle(Qt::CustomDashLine);
98 d.pen.setDashPattern(dashPattern);
99 d.pen.setDashOffset(dashOffset);
110 painterGradient->setStops(g.gradientStops());
111 switch (g.spread()) {
112 case QQuickShapeGradient::PadSpread:
113 painterGradient->setSpread(QGradient::PadSpread);
115 case QQuickShapeGradient::RepeatSpread:
116 painterGradient->setSpread(QGradient::RepeatSpread);
118 case QQuickShapeGradient::ReflectSpread:
119 painterGradient->setSpread(QGradient::ReflectSpread);
128 ShapePathGuiData &d(m_sp[index]);
129 if (QQuickShapeLinearGradient *g = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
130 QLinearGradient painterGradient(g->x1(), g->y1(), g->x2(), g->y2());
131 setupPainterGradient(&painterGradient, *g);
132 d.brush = QBrush(painterGradient);
133 }
else if (QQuickShapeRadialGradient *g = qobject_cast<QQuickShapeRadialGradient *>(gradient)) {
134 QRadialGradient painterGradient(g->centerX(), g->centerY(), g->centerRadius(),
135 g->focalX(), g->focalY(), g->focalRadius());
136 setupPainterGradient(&painterGradient, *g);
137 d.brush = QBrush(painterGradient);
138 }
else if (QQuickShapeConicalGradient *g = qobject_cast<QQuickShapeConicalGradient *>(gradient)) {
139 QConicalGradient painterGradient(g->centerX(), g->centerY(), g->angle());
140 setupPainterGradient(&painterGradient, *g);
141 d.brush = QBrush(painterGradient);
143 d.brush = QBrush(d.fillColor);
152 Q_UNUSED(textureProviderItem);
163 ShapePathGuiData &d(m_sp[index]);
164 if (!(transform.isIdentity() && d.brush.transform().isIdentity()))
165 d.brush.setTransform(transform.matrix().toTransform());
172 m_triangulationScale = scale;
190 const int count = m_sp.size();
191 const bool listChanged = m_accDirty &
DirtyList;
193 m_node->m_sp.resize(count);
195 m_node->m_boundingRect = QRectF();
197 for (
int i = 0; i < count; ++i) {
198 ShapePathGuiData &src(m_sp[i]);
201 if (listChanged || (src.dirty &
DirtyPath)) {
203 dst.path.setFillRule(src.fillRule);
207 dst.path.setFillRule(src.fillRule);
209 if (listChanged || (src.dirty &
DirtyPen)) {
211 dst.strokeWidth = src.strokeWidth;
215 dst.brush = src.brush;
219 QRectF br = dst.path.boundingRect();
220 float sw = qMax(1.0f, dst.strokeWidth);
221 if (dst.pen.isCosmetic())
222 sw *= 2.0f / m_triangulationScale;
223 br.adjust(-sw, -sw, sw, sw);
224 m_node->m_boundingRect |= br;
227 m_node->markDirty(QSGNode::DirtyMaterial);
250 QSGRendererInterface *rif = m_item->window()->rendererInterface();
251 QPainter *p =
static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource));
254 const QRegion *clipRegion = state->clipRegion();
255 if (clipRegion && !clipRegion->isEmpty())
256 p->setClipRegion(*clipRegion, Qt::ReplaceClip);
258 p->setTransform(matrix()->toTransform());
259 p->setOpacity(inheritedOpacity());
261 for (
const ShapePathRenderData &d : std::as_const(m_sp)) {
262 p->setPen(d.strokeWidth > 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen);
263 p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush);
275 return BoundedRectRendering;
280 return m_boundingRect;
RenderingFlags flags() const override
QRectF rect() const override
void releaseResources() override
This function is called when all custom graphics resources allocated by this node have to be freed im...
~QQuickShapeSoftwareRenderNode()
void render(const RenderState *state) override
This function is called by the renderer and should paint this node with directly invoking commands vi...
QQuickShapeSoftwareRenderNode(QQuickShape *item)
StateFlags changedStates() const override
This function should return a mask where each bit represents graphics states changed by the \l render...
void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints={}) override
void setStrokeColor(int index, const QColor &color) override
void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override
void setFillColor(int index, const QColor &color) override
void handleSceneChange(QQuickWindow *window) override
void endSync(bool async) override
void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QVector< qreal > &dashPattern) override
void beginSync(int totalCount, bool *countChanged) override
void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override
void setCosmeticStroke(int index, bool c) override
void setTriangulationScale(qreal scale) override
void setFillGradient(int index, QQuickShapeGradient *gradient) override
void updateNode() override
void setFillRule(int index, QQuickShapePath::FillRule fillRule) override
void setStrokeWidth(int index, qreal w) override
void setFillTransform(int index, const QSGTransform &transform) override
static void setupPainterGradient(QGradient *painterGradient, const QQuickShapeGradient &g)