aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-02-14 17:02:55 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-16 06:36:38 +0100
commit7127120b68ec08296b6e2980d1c9ae1a34e5f28d (patch)
tree5923ca0723243598df85c1a095d5b942c09d94c6 /tests/auto
parent990a95fa3760af233195f87281dfc354002284a0 (diff)
Fix multi-length string substitution.
Multi-length string eliding was provided by QFontMetrics::elidedText() which is no longer used for layouts. So we instead have to do the string substitution ourselves if the text doesn't fit before finally eliding. Change-Id: Iab2e54b332390290d656299a5be148f39f78df9d Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtquick2/qquicktext/data/multilengthStrings.qml14
-rw-r--r--tests/auto/qtquick2/qquicktext/data/multilengthStringsWrapped.qml16
-rw-r--r--tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp66
3 files changed, 96 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquicktext/data/multilengthStrings.qml b/tests/auto/qtquick2/qquicktext/data/multilengthStrings.qml
new file mode 100644
index 0000000000..d26576eacd
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktext/data/multilengthStrings.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+
+Item {
+ width: 300
+ height: 200
+
+ Text {
+ id: myText
+ objectName: "myText"
+ width: 100
+ font.pixelSize: 15
+ font.family: "Helvetica"
+ }
+}
diff --git a/tests/auto/qtquick2/qquicktext/data/multilengthStringsWrapped.qml b/tests/auto/qtquick2/qquicktext/data/multilengthStringsWrapped.qml
new file mode 100644
index 0000000000..0da9bc353a
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktext/data/multilengthStringsWrapped.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.0
+
+Item {
+ width: 300
+ height: 200
+
+ Text {
+ id: myText
+ objectName: "myText"
+ width: 100
+ height: 36
+ font.pixelSize: 15
+ font.family: "Helvetica"
+ wrapMode: Text.Wrap
+ }
+}
diff --git a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
index 4f1225e937..cbe3d30cbb 100644
--- a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
@@ -120,6 +120,8 @@ private slots:
void fontSizeMode();
void fontSizeModeMultiline_data();
void fontSizeModeMultiline();
+ void multilengthStrings_data();
+ void multilengthStrings();
private:
QStringList standard;
@@ -2362,6 +2364,70 @@ void tst_qquicktext::fontSizeModeMultiline()
}
}
+void tst_qquicktext::multilengthStrings_data()
+{
+ QTest::addColumn<QString>("source");
+ QTest::newRow("No Wrap") << testFile("multilengthStrings.qml");
+ QTest::newRow("Wrap") << testFile("multilengthStringsWrapped.qml");
+}
+
+void tst_qquicktext::multilengthStrings()
+{
+ QFETCH(QString, source);
+
+ QScopedPointer<QQuickView> canvas(createView(source));
+ canvas->show();
+
+ QQuickText *myText = canvas->rootObject()->findChild<QQuickText*>("myText");
+ QVERIFY(myText != 0);
+
+ const QString longText = "the quick brown fox jumped over the lazy dog";
+ const QString mediumText = "the brown fox jumped over the dog";
+ const QString shortText = "fox jumped dog";
+
+ myText->setText(longText);
+ QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+ const qreal longWidth = myText->contentWidth();
+ const qreal longHeight = myText->contentHeight();
+
+ myText->setText(mediumText);
+ QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+ const qreal mediumWidth = myText->contentWidth();
+ const qreal mediumHeight = myText->contentHeight();
+
+ myText->setText(shortText);
+ QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+ const qreal shortWidth = myText->contentWidth();
+ const qreal shortHeight = myText->contentHeight();
+
+ myText->setElideMode(QQuickText::ElideRight);
+ myText->setText(longText + QLatin1Char('\x9c') + mediumText + QLatin1Char('\x9c') + shortText);
+
+ myText->setSize(QSizeF(longWidth, longHeight));
+ QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+
+ QCOMPARE(myText->contentWidth(), longWidth);
+ QCOMPARE(myText->contentHeight(), longHeight);
+ QCOMPARE(myText->truncated(), false);
+
+ myText->setSize(QSizeF(mediumWidth, mediumHeight));
+ QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+
+ QCOMPARE(myText->contentWidth(), mediumWidth);
+ QCOMPARE(myText->contentHeight(), mediumHeight);
+#ifdef Q_OS_MAC
+ QEXPECT_FAIL("Wrap", "QTBUG-24310", Continue);
+#endif
+ QCOMPARE(myText->truncated(), true);
+
+ myText->setSize(QSizeF(shortWidth, shortHeight));
+ QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+
+ QCOMPARE(myText->contentWidth(), shortWidth);
+ QCOMPARE(myText->contentHeight(), shortHeight);
+ QCOMPARE(myText->truncated(), true);
+}
+
QTEST_MAIN(tst_qquicktext)
#include "tst_qquicktext.moc"