diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-03-26 10:56:55 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-03-29 12:09:17 (GMT) |
commit | d717d2686ecdbeafee1f5cabc6832c8339cfb2b4 (patch) | |
tree | a64103fc91a3dda5fdf6cb7414a5146665507ce9 /tests/auto/qstatictext | |
parent | e7eb7bdf63791ed03257f2f23b1f515e4d89e054 (diff) | |
download | Qt-d717d2686ecdbeafee1f5cabc6832c8339cfb2b4.zip Qt-d717d2686ecdbeafee1f5cabc6832c8339cfb2b4.tar.gz Qt-d717d2686ecdbeafee1f5cabc6832c8339cfb2b4.tar.bz2 |
Respect QPainter::pen() in QPainter::drawStaticText()
QStaticText needs to support changing the pen on the painter to support
rich text, but it should not override the pen unless it has been
explicitly set in the rich text. We do this by marking the pen as dirty
in updateState() when we record the text items.
Task-number: QTBUG-8908
Reviewed-by: Gunnar
Diffstat (limited to 'tests/auto/qstatictext')
-rw-r--r-- | tests/auto/qstatictext/tst_qstatictext.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/auto/qstatictext/tst_qstatictext.cpp b/tests/auto/qstatictext/tst_qstatictext.cpp index a038878..b59c10b 100644 --- a/tests/auto/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/qstatictext/tst_qstatictext.cpp @@ -81,6 +81,10 @@ private slots: void transformationChanged(); void plainTextVsRichText(); + + void setPenPlainText(); + void setPenRichText(); + void richTextOverridesPen(); }; void tst_QStaticText::init() @@ -518,5 +522,91 @@ void tst_QStaticText::plainTextVsRichText() QCOMPARE(imagePlainText, imageRichText); } +void tst_QStaticText::setPenPlainText() +{ + QFont font = QApplication::font(); + font.setStyleStrategy(QFont::NoAntialias); + + QFontMetricsF fm(font); + QPixmap image(qCeil(fm.width("XXXXX")), qCeil(fm.height())); + image.fill(Qt::white); + { + QPainter p(&image); + p.setFont(font); + p.setPen(Qt::green); + + QStaticText staticText("XXXXX"); + staticText.setTextFormat(Qt::PlainText); + p.drawStaticText(0, fm.ascent(), staticText); + } + + QImage img = image.toImage(); + for (int x=0; x<img.width(); ++x) { + for (int y=0; y<img.height(); ++y) { + QRgb pixel = img.pixel(x, y); + QVERIFY(pixel == QColor(Qt::white).rgba() + || pixel == QColor(Qt::green).rgba()); + } + } +} + +void tst_QStaticText::setPenRichText() +{ + QFont font = QApplication::font(); + font.setStyleStrategy(QFont::NoAntialias); + + QFontMetricsF fm(font); + QPixmap image(qCeil(fm.width("XXXXX")), qCeil(fm.height())); + image.fill(Qt::white); + { + QPainter p(&image); + p.setFont(font); + p.setPen(Qt::green); + + QStaticText staticText; + staticText.setText("<html><body>XXXXX</body></html>"); + staticText.setTextFormat(Qt::RichText); + p.drawStaticText(0, fm.ascent(), staticText); + } + + QImage img = image.toImage(); + for (int x=0; x<img.width(); ++x) { + for (int y=0; y<img.height(); ++y) { + QRgb pixel = img.pixel(x, y); + QVERIFY(pixel == QColor(Qt::white).rgba() + || pixel == QColor(Qt::green).rgba()); + } + } +} + +void tst_QStaticText::richTextOverridesPen() +{ + QFont font = QApplication::font(); + font.setStyleStrategy(QFont::NoAntialias); + + QFontMetricsF fm(font); + QPixmap image(qCeil(fm.width("XXXXX")), qCeil(fm.height())); + image.fill(Qt::white); + { + QPainter p(&image); + p.setFont(font); + p.setPen(Qt::green); + + QStaticText staticText; + staticText.setText("<html><body><font color=\"#ff0000\">XXXXX</font></body></html>"); + staticText.setTextFormat(Qt::RichText); + p.drawStaticText(0, fm.ascent(), staticText); + } + + QImage img = image.toImage(); + for (int x=0; x<img.width(); ++x) { + for (int y=0; y<img.height(); ++y) { + QRgb pixel = img.pixel(x, y); + QVERIFY(pixel == QColor(Qt::white).rgba() + || pixel == QColor(Qt::red).rgba()); + } + } +} + QTEST_MAIN(tst_QStaticText) #include "tst_qstatictext.moc" |