From 0148243a77a42de1ba6170a1da3977b3026c1927 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 13 Feb 2019 14:08:49 +0100 Subject: Canvas: Handle switching between object and string based colors When switching between the two it should respect whatever the color is regardless of whether it is a color value or a string based color. This also accounts for "invalid" colors as this should set the stroke-style to be #000000 to be inline with the default stroke-style indicated in the specification. Change-Id: I00bee6c9a85787762271882838510b4187798ee0 Fixes: QTBUG-42155 Fixes: QTBUG-52959 Reviewed-by: Mitch Curtis --- src/quick/items/context2d/qquickcontext2d.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index 66727e7845..57e697bdd1 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -1548,7 +1548,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_strokeStyle(const QV4::Function if (value->as()) { QColor color = scope.engine->toVariant(value, qMetaTypeId()).value(); if (color.isValid()) { - r->d()->context()->state.fillStyle = color; + r->d()->context()->state.strokeStyle = color; r->d()->context()->buffer()->setStrokeStyle(color); r->d()->context()->m_strokeStyle.set(scope.engine, value); } else { @@ -1559,7 +1559,12 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_strokeStyle(const QV4::Function r->d()->context()->m_strokeStyle.set(scope.engine, value); r->d()->context()->state.strokePatternRepeatX = style->d()->patternRepeatX; r->d()->context()->state.strokePatternRepeatY = style->d()->patternRepeatY; - + } else if (!style && r->d()->context()->state.strokeStyle != QBrush(QColor())) { + // If there is no style object, then ensure that the strokeStyle is at least + // QColor in case it was previously set + r->d()->context()->state.strokeStyle = QBrush(QColor()); + r->d()->context()->buffer()->setStrokeStyle(r->d()->context()->state.strokeStyle); + r->d()->context()->m_strokeStyle.set(scope.engine, value); } } } else if (value->isString()) { -- cgit v1.2.3