diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-08-20 10:57:34 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-14 12:57:10 (GMT) |
commit | 7fbffd29e5904151a3a249004031d0502a16f4fc (patch) | |
tree | d06b39d9993a382a01e250e58d8e547a0cd5a436 /src/gui/painting/qpainter.cpp | |
parent | 161f6b4ccdec38c9817672ad977f4d025acb14f4 (diff) | |
download | Qt-7fbffd29e5904151a3a249004031d0502a16f4fc.zip Qt-7fbffd29e5904151a3a249004031d0502a16f4fc.tar.gz Qt-7fbffd29e5904151a3a249004031d0502a16f4fc.tar.bz2 |
Remove font property in QStaticText and fix handling translation on
painter
1. The font property in QStaticText has been removed. Rather than set a
font on the text explicitly, it picks up the font from the painter. If
you change the font on the painter, the text layout will have to be
updated, like with a matrix.
2. The translation might not be the only transformation on the painter,
so rather than translate back to origo, we explicitly set dx and dy
on the transform to 0.0 for the duration of the function.
3. Update test to reflect changes
Diffstat (limited to 'src/gui/painting/qpainter.cpp')
-rw-r--r-- | src/gui/painting/qpainter.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 9ad19f0..c75547f 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5748,15 +5748,28 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static QPointF transformedPosition = position * d->state->matrix; QTransform matrix = d->state->matrix; - // Already added in transformedPosition - if (d->state->matrix.isTranslating()) - translate(-d->state->matrix.dx(), -d->state->matrix.dy()); + // The translation has been applied to transformedPosition. Remove translation + // component from matrix. + if (d->state->matrix.isTranslating()) { + qreal m11 = d->state->matrix.m11(); + qreal m12 = d->state->matrix.m12(); + qreal m13 = d->state->matrix.m13(); + qreal m21 = d->state->matrix.m21(); + qreal m22 = d->state->matrix.m22(); + qreal m23 = d->state->matrix.m23(); + qreal m33 = d->state->matrix.m33(); + + d->state->matrix.setMatrix(m11, m12, m13, + m21, m22, m23, + 0.0, 0.0, m33); + } // If the transform is not identical to the text transform, // we have to relayout the text (for other transformations than plain translation) + bool staticTextNeedsReinit = false; if (staticText_d->matrix != d->state->matrix) { staticText_d->matrix = d->state->matrix; - staticText_d->init(); + staticTextNeedsReinit = true; } bool restoreWhenFinished = false; @@ -5767,15 +5780,15 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static restoreWhenFinished = true; } - // ### Should we pick up the painter's font and recalculate the layout, like we do - // with the matrix? if (font() != staticText_d->font) { - setFont(staticText_d->font); - - save(); - restoreWhenFinished = true; + staticText_d->font = font(); + staticTextNeedsReinit = true; } + // Recreate the layout of the static text because the matrix or font has changed + if (staticTextNeedsReinit) + staticText_d->init(); + for (int i=0; i<staticText_d->itemCount; ++i) { QStaticTextItem *item = staticText_d->items + i; d->extended->drawStaticTextItem(transformedPosition, item); @@ -5785,7 +5798,7 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static restore(); if (matrix.isTranslating()) - setTransform(matrix); + d->state->matrix = matrix; } /*! |