diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2014-10-22 16:16:56 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2014-10-23 10:39:49 +0200 |
commit | e3c6f39734ff54b2d7425f2edaaf6033ef2b1d9e (patch) | |
tree | b9eb21ef8c173ac9fa2a545dcf4f7e1dd16c8339 /tests | |
parent | 0fc6e4b2c3e187ab60a111b1d1871c1f3e846600 (diff) |
Relayout rich text when width increases
In updateSize() we were trying to force relayouts for RichText
when the width changes by always setting widthExceeded to true.
But further down in the same function, we overwrote this
with textWidth() < idealWidth(), which doesn't work, because
both properties are the wrapped width of the document and
should only differ if the text cannot be wrapped properly.
The result was that when increasing the width of a Text element,
we would hit the optimization and skip the relayout.
[ChangeLog][Text] Fixed Text with the RichText format to
correctly update wrapping when the width of the element grows.
Change-Id: I5fd87052a5ba7e8ee2549be0cfac4adc8ddf8290
Task-number: QTBUG-33020
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index b7335ccc4a..2e5212d5d8 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -416,6 +416,35 @@ void tst_qquicktext::wrap() delete textObject; } + // Check that increasing width from idealWidth will cause a relayout + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import QtQuick 2.0\nText { wrapMode: Text.WordWrap; textFormat: Text.RichText; width: 30; text: \"" + richText.at(i) + "\" }"; + QQmlComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); + + QVERIFY(textObject != 0); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); + + QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); + QVERIFY(textPrivate != 0); + QVERIFY(textPrivate->extra.isAllocated()); + + QTextDocument *doc = textPrivate->extra->doc; + QVERIFY(doc != 0); + textObject->setWidth(doc->idealWidth()); + QCOMPARE(textObject->width(), doc->idealWidth()); + QVERIFY(textObject->height() > textHeight); + + qreal oldHeight = textObject->height(); + textObject->setWidth(100); + QVERIFY(textObject->height() < oldHeight); + + delete textObject; + } + // richtext again with a fixed height for (int i = 0; i < richText.size(); i++) { |