summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2017-05-09 12:15:52 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-05-15 22:55:06 +0000
commit5dc0e4b2857ea279c9481b03e73ebe9b82228197 (patch)
treee0be55191b03e296d53164f2e0c06fabf1505f20 /src/gui/painting
parent8eccd1b0ad4073a548d8ee6343659525c0ccc5bb (diff)
Simplify code by factoring out brush transformation for gradients
Emulation of non-logical coordinate mode gradients was implemented by essentially 3 x 2 repetitions of the same manipulation of the QBrush transform. Avoid the code duplication by extracting a common method. Add lancelot test scripts that excersizes these code paths. Change-Id: I7baa921923231ef9e83e443dba996b82b32ad1e7 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qemulationpaintengine.cpp84
1 files changed, 33 insertions, 51 deletions
diff --git a/src/gui/painting/qemulationpaintengine.cpp b/src/gui/painting/qemulationpaintengine.cpp
index 586b71557e..e6686e3721 100644
--- a/src/gui/painting/qemulationpaintengine.cpp
+++ b/src/gui/painting/qemulationpaintengine.cpp
@@ -72,6 +72,14 @@ QPainterState *QEmulationPaintEngine::createState(QPainterState *orig) const
return real_engine->createState(orig);
}
+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);
+}
+
void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
{
QPainterState *s = state();
@@ -84,26 +92,14 @@ void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
Qt::BrushStyle style = qbrush_style(brush);
if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
- const QGradient *g = brush.gradient();
-
- if (g->coordinateMode() > QGradient::LogicalMode) {
- if (g->coordinateMode() == QGradient::StretchToDeviceMode) {
- QBrush copy = brush;
- QTransform mat = copy.transform();
- mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
- copy.setTransform(mat);
- real_engine->fill(path, copy);
- return;
- } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
- QBrush copy = brush;
- QTransform mat = copy.transform();
- QRectF r = path.controlPointRect();
- mat.translate(r.x(), r.y());
- mat.scale(r.width(), r.height());
- copy.setTransform(mat);
- real_engine->fill(path, copy);
- return;
- }
+ QGradient::CoordinateMode coMode = brush.gradient()->coordinateMode();
+ 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());
+ combineXForm(&copy, r);
+ real_engine->fill(path, copy);
+ return;
}
}
@@ -124,27 +120,15 @@ void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen)
QBrush brush = pen.brush();
QPen copy = pen;
Qt::BrushStyle style = qbrush_style(brush);
- if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
- const QGradient *g = brush.gradient();
-
- if (g->coordinateMode() > QGradient::LogicalMode) {
- if (g->coordinateMode() == QGradient::StretchToDeviceMode) {
- QTransform mat = brush.transform();
- mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
- brush.setTransform(mat);
- copy.setBrush(brush);
- real_engine->stroke(path, copy);
- return;
- } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
- QTransform mat = brush.transform();
- QRectF r = path.controlPointRect();
- mat.translate(r.x(), r.y());
- mat.scale(r.width(), r.height());
- brush.setTransform(mat);
- copy.setBrush(brush);
- real_engine->stroke(path, copy);
- return;
- }
+ if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern ) {
+ 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());
+ combineXForm(&brush, r);
+ copy.setBrush(brush);
+ real_engine->stroke(path, copy);
+ return;
}
}
@@ -179,18 +163,16 @@ void QEmulationPaintEngine::drawTextItem(const QPointF &p, const QTextItem &text
QGradient g = *s->pen.brush().gradient();
if (g.coordinateMode() > QGradient::LogicalMode) {
- QTransform mat = s->pen.brush().transform();
- if (g.coordinateMode() == QGradient::StretchToDeviceMode) {
- mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
- } else if (g.coordinateMode() == QGradient::ObjectBoundingMode) {
- const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
- QRectF r(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
- mat.translate(r.x(), r.y());
- mat.scale(r.width(), r.height());
- }
+ 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());
+ combineXForm(&copy, r);
g.setCoordinateMode(QGradient::LogicalMode);
QBrush brush(g);
- brush.setTransform(mat);
+ brush.setTransform(copy.transform());
s->pen.setBrush(brush);
penChanged();
real_engine->drawTextItem(p, textItem);