summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativetext
diff options
context:
space:
mode:
authorJoona Petrell <joona.t.petrell@nokia.com>2011-03-08 08:05:25 (GMT)
committerJoona Petrell <joona.t.petrell@nokia.com>2011-03-09 07:40:27 (GMT)
commitaeb330e3999ef3d7ae8d94b9330471f2a2a13554 (patch)
treeca612930c19dba6464d7af163a04405282d51cfb /tests/auto/declarative/qdeclarativetext
parent0d6ce63ea84b076efbebfae0f6f39f492d8d7bcf (diff)
downloadQt-aeb330e3999ef3d7ae8d94b9330471f2a2a13554.zip
Qt-aeb330e3999ef3d7ae8d94b9330471f2a2a13554.tar.gz
Qt-aeb330e3999ef3d7ae8d94b9330471f2a2a13554.tar.bz2
Fix horizontal alignment of QTextDocument-based RTL text
Task-number: QTBUG-15880 Reviewed-by: Martin Jones Change-Id: If537d7c795dec46eedee62511e75bab862676ef1
Diffstat (limited to 'tests/auto/declarative/qdeclarativetext')
-rw-r--r--tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp40
1 files changed, 37 insertions, 3 deletions
diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
index c854f86..b5dfba8 100644
--- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
+++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
@@ -523,18 +523,44 @@ void tst_qdeclarativetext::horizontalAlignment_RightToLeft()
QCOMPARE(text->effectiveHAlign(), text->hAlign());
QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() > canvas->width()/2);
- // explicitly left aligned
+ // explicitly left aligned text
text->setHAlign(QDeclarativeText::AlignLeft);
QCOMPARE(text->hAlign(), QDeclarativeText::AlignLeft);
QCOMPARE(text->effectiveHAlign(), text->hAlign());
QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() < canvas->width()/2);
- // explicitly right aligned
+ // explicitly right aligned text
text->setHAlign(QDeclarativeText::AlignRight);
QCOMPARE(text->hAlign(), QDeclarativeText::AlignRight);
QCOMPARE(text->effectiveHAlign(), text->hAlign());
QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() > canvas->width()/2);
+ // change to rich text
+ QString textString = text->text();
+ text->setText(QString("<i>") + textString + QString("</i>"));
+ text->setTextFormat(QDeclarativeText::RichText);
+ text->resetHAlign();
+
+ // implicitly aligned rich text should follow the reading direction of text
+ QCOMPARE(text->hAlign(), QDeclarativeText::AlignRight);
+ QCOMPARE(text->effectiveHAlign(), text->hAlign());
+ QVERIFY(textPrivate->textDocument()->defaultTextOption().alignment() & Qt::AlignLeft);
+
+ // explicitly left aligned rich text
+ text->setHAlign(QDeclarativeText::AlignLeft);
+ QCOMPARE(text->hAlign(), QDeclarativeText::AlignLeft);
+ QCOMPARE(text->effectiveHAlign(), text->hAlign());
+ QVERIFY(textPrivate->textDocument()->defaultTextOption().alignment() & Qt::AlignRight);
+
+ // explicitly right aligned rich text
+ text->setHAlign(QDeclarativeText::AlignRight);
+ QCOMPARE(text->hAlign(), QDeclarativeText::AlignRight);
+ QCOMPARE(text->effectiveHAlign(), text->hAlign());
+ QVERIFY(textPrivate->textDocument()->defaultTextOption().alignment() & Qt::AlignLeft);
+
+ text->setText(textString);
+ text->setTextFormat(QDeclarativeText::PlainText);
+
// explicitly center aligned
text->setHAlign(QDeclarativeText::AlignHCenter);
QCOMPARE(text->hAlign(), QDeclarativeText::AlignHCenter);
@@ -583,8 +609,16 @@ void tst_qdeclarativetext::horizontalAlignment_RightToLeft()
QDeclarativeText::AlignLeft : QDeclarativeText::AlignRight);
text->setHAlign(QDeclarativeText::AlignRight);
QCOMPARE(text->hAlign(), QDeclarativeText::AlignRight);
-
delete canvas;
+
+ // alignment of Text with no text set to it
+ QString componentStr = "import QtQuick 1.0\nText {}";
+ QDeclarativeComponent textComponent(&engine);
+ textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeText *textObject = qobject_cast<QDeclarativeText*>(textComponent.create());
+ QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+ QDeclarativeText::AlignLeft : QDeclarativeText::AlignRight);
+ delete textObject;
}
void tst_qdeclarativetext::verticalAlignment()