diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp | 52 | ||||
-rw-r--r-- | tests/auto/shared/platforminputcontext.h | 22 |
2 files changed, 57 insertions, 17 deletions
diff --git a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp index e97756f330..8cc35f3b50 100644 --- a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp @@ -1219,6 +1219,10 @@ void tst_qquicktextinput::horizontalAlignment() void tst_qquicktextinput::horizontalAlignment_RightToLeft() { + PlatformInputContext platformInputContext; + QInputPanelPrivate *inputPanelPrivate = QInputPanelPrivate::get(qApp->inputPanel()); + inputPanelPrivate->testContext = &platformInputContext; + QQuickView canvas(testFileUrl("horizontalAlignment_RightToLeft.qml")); QQuickTextInput *textInput = canvas.rootObject()->findChild<QQuickTextInput*>("text"); QVERIFY(textInput != 0); @@ -1314,26 +1318,42 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft() // empty text with implicit alignment follows the system locale-based // keyboard input direction from QInputPanel::inputDirection() textInput->setText(""); - QCOMPARE(textInput->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? - QQuickTextInput::AlignLeft : QQuickTextInput::AlignRight); - if (qApp->inputPanel()->inputDirection() == Qt::LeftToRight) { - QCOMPARE(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll, qreal(0)); - } else { - QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1); - QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1); - } - textInput->setHAlign(QQuickTextInput::AlignRight); + platformInputContext.setInputDirection(Qt::LeftToRight); + QVERIFY(qApp->inputPanel()->inputDirection() == Qt::LeftToRight); + QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignLeft); + QCOMPARE(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll, qreal(0)); + + QSignalSpy cursorRectangleSpy(textInput, SIGNAL(cursorRectangleChanged())); + platformInputContext.setInputDirection(Qt::RightToLeft); + QVERIFY(qApp->inputPanel()->inputDirection() == Qt::RightToLeft); + QCOMPARE(cursorRectangleSpy.count(), 1); + QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight); + QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1); + QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1); + + // set input direction while having content + platformInputContext.setInputDirection(Qt::LeftToRight); + textInput->setText("a"); + platformInputContext.setInputDirection(Qt::RightToLeft); + QTest::keyClick(&canvas, Qt::Key_Backspace); + QVERIFY(textInput->text().isEmpty()); + QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight); + QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1); + QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1); + + // input direction changed while not having focus + platformInputContext.setInputDirection(Qt::LeftToRight); + textInput->setFocus(false); + platformInputContext.setInputDirection(Qt::RightToLeft); + textInput->setFocus(true); QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight); QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1); QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1); - QString componentStr = "import QtQuick 2.0\nTextInput {}"; - QDeclarativeComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QQuickTextInput *textObject = qobject_cast<QQuickTextInput*>(textComponent.create()); - QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? - QQuickTextInput::AlignLeft : QQuickTextInput::AlignRight); - delete textObject; + textInput->setHAlign(QQuickTextInput::AlignRight); + QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight); + QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1); + QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1); } void tst_qquicktextinput::verticalAlignment() diff --git a/tests/auto/shared/platforminputcontext.h b/tests/auto/shared/platforminputcontext.h index db5083725b..0c23db4dd9 100644 --- a/tests/auto/shared/platforminputcontext.h +++ b/tests/auto/shared/platforminputcontext.h @@ -48,7 +48,7 @@ public: PlatformInputContext() : m_visible(false), m_action(QInputPanel::Click), m_cursorPosition(0), m_invokeActionCallCount(0), m_showInputPanelCallCount(0), m_hideInputPanelCallCount(0), - m_updateCallCount(0) + m_updateCallCount(0), m_direction(Qt::LeftToRight) { } @@ -77,6 +77,25 @@ public: m_updateCallCount++; } + virtual QLocale locale() const + { + if (m_direction == Qt::RightToLeft) + return QLocale(QLocale::Arabic); + else + return QLocale(QLocale::English); + } + + virtual Qt::LayoutDirection inputDirection() const + { + return m_direction; + } + + void setInputDirection(Qt::LayoutDirection direction) { + m_direction = direction; + emitLocaleChanged(); + emitInputDirectionChanged(inputDirection()); + } + void clear() { m_cursorPosition = 0; m_invokeActionCallCount = 0; @@ -93,4 +112,5 @@ public: int m_showInputPanelCallCount; int m_hideInputPanelCallCount; int m_updateCallCount; + Qt::LayoutDirection m_direction; }; |