From 5645cd7d7a97edb248a67d094993900f1dba4be8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 15 Apr 2010 12:41:36 +1000 Subject: Make sure richtext wraps correctly with a fixed height set. --- src/declarative/graphicsitems/qdeclarativetext.cpp | 2 +- .../qdeclarativetext/tst_qdeclarativetext.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index b65212b..3a35dd5 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -677,7 +677,7 @@ void QDeclarativeTextPrivate::updateSize() QTextOption option((Qt::Alignment)int(hAlign | vAlign)); option.setWrapMode(QTextOption::WrapMode(wrapMode)); doc->setDefaultTextOption(option); - if (wrapMode != QDeclarativeText::NoWrap && !q->heightValid() && q->widthValid()) + if (wrapMode != QDeclarativeText::NoWrap && q->widthValid()) doc->setTextWidth(q->width()); else doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 2d10756..6637415 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -286,8 +286,28 @@ void tst_qdeclarativetext::wrap() QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 30.); QVERIFY(textObject->height() > textHeight); + + qreal oldHeight = textObject->height(); + textObject->setWidth(100); + QVERIFY(textObject->height() < oldHeight); } + // richtext again with a fixed height + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.7\nText { wrapMode: Text.WordWrap; width: 30; height: 50; text: \"" + richText.at(i) + "\" }"; + QDeclarativeComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->implicitHeight() > textHeight); + + qreal oldHeight = textObject->implicitHeight(); + textObject->setWidth(100); + QVERIFY(textObject->implicitHeight() < oldHeight); + } } void tst_qdeclarativetext::elide() -- cgit v0.12