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]);
67 d.fillRule = Qt::FillRule(fillRule);
74 ShapePathGuiData &d(m_sp[index]);
75 d.pen.setJoinStyle(Qt::PenJoinStyle(joinStyle));
76 d.pen.setMiterLimit(miterLimit);
83 ShapePathGuiData &d(m_sp[index]);
84 d.pen.setCapStyle(Qt::PenCapStyle(capStyle));
90 qreal dashOffset,
const QList<qreal> &dashPattern)
92 ShapePathGuiData &d(m_sp[index]);
93 switch (strokeStyle) {
94 case QQuickShapePath::SolidLine:
95 d.pen.setStyle(Qt::SolidLine);
97 case QQuickShapePath::DashLine:
98 d.pen.setStyle(Qt::CustomDashLine);
99 d.pen.setDashPattern(dashPattern);
100 d.pen.setDashOffset(dashOffset);
111 painterGradient->setStops(g.gradientStops());
112 switch (g.spread()) {
113 case QQuickShapeGradient::PadSpread:
114 painterGradient->setSpread(QGradient::PadSpread);
116 case QQuickShapeGradient::RepeatSpread:
117 painterGradient->setSpread(QGradient::RepeatSpread);
119 case QQuickShapeGradient::ReflectSpread:
120 painterGradient->setSpread(QGradient::ReflectSpread);
129 ShapePathGuiData &d(m_sp[index]);
130 if (QQuickShapeLinearGradient *g = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
131 QLinearGradient painterGradient(g->x1(), g->y1(), g->x2(), g->y2());
132 setupPainterGradient(&painterGradient, *g);
133 d.brush = QBrush(painterGradient);
134 }
else if (QQuickShapeRadialGradient *g = qobject_cast<QQuickShapeRadialGradient *>(gradient)) {
135 QRadialGradient painterGradient(g->centerX(), g->centerY(), g->centerRadius(),
136 g->focalX(), g->focalY(), g->focalRadius());
137 setupPainterGradient(&painterGradient, *g);
138 d.brush = QBrush(painterGradient);
139 }
else if (QQuickShapeConicalGradient *g = qobject_cast<QQuickShapeConicalGradient *>(gradient)) {
140 QConicalGradient painterGradient(g->centerX(), g->centerY(), g->angle());
141 setupPainterGradient(&painterGradient, *g);
142 d.brush = QBrush(painterGradient);
144 d.brush = QBrush(d.fillColor);
153 Q_UNUSED(textureProviderItem);
164 ShapePathGuiData &d(m_sp[index]);
165 if (!(transform.isIdentity() && d.brush.transform().isIdentity()))
166 d.brush.setTransform(transform.matrix().toTransform());
173 ShapePathGuiData &d(m_sp[index]);
174 d.triangulationScale = scale;
194 const int count = m_sp.size();
195 const bool listChanged = m_accDirty &
DirtyList;
197 m_node->m_sp.resize(count);
199 m_node->m_boundingRect = QRectF();
201 for (
int i = 0; i < count; ++i) {
202 ShapePathGuiData &src(m_sp[i]);
205 if (listChanged || (src.dirty &
DirtyPath)) {
207 dst.path.setFillRule(src.fillRule);
211 dst.path.setFillRule(src.fillRule);
213 if (listChanged || (src.dirty &
DirtyPen)) {
215 dst.strokeWidth = src.strokeWidth;
216 dst.triangulationScale = src.triangulationScale;
220 dst.brush = src.brush;
224 QRectF br = dst.path.boundingRect();
225 float sw = qMax(1.0f, dst.strokeWidth);
226 if (dst.pen.isCosmetic())
227 sw *= 2.0f / dst.triangulationScale;
228 br.adjust(-sw, -sw, sw, sw);
229 m_node->m_boundingRect |= br;
232 m_node->markDirty(QSGNode::DirtyMaterial);
255 QSGRendererInterface *rif = m_item->window()->rendererInterface();
256 QPainter *p =
static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource));
259 const QRegion *clipRegion = state->clipRegion();
260 if (clipRegion && !clipRegion->isEmpty())
261 p->setClipRegion(*clipRegion, Qt::ReplaceClip);
263 p->setTransform(matrix()->toTransform());
264 p->setOpacity(inheritedOpacity());
266 for (
const ShapePathRenderData &d : std::as_const(m_sp)) {
267 p->setPen(d.strokeWidth > 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen);
268 p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush);
280 return BoundedRectRendering;
285 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 setTriangulationScale(int index, qreal scale) 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 void setupPainterGradient(QGradient *painterGradient, const QQuickShapeGradient &g)