summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2010-08-09 15:56:34 +0200
committerJason McDonald <jason.mcdonald@nokia.com>2010-09-02 16:01:53 +1000
commit1864ecabcaa21261629d56518a4b88b2d3e0d7ba (patch)
tree74042c4ecf1f039b54ef48b952ef7193bbef33d2 /tests
parent3015f695f4d2a2a776cf4bc85121ebc051706351 (diff)
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 (cherry picked from commit a1641e27d2e2f5e29362e3737be6b9d75714d138)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qstatictext/tst_qstatictext.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/auto/qstatictext/tst_qstatictext.cpp b/tests/auto/qstatictext/tst_qstatictext.cpp
index 1d166f49e5..0ae5320b82 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"