6#include <private/qquickpath_p_p.h>
12 if (m_sp.size() != totalCount) {
13 m_sp.resize(totalCount);
17 *countChanged =
false;
23 ShapePathGuiData &d(m_sp[index]);
31 ShapePathGuiData &d(m_sp[index]);
32 d.pen.setColor(color);
39 ShapePathGuiData &d(m_sp[index]);
49 ShapePathGuiData &d(m_sp[index]);
57 ShapePathGuiData &d(m_sp[index]);
59 d.brush.setColor(color);
66 ShapePathGuiData &d(m_sp[index]);
74 ShapePathGuiData &d(m_sp[index]);
75 d.fillRule = Qt::FillRule(fillRule);
82 ShapePathGuiData &d(m_sp[index]);
83 d.pen.setJoinStyle(Qt::PenJoinStyle(joinStyle));
84 d.pen.setMiterLimit(miterLimit);
91 ShapePathGuiData &d(m_sp[index]);
92 d.pen.setCapStyle(Qt::PenCapStyle(capStyle));
98 qreal dashOffset,
const QList<qreal> &dashPattern)
100 ShapePathGuiData &d(m_sp[index]);
101 switch (strokeStyle) {
102 case QQuickShapePath::SolidLine:
103 d.pen.setStyle(Qt::SolidLine);
105 case QQuickShapePath::DashLine:
106 d.pen.setStyle(Qt::CustomDashLine);
107 d.pen.setDashPattern(dashPattern);
108 d.pen.setDashOffset(dashOffset);
119 painterGradient->setStops(g.gradientStops());
120 switch (g.spread()) {
121 case QQuickShapeGradient::PadSpread:
122 painterGradient->setSpread(QGradient::PadSpread);
124 case QQuickShapeGradient::RepeatSpread:
125 painterGradient->setSpread(QGradient::RepeatSpread);
127 case QQuickShapeGradient::ReflectSpread:
128 painterGradient->setSpread(QGradient::ReflectSpread);
137 if (
const QQuickShapeLinearGradient *g = qobject_cast<
const QQuickShapeLinearGradient *>(gradient)) {
138 QLinearGradient painterGradient(g->x1(), g->y1(), g->x2(), g->y2());
139 setupPainterGradient(&painterGradient, *g);
140 return QBrush(painterGradient);
141 }
else if (
const QQuickShapeRadialGradient *g = qobject_cast<
const QQuickShapeRadialGradient *>(gradient)) {
142 QRadialGradient painterGradient(g->centerX(), g->centerY(), g->centerRadius(),
143 g->focalX(), g->focalY(), g->focalRadius());
144 setupPainterGradient(&painterGradient, *g);
145 return QBrush(painterGradient);
146 }
else if (
const QQuickShapeConicalGradient *g = qobject_cast<
const QQuickShapeConicalGradient *>(gradient)) {
147 QConicalGradient painterGradient(g->centerX(), g->centerY(), g->angle());
148 setupPainterGradient(&painterGradient, *g);
149 return QBrush(painterGradient);
151 return QBrush(color);
157 ShapePathGuiData &d(m_sp[index]);
158 d.brush = copyGradient(gradient, d.fillColor);
165 ShapePathGuiData &d(m_sp[index]);
166 d.pen.setBrush(copyGradient(gradient, d.pen.color()));
174 Q_UNUSED(textureProviderItem);
185 ShapePathGuiData &d(m_sp[index]);
186 if (!(transform.isIdentity() && d.brush.transform().isIdentity()))
187 d.brush.setTransform(transform.matrix().toTransform());
194 ShapePathGuiData &d(m_sp[index]);
195 d.triangulationScale = scale;
215 const int count = m_sp.size();
216 const bool listChanged = m_accDirty &
DirtyList;
218 m_node->m_sp.resize(count);
220 m_node->m_boundingRect = QRectF();
222 for (
int i = 0; i < count; ++i) {
223 ShapePathGuiData &src(m_sp[i]);
226 if (listChanged || (src.dirty &
DirtyPath)) {
228 dst.path.setFillRule(src.fillRule);
232 dst.path.setFillRule(src.fillRule);
234 if (listChanged || (src.dirty &
DirtyPen)) {
236 dst.strokeWidth = src.strokeWidth;
237 dst.triangulationScale = src.triangulationScale;
241 dst.brush = src.brush;
244 dst.visible = src.visible;
251 QRectF br = dst.path.boundingRect();
252 float sw = qMax(1.0f, dst.strokeWidth);
253 if (dst.pen.isCosmetic())
254 sw *= 2.0f / dst.triangulationScale;
255 br.adjust(-sw, -sw, sw, sw);
256 m_node->m_boundingRect |= br;
259 m_node->markDirty(QSGNode::DirtyMaterial);
282 QSGRendererInterface *rif = m_item->window()->rendererInterface();
283 QPainter *p =
static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource));
286 const QRegion *clipRegion = state->clipRegion();
287 if (clipRegion && !clipRegion->isEmpty())
288 p->setClipRegion(*clipRegion, Qt::ReplaceClip);
290 p->setTransform(matrix()->toTransform());
291 p->setOpacity(inheritedOpacity());
293 for (
const ShapePathRenderData &d : std::as_const(m_sp)) {
296 p->setPen(d.strokeWidth > 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen);
297 p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush);
309 return BoundedRectRendering;
314 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 setStrokeGradient(int index, QQuickShapeGradient *gradient) override
void setFillColor(int index, const QColor &color) override
void setTriangulationScale(int index, qreal scale) override
void setVisible(int index, bool visible) override
void handleSceneChange(QQuickWindow *window) override
void endSync(bool async) override
void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override
void beginSync(int totalCount, bool *countChanged) override
void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QList< qreal > &dashPattern) override
void setCosmeticStroke(int index, bool c) 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
Combined button and popup list for selecting options.
static QBrush copyGradient(const QQuickShapeGradient *gradient, const QColor &color)
static void setupPainterGradient(QGradient *painterGradient, const QQuickShapeGradient &g)