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 if (
const QQuickShapeLinearGradient *g = qobject_cast<
const QQuickShapeLinearGradient *>(gradient)) {
130 QLinearGradient painterGradient(g->x1(), g->y1(), g->x2(), g->y2());
131 setupPainterGradient(&painterGradient, *g);
132 return QBrush(painterGradient);
133 }
else if (
const QQuickShapeRadialGradient *g = qobject_cast<
const QQuickShapeRadialGradient *>(gradient)) {
134 QRadialGradient painterGradient(g->centerX(), g->centerY(), g->centerRadius(),
135 g->focalX(), g->focalY(), g->focalRadius());
136 setupPainterGradient(&painterGradient, *g);
137 return QBrush(painterGradient);
138 }
else if (
const QQuickShapeConicalGradient *g = qobject_cast<
const QQuickShapeConicalGradient *>(gradient)) {
139 QConicalGradient painterGradient(g->centerX(), g->centerY(), g->angle());
140 setupPainterGradient(&painterGradient, *g);
141 return QBrush(painterGradient);
143 return QBrush(color);
149 ShapePathGuiData &d(m_sp[index]);
150 d.brush = copyGradient(gradient, d.fillColor);
157 ShapePathGuiData &d(m_sp[index]);
158 d.pen.setBrush(copyGradient(gradient, d.pen.color()));
166 Q_UNUSED(textureProviderItem);
177 ShapePathGuiData &d(m_sp[index]);
178 if (!(transform.isIdentity() && d.brush.transform().isIdentity()))
179 d.brush.setTransform(transform.matrix().toTransform());
186 ShapePathGuiData &d(m_sp[index]);
187 d.triangulationScale = scale;
207 const int count = m_sp.size();
208 const bool listChanged = m_accDirty &
DirtyList;
210 m_node->m_sp.resize(count);
212 m_node->m_boundingRect = QRectF();
214 for (
int i = 0; i < count; ++i) {
215 ShapePathGuiData &src(m_sp[i]);
218 if (listChanged || (src.dirty &
DirtyPath)) {
220 dst.path.setFillRule(src.fillRule);
224 dst.path.setFillRule(src.fillRule);
226 if (listChanged || (src.dirty &
DirtyPen)) {
228 dst.strokeWidth = src.strokeWidth;
229 dst.triangulationScale = src.triangulationScale;
233 dst.brush = src.brush;
237 QRectF br = dst.path.boundingRect();
238 float sw = qMax(1.0f, dst.strokeWidth);
239 if (dst.pen.isCosmetic())
240 sw *= 2.0f / dst.triangulationScale;
241 br.adjust(-sw, -sw, sw, sw);
242 m_node->m_boundingRect |= br;
245 m_node->markDirty(QSGNode::DirtyMaterial);
268 QSGRendererInterface *rif = m_item->window()->rendererInterface();
269 QPainter *p =
static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource));
272 const QRegion *clipRegion = state->clipRegion();
273 if (clipRegion && !clipRegion->isEmpty())
274 p->setClipRegion(*clipRegion, Qt::ReplaceClip);
276 p->setTransform(matrix()->toTransform());
277 p->setOpacity(inheritedOpacity());
279 for (
const ShapePathRenderData &d : std::as_const(m_sp)) {
280 p->setPen(d.strokeWidth > 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen);
281 p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush);
293 return BoundedRectRendering;
298 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 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)