summaryrefslogtreecommitdiffstats
path: root/tests
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
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')
-rw-r--r--tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp40
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp34
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp9
3 files changed, 79 insertions, 4 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()
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index db36220..402c6cd 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -448,7 +448,7 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft()
QVERIFY(textEdit != 0);
canvas->show();
- // implicit alignment should follow the reading direction of RTL text
+ // implicit alignment should follow the reading direction of text
QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight);
QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2);
@@ -462,6 +462,29 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft()
QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight);
QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2);
+ QString textString = textEdit->text();
+ textEdit->setText(QString("<i>") + textString + QString("</i>"));
+ textEdit->resetHAlign();
+
+ // implicitly aligned rich text should follow the reading direction of RTL text
+ QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight);
+ QCOMPARE(textEdit->effectiveHAlign(), textEdit->hAlign());
+ QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2);
+
+ // explicitly left aligned rich text
+ textEdit->setHAlign(QDeclarativeTextEdit::AlignLeft);
+ QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignLeft);
+ QCOMPARE(textEdit->effectiveHAlign(), textEdit->hAlign());
+ QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2);
+
+ // explicitly right aligned rich text
+ textEdit->setHAlign(QDeclarativeTextEdit::AlignRight);
+ QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight);
+ QCOMPARE(textEdit->effectiveHAlign(), textEdit->hAlign());
+ QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2);
+
+ textEdit->setText(textString);
+
// explicitly center aligned
textEdit->setHAlign(QDeclarativeTextEdit::AlignHCenter);
QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignHCenter);
@@ -515,6 +538,15 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft()
QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2);
delete canvas;
+
+ // alignment of TextEdit with no text set to it
+ QString componentStr = "import QtQuick 1.0\nTextEdit {}";
+ QDeclarativeComponent textComponent(&engine);
+ textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeTextEdit *textObject = qobject_cast<QDeclarativeTextEdit*>(textComponent.create());
+ QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+ QDeclarativeTextEdit::AlignLeft : QDeclarativeTextEdit::AlignRight);
+ delete textObject;
}
void tst_qdeclarativetextedit::vAlign()
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index fc19c94..734f91f 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -1125,6 +1125,15 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft()
QVERIFY(-textInputPrivate->hscroll > canvas->width()/2);
delete canvas;
+
+ // alignment of TextInput with no text set to it
+ QString componentStr = "import QtQuick 1.0\nTextInput {}";
+ QDeclarativeComponent textComponent(&engine);
+ textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeTextInput *textObject = qobject_cast<QDeclarativeTextInput*>(textComponent.create());
+ QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+ QDeclarativeTextInput::AlignLeft : QDeclarativeTextInput::AlignRight);
+ delete textObject;
}
void tst_qdeclarativetextinput::positionAt()