diff options
author | Jiang Jiang <jiang.jiang@nokia.com> | 2010-08-09 13:56:34 (GMT) |
---|---|---|
committer | Jiang Jiang <jiang.jiang@nokia.com> | 2010-08-10 07:32:14 (GMT) |
commit | a1641e27d2e2f5e29362e3737be6b9d75714d138 (patch) | |
tree | 102bca29bcfc048dead2a77d57ab4bb008662dd2 /tests/auto | |
parent | 031b62a32b9f20401cadd5a424a5f4746b018b56 (diff) | |
download | Qt-a1641e27d2e2f5e29362e3737be6b9d75714d138.zip Qt-a1641e27d2e2f5e29362e3737be6b9d75714d138.tar.gz Qt-a1641e27d2e2f5e29362e3737be6b9d75714d138.tar.bz2 |
Add text decoration support to QStaticText
The original code path of QStaticText does not include decoration
drawing, this patch generalized the drawTextItemDecoration()
function to draw decoration for drawText(), then use that to draw
decoration for QStaticText. A helper function called
drawDecorationForGlyphs() is made to allow easier extension for
direct glyphs drawing support.
Task-number: QTBUG-12121
Reviewed-by: Eskil
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qstatictext/tst_qstatictext.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/auto/qstatictext/tst_qstatictext.cpp b/tests/auto/qstatictext/tst_qstatictext.cpp index 1d166f4..0ae5320 100644 --- a/tests/auto/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/qstatictext/tst_qstatictext.cpp @@ -85,6 +85,10 @@ private slots: void setPenPlainText(); void setPenRichText(); void richTextOverridesPen(); + + void drawStruckOutText(); + void drawOverlinedText(); + void drawUnderlinedText(); }; void tst_QStaticText::init() @@ -620,5 +624,107 @@ void tst_QStaticText::richTextOverridesPen() } } +void tst_QStaticText::drawStruckOutText() +{ + QPixmap imageDrawText(1000, 1000); + QPixmap imageDrawStaticText(1000, 1000); + + imageDrawText.fill(Qt::white); + imageDrawStaticText.fill(Qt::white); + + QString s = QString::fromLatin1("Foobar"); + + QFont font; + font.setStrikeOut(true); + + { + QPainter p(&imageDrawText); + p.setFont(font); + p.drawText(QPointF(50, 50), s); + } + + { + QPainter p(&imageDrawStaticText); + QStaticText text = QStaticText(s); + p.setFont(font); + p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawStruckOutText_imageDrawText.png"); + imageDrawStaticText.save("drawStruckOutText_imageDrawStaticText.png"); +#endif + + QCOMPARE(imageDrawText, imageDrawStaticText); +} + +void tst_QStaticText::drawOverlinedText() +{ + QPixmap imageDrawText(1000, 1000); + QPixmap imageDrawStaticText(1000, 1000); + + imageDrawText.fill(Qt::white); + imageDrawStaticText.fill(Qt::white); + + QString s = QString::fromLatin1("Foobar"); + + QFont font; + font.setOverline(true); + + { + QPainter p(&imageDrawText); + p.setFont(font); + p.drawText(QPointF(50, 50), s); + } + + { + QPainter p(&imageDrawStaticText); + QStaticText text = QStaticText(s); + p.setFont(font); + p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawOverlinedText_imageDrawText.png"); + imageDrawStaticText.save("drawOverlinedText_imageDrawStaticText.png"); +#endif + + QCOMPARE(imageDrawText, imageDrawStaticText); +} + +void tst_QStaticText::drawUnderlinedText() +{ + QPixmap imageDrawText(1000, 1000); + QPixmap imageDrawStaticText(1000, 1000); + + imageDrawText.fill(Qt::white); + imageDrawStaticText.fill(Qt::white); + + QString s = QString::fromLatin1("Foobar"); + + QFont font; + font.setUnderline(true); + + { + QPainter p(&imageDrawText); + p.setFont(font); + p.drawText(QPointF(50, 50), s); + } + + { + QPainter p(&imageDrawStaticText); + QStaticText text = QStaticText(s); + p.setFont(font); + p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawUnderlinedText_imageDrawText.png"); + imageDrawStaticText.save("drawUnderlinedText_imageDrawStaticText.png"); +#endif + + QCOMPARE(imageDrawText, imageDrawStaticText); +} + QTEST_MAIN(tst_QStaticText) #include "tst_qstatictext.moc" |