summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qemulationpaintengine.cpp
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2017-08-04 16:22:23 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2018-06-22 10:42:33 +0000
commitf5fe9fc5a4136a696f07c4bd3567d85348ec42d9 (patch)
treecbfd3a39c9eeaa5ae11a8469bcd5431bedc06f77 /src/gui/painting/qemulationpaintengine.cpp
parent99d4f0026f90681974f6fd1d23941e5b69024796 (diff)
Add ObjectMode coordinate mode to QGradient
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ø <tor.arne.vestbo@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/gui/painting/qemulationpaintengine.cpp')
-rw-r--r--src/gui/painting/qemulationpaintengine.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/gui/painting/qemulationpaintengine.cpp b/src/gui/painting/qemulationpaintengine.cpp
index 49ecd3b318..638834ef3b 100644
--- a/src/gui/painting/qemulationpaintengine.cpp
+++ b/src/gui/painting/qemulationpaintengine.cpp
@@ -74,10 +74,11 @@ QPainterState *QEmulationPaintEngine::createState(QPainterState *orig) const
static inline void combineXForm(QBrush *brush, const QRectF &r)
{
- QTransform t = brush->transform();
- t.translate(r.x(), r.y());
- t.scale(r.width(), r.height());
- brush->setTransform(t);
+ QTransform t(r.width(), 0, 0, r.height(), r.x(), r.y());
+ if (brush->gradient()->coordinateMode() == QGradient::ObjectMode)
+ brush->setTransform(brush->transform() * t);
+ else
+ brush->setTransform(t * brush->transform());
}
void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
@@ -96,7 +97,7 @@ void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
if (coMode > QGradient::LogicalMode) {
QBrush copy = brush;
const QPaintDevice *d = real_engine->painter()->device();
- QRectF r = (coMode == QGradient::ObjectBoundingMode) ? path.controlPointRect() : QRectF(0, 0, d->width(), d->height());
+ QRectF r = (coMode == QGradient::StretchToDeviceMode) ? QRectF(0, 0, d->width(), d->height()) : path.controlPointRect();
combineXForm(&copy, r);
real_engine->fill(path, copy);
return;
@@ -132,7 +133,7 @@ void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen)
QGradient::CoordinateMode coMode = brush.gradient()->coordinateMode();
if (coMode > QGradient::LogicalMode) {
const QPaintDevice *d = real_engine->painter()->device();
- QRectF r = (coMode == QGradient::ObjectBoundingMode) ? path.controlPointRect() : QRectF(0, 0, d->width(), d->height());
+ QRectF r = (coMode == QGradient::StretchToDeviceMode) ? QRectF(0, 0, d->width(), d->height()) : path.controlPointRect();
combineXForm(&brush, r);
copy.setBrush(brush);
real_engine->stroke(path, copy);
@@ -174,9 +175,9 @@ void QEmulationPaintEngine::drawTextItem(const QPointF &p, const QTextItem &text
QBrush copy = s->pen.brush();
const QPaintDevice *d = real_engine->painter()->device();
const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
- QRectF r = (g.coordinateMode() == QGradient::ObjectBoundingMode) ?
- QRectF(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal()) :
- QRectF(0, 0, d->width(), d->height());
+ QRectF r = (g.coordinateMode() == QGradient::StretchToDeviceMode) ?
+ QRectF(0, 0, d->width(), d->height()) :
+ QRectF(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
combineXForm(&copy, r);
g.setCoordinateMode(QGradient::LogicalMode);
QBrush brush(g);