From 39f9b5def185337b2087cadeb3e137dfbeb85fa4 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Thu, 5 Jan 2012 16:33:56 +0200 Subject: [PATCH] Adapt to QInputPanel::inputDirection() API Information moved from QGuiApplication into QInputPanel. Change-Id: Idd80609f4b67bffae7222a1fa27918724ebf60f6 Reviewed-by: Joona Petrell --- doc/src/declarative/righttoleft.qdoc | 2 +- doc/src/qtquick1/righttoleft.qdoc | 2 +- src/qtquick1/graphicsitems/qdeclarativetext.cpp | 3 ++- src/qtquick1/graphicsitems/qdeclarativetextedit.cpp | 2 +- src/qtquick1/graphicsitems/qdeclarativetextinput.cpp | 2 +- src/quick/items/qquicktext.cpp | 3 ++- src/quick/items/qquicktextedit.cpp | 2 +- src/quick/items/qquicktextinput.cpp | 3 ++- src/quick/items/qquicktextinput_p_p.h | 2 +- tests/auto/qtquick1/qdeclarativetext/tst_qdeclarativetext.cpp | 6 +++--- .../qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 8 ++++---- .../qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 8 ++++---- tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp | 6 +++--- tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp | 8 ++++---- tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp | 8 ++++---- 15 files changed, 34 insertions(+), 31 deletions(-) diff --git a/doc/src/declarative/righttoleft.qdoc b/doc/src/declarative/righttoleft.qdoc index 2380588..cd294ed 100644 --- a/doc/src/declarative/righttoleft.qdoc +++ b/doc/src/declarative/righttoleft.qdoc @@ -58,7 +58,7 @@ When the horizontal alignment of a text item is not explicitly set, the text ele automatically aligned to the natural reading direction of the text. By default left-to-right text like English is aligned to the left side of the text area, and right-to-left text like Arabic is aligned to the right side of the text area. The alignment of a text element with empty text takes -its alignment cue from \l QApplication::keyboardInputDirection(), which is based on the active +its alignment cue from \l QInputPanel::inputDirection(), which is based on the active system locale. This default locale-based alignment can be overriden by setting the \c horizontalAlignment diff --git a/doc/src/qtquick1/righttoleft.qdoc b/doc/src/qtquick1/righttoleft.qdoc index f3bb601..5afbdff 100644 --- a/doc/src/qtquick1/righttoleft.qdoc +++ b/doc/src/qtquick1/righttoleft.qdoc @@ -58,7 +58,7 @@ When the horizontal alignment of a text item is not explicitly set, the text ele automatically aligned to the natural reading direction of the text. By default left-to-right text like English is aligned to the left side of the text area, and right-to-left text like Arabic is aligned to the right side of the text area. The alignment of a text element with empty text takes -its alignment cue from \l QApplication::keyboardInputDirection(), which is based on the active +its alignment cue from \l QInputPanel::inputDirection(), which is based on the active system locale. This default locale-based alignment can be overriden by setting the \c horizontalAlignment diff --git a/src/qtquick1/graphicsitems/qdeclarativetext.cpp b/src/qtquick1/graphicsitems/qdeclarativetext.cpp index 129ea0b..4434cf8 100644 --- a/src/qtquick1/graphicsitems/qdeclarativetext.cpp +++ b/src/qtquick1/graphicsitems/qdeclarativetext.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -1126,7 +1127,7 @@ bool QDeclarative1TextPrivate::determineHorizontalAlignment() { Q_Q(QDeclarative1Text); if (hAlignImplicit && q->isComponentComplete()) { - bool alignToRight = text.isEmpty() ? QApplication::keyboardInputDirection() == Qt::RightToLeft : rightToLeftText; + bool alignToRight = text.isEmpty() ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft : rightToLeftText; return setHAlign(alignToRight ? QDeclarative1Text::AlignRight : QDeclarative1Text::AlignLeft); } return false; diff --git a/src/qtquick1/graphicsitems/qdeclarativetextedit.cpp b/src/qtquick1/graphicsitems/qdeclarativetextedit.cpp index b42af18..2dd9735 100644 --- a/src/qtquick1/graphicsitems/qdeclarativetextedit.cpp +++ b/src/qtquick1/graphicsitems/qdeclarativetextedit.cpp @@ -560,7 +560,7 @@ bool QDeclarative1TextEditPrivate::determineHorizontalAlignment() ? control->textCursor().block().layout()->preeditAreaText() : QString(); alignToRight = preeditText.isEmpty() - ? QApplication::keyboardInputDirection() == Qt::RightToLeft + ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft : preeditText.isRightToLeft(); } else { alignToRight = rightToLeftText; diff --git a/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp b/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp index bc2734e..cff87fa 100644 --- a/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp +++ b/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp @@ -417,7 +417,7 @@ bool QDeclarative1TextInputPrivate::determineHorizontalAlignment() if (text.isEmpty()) text = control->preeditAreaText(); bool isRightToLeft = text.isEmpty() - ? QApplication::keyboardInputDirection() == Qt::RightToLeft + ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft : text.isRightToLeft(); return setHAlign(isRightToLeft ? QDeclarative1TextInput::AlignRight : QDeclarative1TextInput::AlignLeft); } diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 6948e88..e8eb555 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -1365,7 +1366,7 @@ bool QQuickTextPrivate::setHAlign(QQuickText::HAlignment alignment, bool forceAl bool QQuickTextPrivate::determineHorizontalAlignment() { if (hAlignImplicit) { - bool alignToRight = text.isEmpty() ? QGuiApplication::keyboardInputDirection() == Qt::RightToLeft : rightToLeftText; + bool alignToRight = text.isEmpty() ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft : rightToLeftText; return setHAlign(alignToRight ? QQuickText::AlignRight : QQuickText::AlignLeft); } return false; diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index eba8582..e971ef7 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -556,7 +556,7 @@ bool QQuickTextEditPrivate::determineHorizontalAlignment() if (text.isEmpty()) { const QString preeditText = control->textCursor().block().layout()->preeditAreaText(); alignToRight = preeditText.isEmpty() - ? QGuiApplication::keyboardInputDirection() == Qt::RightToLeft + ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft : preeditText.isRightToLeft(); } else { alignToRight = rightToLeftText; diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 12f02d8..0ef3cd6 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -478,7 +478,8 @@ bool QQuickTextInputPrivate::determineHorizontalAlignment() QString text = q_func()->text(); if (text.isEmpty()) text = m_textLayout.preeditAreaText(); - bool isRightToLeft = text.isEmpty() ? QGuiApplication::keyboardInputDirection() == Qt::RightToLeft : text.isRightToLeft(); + bool isRightToLeft = text.isEmpty() ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft + : text.isRightToLeft(); return setHAlign(isRightToLeft ? QQuickTextInput::AlignRight : QQuickTextInput::AlignLeft); } return false; diff --git a/src/quick/items/qquicktextinput_p_p.h b/src/quick/items/qquicktextinput_p_p.h index 44df9f2..3f28c4a 100644 --- a/src/quick/items/qquicktextinput_p_p.h +++ b/src/quick/items/qquicktextinput_p_p.h @@ -383,7 +383,7 @@ public: Qt::LayoutDirection layoutDirection() const { if (m_layoutDirection == Qt::LayoutDirectionAuto) { if (m_text.isEmpty()) - return QGuiApplication::keyboardInputDirection(); + return qApp->inputPanel()->inputDirection(); return m_text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight; } return m_layoutDirection; diff --git a/tests/auto/qtquick1/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/qtquick1/qdeclarativetext/tst_qdeclarativetext.cpp index 65c1d4e..fa49cd8 100644 --- a/tests/auto/qtquick1/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/qtquick1/qdeclarativetext/tst_qdeclarativetext.cpp @@ -636,9 +636,9 @@ void tst_qdeclarativetext::horizontalAlignment_RightToLeft() #ifndef Q_OS_MAC // QTBUG-18040 // empty text with implicit alignment follows the system locale-based - // keyboard input direction from QApplication::keyboardInputDirection + // keyboard input direction from QInputpanel::inputDirection text->setText(""); - QCOMPARE(text->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(text->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QDeclarative1Text::AlignLeft : QDeclarative1Text::AlignRight); text->setHAlign(QDeclarative1Text::AlignRight); QCOMPARE(text->hAlign(), QDeclarative1Text::AlignRight); @@ -652,7 +652,7 @@ void tst_qdeclarativetext::horizontalAlignment_RightToLeft() QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QDeclarative1Text *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QDeclarative1Text::AlignLeft : QDeclarative1Text::AlignRight); delete textObject; #endif diff --git a/tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 9d9dd89..39ca3cf 100644 --- a/tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -558,11 +558,11 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft() #ifndef Q_OS_MAC // QTBUG-18040 // empty text with implicit alignment follows the system locale-based - // keyboard input direction from QApplication::keyboardInputDirection + // keyboard input direction from QInputPanel::inputDirection textEdit->setText(""); - QCOMPARE(textEdit->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textEdit->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QDeclarative1TextEdit::AlignLeft : QDeclarative1TextEdit::AlignRight); - if (QApplication::keyboardInputDirection() == Qt::LeftToRight) + if (qApp->inputPanel()->inputDirection() == Qt::LeftToRight) QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2); else QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2); @@ -579,7 +579,7 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft() QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QDeclarative1TextEdit *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QDeclarative1TextEdit::AlignLeft : QDeclarative1TextEdit::AlignRight); delete textObject; #endif diff --git a/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index ee6c0d3..8355525 100644 --- a/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1300,11 +1300,11 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() #ifndef Q_OS_MAC // QTBUG-18040 // empty text with implicit alignment follows the system locale-based - // keyboard input direction from QApplication::keyboardInputDirection + // keyboard input direction from QInputPanel::inputDirection textInput->setText(""); - QCOMPARE(textInput->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textInput->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QDeclarative1TextInput::AlignLeft : QDeclarative1TextInput::AlignRight); - if (QApplication::keyboardInputDirection() == Qt::LeftToRight) + if (qApp->inputPanel()->inputDirection() == Qt::LeftToRight) QVERIFY(-textInputPrivate->hscroll < canvas->width()/2); else QVERIFY(-textInputPrivate->hscroll > canvas->width()/2); @@ -1321,7 +1321,7 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QDeclarative1TextInput *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QDeclarative1TextInput::AlignLeft : QDeclarative1TextInput::AlignRight); delete textObject; #endif diff --git a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp index bb27505..b76f764 100644 --- a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp @@ -712,9 +712,9 @@ void tst_qquicktext::horizontalAlignment_RightToLeft() QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() < canvas->width()/2); // empty text with implicit alignment follows the system locale-based - // keyboard input direction from QApplication::keyboardInputDirection + // keyboard input direction from QInputPanel::inputDirection() text->setText(""); - QCOMPARE(text->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(text->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QQuickText::AlignLeft : QQuickText::AlignRight); text->setHAlign(QQuickText::AlignRight); QCOMPARE(text->hAlign(), QQuickText::AlignRight); @@ -726,7 +726,7 @@ void tst_qquicktext::horizontalAlignment_RightToLeft() QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QQuickText::AlignLeft : QQuickText::AlignRight); delete textObject; } diff --git a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp index 7d40bc4..40dc438 100644 --- a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp @@ -714,11 +714,11 @@ void tst_qquicktextedit::hAlign_RightToLeft() { QInputMethodEvent ev; QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); } // empty text with implicit alignment follows the system locale-based - // keyboard input direction from QGuiApplication::keyboardInputDirection + // keyboard input direction from qApp->inputPanel()->inputDirection textEdit->setText(""); - QCOMPARE(textEdit->hAlign(), QGuiApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textEdit->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QQuickTextEdit::AlignLeft : QQuickTextEdit::AlignRight); - if (QGuiApplication::keyboardInputDirection() == Qt::LeftToRight) + if (qApp->inputPanel()->inputDirection() == Qt::LeftToRight) QVERIFY(textEdit->positionToRectangle(0).x() < canvas.width()/2); else QVERIFY(textEdit->positionToRectangle(0).x() > canvas.width()/2); @@ -731,7 +731,7 @@ void tst_qquicktextedit::hAlign_RightToLeft() QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickTextEdit *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->hAlign(), QGuiApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QQuickTextEdit::AlignLeft : QQuickTextEdit::AlignRight); delete textObject; } diff --git a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp index ac60ad3..fa81781 100644 --- a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp @@ -1312,11 +1312,11 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft() { QInputMethodEvent ev; QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); } // empty text with implicit alignment follows the system locale-based - // keyboard input direction from QGuiApplication::keyboardInputDirection + // keyboard input direction from QInputPanel::inputDirection() textInput->setText(""); - QCOMPARE(textInput->hAlign(), QGuiApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textInput->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QQuickTextInput::AlignLeft : QQuickTextInput::AlignRight); - if (QGuiApplication::keyboardInputDirection() == Qt::LeftToRight) { + if (qApp->inputPanel()->inputDirection() == Qt::LeftToRight) { QCOMPARE(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll, qreal(0)); } else { QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1); @@ -1331,7 +1331,7 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft() QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickTextInput *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->hAlign(), QGuiApplication::keyboardInputDirection() == Qt::LeftToRight ? + QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ? QQuickTextInput::AlignLeft : QQuickTextInput::AlignRight); delete textObject; } -- 2.7.4