diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-04-19 11:08:28 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-27 06:27:46 +0200 |
commit | 2a6e105f43885e0901c252bffc77bd1c9db87b67 (patch) | |
tree | fbab5df14ceeb7e3a798cdbe4e5c6d5effff331d /tests/auto/quick/qquicktext | |
parent | 1770fa632facf2f1e4bb05e7689efc939d46cfef (diff) |
Fix bounding rects of text items.
Ensure the rectangles are correctly positioned with right
and center aligned text, not just sized correctly. Also add
padding to the clip rects so the cursor and styled text aren't
clipped at the item boundaries.
Change-Id: I03ef140589154ebd49b600b0a4c4fbeff845c10f
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquicktext')
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 297fa0106f..d1899a62b7 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -114,6 +114,7 @@ private slots: void boundingRect_data(); void boundingRect(); + void clipRect(); void lineLaidOut(); void imgTagsBaseUrl_data(); @@ -1802,6 +1803,50 @@ void tst_qquicktext::boundingRect() QVERIFY(text->boundingRect().height() > line.height()); } +void tst_qquicktext::clipRect() +{ + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0\n Text {}", QUrl()); + QScopedPointer<QObject> object(component.create()); + QQuickText *text = qobject_cast<QQuickText *>(object.data()); + QVERIFY(text); + + QTextLayout layout; + layout.setFont(text->font()); + + QCOMPARE(text->clipRect().x(), qreal(0)); + QCOMPARE(text->clipRect().y(), qreal(0)); + QCOMPARE(text->clipRect().width(), text->width()); + QCOMPARE(text->clipRect().height(), text->height()); + + text->setText("Hello World"); + + QCOMPARE(text->clipRect().x(), qreal(0)); + QCOMPARE(text->clipRect().y(), qreal(0)); + QCOMPARE(text->clipRect().width(), text->width()); + QCOMPARE(text->clipRect().height(), text->height()); + + // Clip rect follows the item not content dimensions. + text->setWidth(text->width() / 2); + QCOMPARE(text->clipRect().x(), qreal(0)); + QCOMPARE(text->clipRect().y(), qreal(0)); + QCOMPARE(text->clipRect().width(), text->width()); + QCOMPARE(text->clipRect().height(), text->height()); + + text->setHeight(text->height() * 2); + QCOMPARE(text->clipRect().x(), qreal(0)); + QCOMPARE(text->clipRect().y(), qreal(0)); + QCOMPARE(text->clipRect().width(), text->width()); + QCOMPARE(text->clipRect().height(), text->height()); + + // Setting a style adds a small amount of padding to the clip rect. + text->setStyle(QQuickText::Outline); + QCOMPARE(text->clipRect().x(), qreal(-1)); + QCOMPARE(text->clipRect().y(), qreal(0)); + QCOMPARE(text->clipRect().width(), text->width() + 2); + QCOMPARE(text->clipRect().height(), text->height() + 2); +} + void tst_qquicktext::lineLaidOut() { QQuickView *canvas = createView(testFile("lineLayout.qml")); |