From bbdee08472a0763ed9a60ce60f60ddb86bd946df Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 19 Feb 2010 16:02:56 +0100 Subject: Fix fallback for QStaticText when it's unsupported in paint engine When the paint engine does not support QStaticText, we fall back to regular drawText() calls. This fallback would previously paint all text to (0, 0). This fixes the qstatictext autotest on Linux. Reviewed-by: Olivier --- src/gui/painting/qpainter.cpp | 2 +- src/gui/text/qstatictext.cpp | 15 +++++++++------ src/gui/text/qstatictext_p.h | 2 +- tests/auto/auto.pro | 1 + tests/auto/qstatictext/tst_qstatictext.cpp | 18 ++++++++++++++++-- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 2cb6915..1b8b718 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5768,7 +5768,7 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static // If we don't have an extended paint engine, or if the painter is projected, // we go through standard code path if (d->extended == 0 || !d->state->matrix.isAffine()) { - staticText_d->paintText(this); + staticText_d->paintText(position, this); return; } diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 7d4181c..a7138b9 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -530,7 +530,7 @@ namespace { }; } -void QStaticTextPrivate::paintText(QPainter *p) +void QStaticTextPrivate::paintText(const QPointF &pos, QPainter *p) { bool preferRichText = textFormat == Qt::RichText || (textFormat == Qt::AutoText && Qt::mightBeRichText(text)); @@ -538,13 +538,13 @@ void QStaticTextPrivate::paintText(QPainter *p) if (!preferRichText) { if (maximumSize.isValid()) { QRectF boundingRect; - p->drawText(QRectF(QPointF(0, 0), maximumSize), Qt::TextWordWrap, text, &boundingRect); + p->drawText(QRectF(pos, maximumSize), Qt::TextWordWrap, text, &boundingRect); actualSize = boundingRect.size(); needsClipRect = boundingRect.width() > maximumSize.width() || boundingRect.height() > maximumSize.height(); } else { - p->drawText(0, 0, text); + p->drawText(pos, text); needsClipRect = false; QFontMetrics fm(font); @@ -555,9 +555,12 @@ void QStaticTextPrivate::paintText(QPainter *p) document.setDefaultFont(font); document.setHtml(text); - QRectF rect = maximumSize.isValid() ? QRectF(QPointF(0, 0), maximumSize) : QRectF(); + QRectF rect = maximumSize.isValid() ? QRectF(pos, maximumSize) : QRectF(); document.adjustSize(); + p->save(); + p->translate(pos); document.drawContents(p, rect); + p->restore(); actualSize = document.size(); needsClipRect = maximumSize.isValid() && (actualSize.width() > maximumSize.width() @@ -581,7 +584,7 @@ void QStaticTextPrivate::init() painter.setFont(font); painter.setTransform(matrix); - paintText(&painter); + paintText(QPointF(0, 0), &painter); } @@ -605,7 +608,7 @@ void QStaticTextPrivate::init() painter.setFont(font); painter.setTransform(matrix); - paintText(&painter); + paintText(QPointF(0, 0), &painter); } } diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h index 89483d8..e758244 100644 --- a/src/gui/text/qstatictext_p.h +++ b/src/gui/text/qstatictext_p.h @@ -116,7 +116,7 @@ public: ~QStaticTextPrivate(); void init(); - void paintText(QPainter *p); + void paintText(const QPointF &pos, QPainter *p); QAtomicInt ref; // 4 bytes per text diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 8bfd151..a9afa5d 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -324,6 +324,7 @@ SUBDIRS += \ qstandarditemmodel \ qstate \ qstatemachine \ + qstatictext \ qstatusbar \ qstl \ qstring \ diff --git a/tests/auto/qstatictext/tst_qstatictext.cpp b/tests/auto/qstatictext/tst_qstatictext.cpp index c826b05..68f05c1 100644 --- a/tests/auto/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/qstatictext/tst_qstatictext.cpp @@ -44,8 +44,6 @@ #include #include -#include - #include #include @@ -114,6 +112,7 @@ void tst_QStaticText::drawToPoint() { QPainter p(&imageDrawStaticText); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + text.setTextFormat(Qt::PlainText); text.setPerformanceHint(performanceHint); p.drawStaticText(QPointF(11, 12), text); } @@ -146,6 +145,7 @@ void tst_QStaticText::drawToRect() QPainter p(&imageDrawStaticText); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", QSizeF(10, 500)); text.setPerformanceHint(performanceHint); + text.setTextFormat(Qt::PlainText); p.drawStaticText(QPointF(11, 12), text); } @@ -173,6 +173,7 @@ void tst_QStaticText::prepareToCorrectData() p.setTransform(transform); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); text.prepare(transform, p.font()); + text.setTextFormat(Qt::PlainText); p.drawStaticText(QPointF(11, 12), text); } @@ -198,6 +199,7 @@ void tst_QStaticText::prepareToWrongData() QPainter p(&imageDrawStaticText); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); text.prepare(transform, p.font()); + text.setTextFormat(Qt::PlainText); p.drawStaticText(QPointF(11, 12), text); } @@ -228,6 +230,7 @@ void tst_QStaticText::setFont() QStaticText text; text.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + text.setTextFormat(Qt::PlainText); p.drawStaticText(0, 0, text); @@ -277,6 +280,8 @@ void tst_QStaticText::translatedPainter() p.translate(100, 200); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + text.setTextFormat(Qt::PlainText); + p.drawStaticText(QPointF(11, 12), text); } @@ -297,6 +302,7 @@ void tst_QStaticText::rotatedPainter() imageDrawStaticText.fill(Qt::white); { QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + text.setTextFormat(Qt::PlainText); QPainter p(&imageDrawStaticText); p.rotate(30.0); @@ -329,6 +335,8 @@ void tst_QStaticText::scaledPainter() p.scale(2.0, 0.2); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + text.setTextFormat(Qt::PlainText); + p.drawStaticText(QPointF(11, 12), text); } @@ -356,6 +364,8 @@ void tst_QStaticText::projectedPainter() p.setTransform(transform); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + text.setTextFormat(Qt::PlainText); + p.drawStaticText(QPointF(11, 12), text); } @@ -385,6 +395,8 @@ void tst_QStaticText::rotatedScaledAndTranslatedPainter() p.translate(100, 200); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + text.setTextFormat(Qt::PlainText); + p.drawStaticText(QPointF(11, 12), text); } @@ -419,6 +431,8 @@ void tst_QStaticText::transformationChanged() p.scale(0.5, 0.7); QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + text.setTextFormat(Qt::PlainText); + p.drawStaticText(QPointF(0, 0), text); p.scale(7.0, 5.0); -- cgit v0.12