From f5fe9fc5a4136a696f07c4bd3567d85348ec42d9 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 4 Aug 2017 16:22:23 +0200 Subject: Add ObjectMode coordinate mode to QGradient MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ObjectBoundingMode coordinate mode of QGradient allows specifying the gradient coordinates relative to the object being painted. But if the gradient brush also has a transformation, that transformation is applied in the logical, not object, coordinate space. That behavior is counterintuitive. However, changing it now would break existing code. Instead, we introduce a new coordinate mode enum with the expected behavior, and document the old one as deprecated. This prepares to fix the bugs below in qtsvg, by making it possible to specify the same behavior in Qt as SVG has. [ChangeLog][QtGui][QGradient] Add ObjectMode coordinate mode [ChangeLog][Important Behavior Changes] QDataStream version bumped up to 18 to account for changes in the serialization of QGradient. Task-number: QTBUG-59978 Task-number: QTBUG-67995 Change-Id: I8820a2555359812f3e1a46e37d6ac2cc29a2091d Reviewed-by: Tor Arne Vestbø Reviewed-by: Allan Sandfeld Jensen --- src/gui/painting/qpainter.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/gui/painting/qpainter.cpp') diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 4a18df899e..41e81c5fbe 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -530,7 +530,10 @@ static inline QBrush stretchGradientToUserSpace(const QBrush &brush, const QRect g.setCoordinateMode(QGradient::LogicalMode); QBrush b(g); - b.setTransform(gradientToUser * b.transform()); + if (brush.gradient()->coordinateMode() == QGradient::ObjectMode) + b.setTransform(b.transform() * gradientToUser); + else + b.setTransform(gradientToUser * b.transform()); return b; } @@ -569,7 +572,7 @@ void QPainterPrivate::drawStretchedGradient(const QPainterPath &path, DrawOperat } else { needsFill = true; - if (brushMode == QGradient::ObjectBoundingMode) { + if (brushMode == QGradient::ObjectBoundingMode || brushMode == QGradient::ObjectMode) { Q_ASSERT(engine->hasFeature(QPaintEngine::PatternTransform)); boundingRect = path.boundingRect(); q->setBrush(stretchGradientToUserSpace(brush, boundingRect)); @@ -613,11 +616,11 @@ void QPainterPrivate::drawStretchedGradient(const QPainterPath &path, DrawOperat changedBrush = true; } - if (penMode == QGradient::ObjectBoundingMode) { + if (penMode == QGradient::ObjectBoundingMode || penMode == QGradient::ObjectMode) { Q_ASSERT(engine->hasFeature(QPaintEngine::PatternTransform)); // avoid computing the bounding rect twice - if (!needsFill || brushMode != QGradient::ObjectBoundingMode) + if (!needsFill || (brushMode != QGradient::ObjectBoundingMode && brushMode != QGradient::ObjectMode)) boundingRect = path.boundingRect(); QPen p = pen; @@ -849,8 +852,8 @@ void QPainterPrivate::updateEmulationSpecifier(QPainterState *s) gradientStretch |= (brushMode == QGradient::StretchToDeviceMode); gradientStretch |= (penMode == QGradient::StretchToDeviceMode); - objectBoundingMode |= (brushMode == QGradient::ObjectBoundingMode); - objectBoundingMode |= (penMode == QGradient::ObjectBoundingMode); + objectBoundingMode |= (brushMode == QGradient::ObjectBoundingMode || brushMode == QGradient::ObjectMode); + objectBoundingMode |= (penMode == QGradient::ObjectBoundingMode || penMode == QGradient::ObjectMode); } if (gradientStretch) s->emulationSpecifier |= QGradient_StretchToDevice; @@ -6857,7 +6860,8 @@ static inline bool needsResolving(const QBrush &brush) Qt::BrushStyle s = brush.style(); return ((s == Qt::LinearGradientPattern || s == Qt::RadialGradientPattern || s == Qt::ConicalGradientPattern) && - brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode); + (brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode || + brush.gradient()->coordinateMode() == QGradient::ObjectMode)); } /*! -- cgit v1.2.3