aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickvectorimage/generator/qquickitemgenerator.cpp
diff options
context:
space:
mode:
authorHatem ElKharashy <hatem.elkharashy@qt.io>2024-03-28 15:58:50 +0200
committerHatem ElKharashy <hatem.elkharashy@qt.io>2024-04-18 15:42:40 +0300
commit5ce8fd73430c86cc0b52f8eaf5dbfc000605b6a0 (patch)
tree3c96e65750bbbdba59faa9bfad112fbc4133401a /src/quickvectorimage/generator/qquickitemgenerator.cpp
parentf1051cb48243ab27a44ec4f30259fa38116c2783 (diff)
VectorImage: tweak the default pen and fix opacity behavior
There are many changes done in this commit, which either prepare the generator for features implemented in the future or fix the current behavior. The default QPen in the style resolver class is changed to match the default QPen used by Qt Svg module, because this default pen sets the CapStyle and JoinStyle. This is going to be important when implementing those features in VectorImage. There were also some issues with the opacity for several reasons. The first one was because "transparent" color was not taken into account. This is not part of the SVG standard, but the browsers, as well as Qt Svg, implements it anyway. Although we get the correct color from style resolver, the currentFillColor function overrides the opacity with the fillOpacity from the extra states. Finally, this takes us to the other issue with opacity. The fill and stroke attributes define an RGB color or a paint server like gradients. The opacity can be controlled on those using fill-opacity and stroke-opacity. Those opacities can be applied on gradient as well and not only on normal colors. This change adds new member variables in the NodeInfo structs to handle the fillOpacity and strokeOpacity. Change-Id: I267126aecbab488700f6f7490634341893b21a1c Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/quickvectorimage/generator/qquickitemgenerator.cpp')
-rw-r--r--src/quickvectorimage/generator/qquickitemgenerator.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/quickvectorimage/generator/qquickitemgenerator.cpp b/src/quickvectorimage/generator/qquickitemgenerator.cpp
index c939ffccd7..1917c53013 100644
--- a/src/quickvectorimage/generator/qquickitemgenerator.cpp
+++ b/src/quickvectorimage/generator/qquickitemgenerator.cpp
@@ -123,12 +123,12 @@ void QQuickItemGenerator::outputShapePath(const PathNodeInfo &info, const QPaint
Q_UNUSED(pathSelector)
Q_ASSERT(painterPath || quadPath);
- QString penName = info.strokeColor;
- const bool noPen = penName.isEmpty() || penName == u"transparent";
+ const bool noPen = info.strokeColor == QColorConstants::Transparent;
if (pathSelector == QQuickVectorImageGenerator::StrokePath && noPen)
return;
- const bool noFill = info.grad.type() == QGradient::NoGradient && info.fillColor == u"transparent";
+ const bool noFill = info.grad.type() == QGradient::NoGradient && info.fillColor == QColorConstants::Transparent;
+
if (pathSelector == QQuickVectorImageGenerator::FillPath && noFill)
return;
@@ -145,7 +145,7 @@ void QQuickItemGenerator::outputShapePath(const PathNodeInfo &info, const QPaint
if (noPen || !(pathSelector & QQuickVectorImageGenerator::StrokePath)) {
shapePath->setStrokeColor(Qt::transparent);
} else {
- shapePath->setStrokeColor(QColor::fromString(penName));
+ shapePath->setStrokeColor(info.strokeColor);
shapePath->setStrokeWidth(info.strokeWidth);
}
@@ -156,7 +156,7 @@ void QQuickItemGenerator::outputShapePath(const PathNodeInfo &info, const QPaint
else if (info.grad.type() != QGradient::NoGradient)
generateGradient(&info.grad, shapePath, boundingRect);
else
- shapePath->setFillColor(QColor::fromString(info.fillColor));
+ shapePath->setFillColor(info.fillColor);
shapePath->setFillRule(fillRule);
@@ -179,7 +179,7 @@ void QQuickItemGenerator::generateGradient(const QGradient *grad, QQuickShapePat
if (!shapePath)
return;
- auto setStops = [](QQuickShapeGradient *quickGrad, const QGradientStops &stops) {
+ auto setStops = [=](QQuickShapeGradient *quickGrad, const QGradientStops &stops) {
auto stopsProp = quickGrad->stops();
for (auto &stop : stops) {
auto *stopObj = new QQuickGradientStop(quickGrad);
@@ -281,13 +281,13 @@ void QQuickItemGenerator::generateTextNode(const TextNodeInfo &info)
}
}
- textItem->setColor(QColor::fromString(info.color));
+ textItem->setColor(info.fillColor);
textItem->setTextFormat(info.needsRichText ? QQuickText::RichText : QQuickText::StyledText);
textItem->setText(info.text);
textItem->setFont(info.font);
- if (!info.strokeColor.isEmpty()) {
- textItem->setStyleColor(QColor::fromString(info.strokeColor));
+ if (info.strokeColor != QColorConstants::Transparent) {
+ textItem->setStyleColor(info.strokeColor);
textItem->setStyle(QQuickText::Outline);
}