summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2016-10-04 12:41:47 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2016-10-04 14:30:13 +0000
commit4d552815cf370c0d5abbbeb50ff1350b449e7bb2 (patch)
tree120722bc61931f7c5054b76e50d617ead2f4da12 /tests/auto/gui/text/qstatictext/tst_qstatictext.cpp
parentf3d19244cd8cc09d643dc74e0476ff8e975a7054 (diff)
Fix plain text QStaticText with line breaks
The layout isn't actually created until endLayout() or setLineWidth() is called. So in the case where this was not done, the height of the line would be 0, thus multiple lines would be placed on top of each other, at y == 0. [ChangeLog][QtGui][Text] Fixed QStaticText when manually breaking lines and no text width was set. Task-number: QTBUG-56346 Change-Id: I7f6ed6260545882f05fe39b21134315eca7401b9 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'tests/auto/gui/text/qstatictext/tst_qstatictext.cpp')
-rw-r--r--tests/auto/gui/text/qstatictext/tst_qstatictext.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp
index ec30cc8b67..b3d1b75a42 100644
--- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp
+++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp
@@ -96,6 +96,8 @@ private slots:
void textDocumentColor();
#endif
+ void multiLine();
+
private:
bool supportsTransformations() const;
@@ -854,5 +856,58 @@ void tst_QStaticText::textDocumentColor()
}
#endif
+class TestPaintEngine: public QPaintEngine
+{
+public:
+ void drawTextItem(const QPointF &p, const QTextItem &textItem) Q_DECL_OVERRIDE
+ {
+ differentVerticalPositions.insert(qRound(p.y()));
+ }
+
+ void updateState(const QPaintEngineState &) Q_DECL_OVERRIDE {}
+
+ void drawPolygon(const QPointF *, int , PolygonDrawMode ) Q_DECL_OVERRIDE {}
+
+ bool begin(QPaintDevice *) Q_DECL_OVERRIDE { return true; }
+ bool end() Q_DECL_OVERRIDE { return true; }
+ void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) Q_DECL_OVERRIDE {}
+ Type type() const Q_DECL_OVERRIDE
+ {
+ return User;
+ }
+
+ QSet<int> differentVerticalPositions;
+};
+
+class TestPixmap: public QPixmap
+{
+public:
+ TestPixmap(int w, int h) : QPixmap(w, h), testPaintEngine(new TestPaintEngine) {}
+ ~TestPixmap() { delete testPaintEngine; }
+
+ QPaintEngine *paintEngine() const
+ {
+ return testPaintEngine;
+ }
+
+ TestPaintEngine *testPaintEngine;
+};
+
+void tst_QStaticText::multiLine()
+{
+ TestPixmap pixmap(100, 100);
+
+ TestPaintEngine *paintEngine = pixmap.testPaintEngine;
+
+ {
+ QPainter p(&pixmap);
+ QStaticText text;
+ text.setText(QLatin1String("line 1") + QChar(QChar::LineSeparator) + QLatin1String("line 2"));
+ p.drawStaticText(0, 0, text);
+ }
+
+ QCOMPARE(paintEngine->differentVerticalPositions.size(), 2);
+}
+
QTEST_MAIN(tst_QStaticText)
#include "tst_qstatictext.moc"