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>bb10
parent
f3d19244cd
commit
4d552815cf
|
|
@ -622,6 +622,8 @@ void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p)
|
|||
|
||||
if (textWidth >= 0.0)
|
||||
line.setLineWidth(textWidth);
|
||||
else
|
||||
line.setLineWidth(QFIXED_MAX);
|
||||
height += leading;
|
||||
line.setPosition(QPointF(0.0, height));
|
||||
height += line.height();
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue