diff options
author | Christopher Ham <christopher.ham@nokia.com> | 2011-01-28 03:32:25 (GMT) |
---|---|---|
committer | Christopher Ham <christopher.ham@nokia.com> | 2011-01-28 03:32:25 (GMT) |
commit | 64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f (patch) | |
tree | 2e0ffdfb7c9dbf702eed0609ebe46b77339b97e7 /tests | |
parent | 57ddd7c69705dfbf3d06b8a0157e5e706120c818 (diff) | |
download | Qt-64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f.zip Qt-64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f.tar.gz Qt-64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f.tar.bz2 |
Fixing right-to-left text in Text and TextInput
The Text and TextInput items should now automatically flip the
alignment of right-to-left text. Autotests also added to ensure the
text is on the correct side (added for TextInput also).
Task-number: QTBUG-15880
Reviewed-by: Martin Jones
Diffstat (limited to 'tests')
6 files changed, 148 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativetext/data/horizontalAlignment_RightToLeft.qml b/tests/auto/declarative/qdeclarativetext/data/horizontalAlignment_RightToLeft.qml new file mode 100644 index 0000000..4f58944 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/horizontalAlignment_RightToLeft.qml @@ -0,0 +1,23 @@ +import QtQuick 1.0 + +Rectangle { + id: top + width: 200; height: 70; + + property alias horizontalAlignment: text.horizontalAlignment + property string text: "اختبا" + + Rectangle { + anchors.centerIn: parent + width: 180 + height: 20 + color: "green" + + Text { + id: text + objectName: "text" + anchors.fill: parent + text: top.text + } + } +} diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index fabae18..c9b5295 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -43,6 +43,7 @@ #include <QtDeclarative/qdeclarativeengine.h> #include <QtDeclarative/qdeclarativecomponent.h> #include <private/qdeclarativetext_p.h> +#include <private/qdeclarativetext_p_p.h> #include <private/qdeclarativevaluetype_p.h> #include <QFontMetrics> #include <QGraphicsSceneMouseEvent> @@ -83,6 +84,7 @@ private slots: // ### these tests may be trivial void horizontalAlignment(); + void horizontalAlignment_RightToLeft(); void verticalAlignment(); void font(); void style(); @@ -502,6 +504,32 @@ void tst_qdeclarativetext::horizontalAlignment() } +void tst_qdeclarativetext::horizontalAlignment_RightToLeft() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/horizontalAlignment_RightToLeft.qml"); + QDeclarativeText *text = canvas->rootObject()->findChild<QDeclarativeText*>("text"); + QVERIFY(text != 0); + canvas->show(); + + QDeclarativeTextPrivate *textPrivate = QDeclarativeTextPrivate::get(text); + QVERIFY(textPrivate != 0); + + QVERIFY(textPrivate->layout.lineAt(0).x() > canvas->width()/2); + + // "Right" aligned + text->setHAlign(QDeclarativeText::AlignRight); + QCOMPARE(text->hAlign(), QDeclarativeText::AlignRight); + QVERIFY(textPrivate->layout.lineAt(0).x() < canvas->width()/2); + + // Center aligned + text->setHAlign(QDeclarativeText::AlignHCenter); + QCOMPARE(text->hAlign(), QDeclarativeText::AlignHCenter); + QVERIFY(textPrivate->layout.lineAt(0).x() < canvas->width()/2); + QVERIFY(textPrivate->layout.lineAt(0).x() + textPrivate->layout.lineAt(0).width() > canvas->width()/2); + + delete canvas; +} + void tst_qdeclarativetext::verticalAlignment() { //test one align each, and then test if two align fails. diff --git a/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml b/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml new file mode 100644 index 0000000..43ea8d8 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml @@ -0,0 +1,23 @@ +import QtQuick 1.0 + +Rectangle { + id: top + width: 200; height: 70; + + property alias horizontalAlignment: text.horizontalAlignment + property string text: "اختبا" + + Rectangle { + anchors.centerIn: parent + width: 200 + height: 20 + color: "green" + + TextEdit { + id: text + objectName: "text" + anchors.fill: parent + text: top.text + } + } +} diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index cd1977a..b1e0cb9 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -102,6 +102,7 @@ private slots: // ### these tests may be trivial void hAlign(); + void hAlign_RightToLeft(); void vAlign(); void font(); void color(); @@ -424,6 +425,30 @@ void tst_qdeclarativetextedit::hAlign() } +void tst_qdeclarativetextedit::hAlign_RightToLeft() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/horizontalAlignment_RightToLeft.qml"); + QDeclarativeTextEdit *textEdit = canvas->rootObject()->findChild<QDeclarativeTextEdit*>("text"); + QVERIFY(textEdit != 0); + canvas->show(); + + QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2); + + // "Right" align + textEdit->setHAlign(QDeclarativeTextEdit::AlignRight); + QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight); + QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2); + + // Center align + // Note that position 0 is on the right-hand side + textEdit->setHAlign(QDeclarativeTextEdit::AlignHCenter); + QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignHCenter); + QVERIFY(textEdit->positionToRectangle(0).x() - textEdit->width() < canvas->width()/2); + QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2); + + delete canvas; +} + void tst_qdeclarativetextedit::vAlign() { //test one align each, and then test if two align fails. diff --git a/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml b/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml new file mode 100644 index 0000000..b11535e --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml @@ -0,0 +1,23 @@ +import QtQuick 1.0 + +Rectangle { + id: top + width: 200; height: 70; + + property alias horizontalAlignment: text.horizontalAlignment + property string text: "اختبا" + + Rectangle { + anchors.centerIn: parent + width: 180 + height: 20 + color: "green" + + TextInput { + id: text + objectName: "text" + anchors.fill: parent + text: top.text + } + } +} diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 69c1f7e..78f6693 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -95,6 +95,7 @@ private slots: void horizontalAlignment_data(); void horizontalAlignment(); + void horizontalAlignment_RightToLeft(); void positionAt(); @@ -662,6 +663,31 @@ void tst_qdeclarativetextinput::horizontalAlignment() delete canvas; } +void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/horizontalAlignment_RightToLeft.qml"); + QDeclarativeTextInput *textInput = canvas->rootObject()->findChild<QDeclarativeTextInput*>("text"); + QVERIFY(textInput != 0); + canvas->show(); + + QDeclarativeTextInputPrivate *textInputPrivate = QDeclarativeTextInputPrivate::get(textInput); + QVERIFY(textInputPrivate != 0); + QVERIFY(-textInputPrivate->hscroll > canvas->width()/2); + + // "Right" Align + textInput->setHAlign(QDeclarativeTextInput::AlignRight); + QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignRight); + QVERIFY(-textInputPrivate->hscroll < canvas->width()/2); + + // Center Align + textInput->setHAlign(QDeclarativeTextInput::AlignHCenter); + QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignHCenter); + QVERIFY(-textInputPrivate->hscroll < canvas->width()/2); + QVERIFY(-textInputPrivate->hscroll + textInputPrivate->width() > canvas->width()/2); + + delete canvas; +} + void tst_qdeclarativetextinput::positionAt() { QDeclarativeView *canvas = createView(SRCDIR "/data/positionAt.qml"); |