diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2012-05-03 15:00:33 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-03 08:05:33 +0200 |
commit | f50c0af7532247b3a9c38244ec297da97a8e31ab (patch) | |
tree | 263c6746f8b607b890c3ee2af8dd9288efe660f1 /tests | |
parent | bf817782e6dfeb8455febe3e481bcdb4c383ed05 (diff) |
Fix alignment bug in QQuickText with multi-line text and implicit width
If the horizontal alignment is not left and the width of the text is not
known during the first pass, we need to relayout once we know the
maximum line width.
Task-number: QTBUG-18617
Change-Id: I0cad100946beda151034067e23439185684de144
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml | 13 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 55 |
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml b/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml new file mode 100644 index 0000000000..136e5d21a2 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Rectangle { + width: 200 + height: 100 + + Text { + objectName: "textItem" + text: "AA\nBBBBB\nCCCCCCCCCCCCCCCC" + anchors.centerIn: parent + horizontalAlignment: Text.AlignLeft + } +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index a83a10e216..d9395ca78d 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -90,6 +90,7 @@ private slots: void horizontalAlignment(); void horizontalAlignment_RightToLeft(); void verticalAlignment(); + void hAlignImplicitWidth(); void font(); void style(); void color(); @@ -158,6 +159,7 @@ private: QQmlEngine engine; QQuickView *createView(const QString &filename); + int numberOfNonWhitePixels(int fromX, int toX, const QImage &image); }; tst_qquicktext::tst_qquicktext() @@ -836,6 +838,59 @@ void tst_qquicktext::horizontalAlignment_RightToLeft() delete textObject; } +int tst_qquicktext::numberOfNonWhitePixels(int fromX, int toX, const QImage &image) +{ + int pixels = 0; + for (int x = fromX; x < toX; ++x) { + for (int y = 0; y < image.height(); ++y) { + if (image.pixel(x, y) != qRgb(255, 255, 255)) + pixels++; + } + } + return pixels; +} + +void tst_qquicktext::hAlignImplicitWidth() +{ + QQuickView view(testFileUrl("hAlignImplicitWidth.qml")); + view.show(); + view.requestActivateWindow(); + QTest::qWaitForWindowShown(&view); + + QQuickText *text = view.rootObject()->findChild<QQuickText*>("textItem"); + QVERIFY(text != 0); + + { + // Left Align + QImage image = view.grabFrameBuffer(); + int left = numberOfNonWhitePixels(0, image.width() / 3, image); + int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); + int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); + QVERIFY(left > mid); + QVERIFY(mid > right); + } + { + // HCenter Align + text->setHAlign(QQuickText::AlignHCenter); + QImage image = view.grabFrameBuffer(); + int left = numberOfNonWhitePixels(0, image.width() / 3, image); + int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); + int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); + QVERIFY(left < mid); + QVERIFY(mid > right); + } + { + // Right Align + text->setHAlign(QQuickText::AlignRight); + QImage image = view.grabFrameBuffer(); + int left = numberOfNonWhitePixels(0, image.width() / 3, image); + int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); + int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); + QVERIFY(left < mid); + QVERIFY(mid < right); + } +} + void tst_qquicktext::verticalAlignment() { //test one align each, and then test if two align fails. |