Adapt to QInputPanel::inputDirection() API
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Thu, 5 Jan 2012 14:33:56 +0000 (16:33 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 12 Jan 2012 15:21:35 +0000 (16:21 +0100)
Information moved from QGuiApplication into QInputPanel.

Change-Id: Idd80609f4b67bffae7222a1fa27918724ebf60f6
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
15 files changed:
doc/src/declarative/righttoleft.qdoc
doc/src/qtquick1/righttoleft.qdoc
src/qtquick1/graphicsitems/qdeclarativetext.cpp
src/qtquick1/graphicsitems/qdeclarativetextedit.cpp
src/qtquick1/graphicsitems/qdeclarativetextinput.cpp
src/quick/items/qquicktext.cpp
src/quick/items/qquicktextedit.cpp
src/quick/items/qquicktextinput.cpp
src/quick/items/qquicktextinput_p_p.h
tests/auto/qtquick1/qdeclarativetext/tst_qdeclarativetext.cpp
tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp

index 2380588..cd294ed 100644 (file)
@@ -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
index f3bb601..5afbdff 100644 (file)
@@ -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
index 129ea0b..4434cf8 100644 (file)
@@ -52,6 +52,7 @@
 #include <QGraphicsSceneMouseEvent>
 #include <QPainter>
 #include <QAbstractTextDocumentLayout>
+#include <QtGui/QInputPanel>
 #include <qmath.h>
 #include <limits.h>
 
@@ -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;
index b42af18..2dd9735 100644 (file)
@@ -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;
index bc2734e..cff87fa 100644 (file)
@@ -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);
     }
index 6948e88..e8eb555 100644 (file)
@@ -56,6 +56,7 @@
 #include <QtGui/qtextobject.h>
 #include <QtGui/qtextcursor.h>
 #include <QtGui/qguiapplication.h>
+#include <QtGui/qinputpanel.h>
 
 #include <private/qdeclarativestyledtext_p.h>
 #include <QtQuick/private/qdeclarativepixmapcache_p.h>
@@ -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;
index eba8582..e971ef7 100644 (file)
@@ -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;
index 12f02d8..0ef3cd6 100644 (file)
@@ -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;
index 44df9f2..3f28c4a 100644 (file)
@@ -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;
index 65c1d4e..fa49cd8 100644 (file)
@@ -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<QDeclarative1Text*>(textComponent.create());
-    QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+    QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ?
                                   QDeclarative1Text::AlignLeft : QDeclarative1Text::AlignRight);
     delete textObject;
 #endif
index 9d9dd89..39ca3cf 100644 (file)
@@ -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<QDeclarative1TextEdit*>(textComponent.create());
-    QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+    QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ?
                                   QDeclarative1TextEdit::AlignLeft : QDeclarative1TextEdit::AlignRight);
     delete textObject;
 #endif
index ee6c0d3..8355525 100644 (file)
@@ -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<QDeclarative1TextInput*>(textComponent.create());
-    QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+    QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ?
                                   QDeclarative1TextInput::AlignLeft : QDeclarative1TextInput::AlignRight);
     delete textObject;
 #endif
index bb27505..b76f764 100644 (file)
@@ -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<QQuickText*>(textComponent.create());
-    QCOMPARE(textObject->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ?
+    QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ?
                                   QQuickText::AlignLeft : QQuickText::AlignRight);
     delete textObject;
 }
index 7d40bc4..40dc438 100644 (file)
@@ -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<QQuickTextEdit*>(textComponent.create());
-    QCOMPARE(textObject->hAlign(), QGuiApplication::keyboardInputDirection() == Qt::LeftToRight ?
+    QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ?
                                   QQuickTextEdit::AlignLeft : QQuickTextEdit::AlignRight);
     delete textObject;
 }
index ac60ad3..fa81781 100644 (file)
@@ -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<QQuickTextInput*>(textComponent.create());
-    QCOMPARE(textObject->hAlign(), QGuiApplication::keyboardInputDirection() == Qt::LeftToRight ?
+    QCOMPARE(textObject->hAlign(), qApp->inputPanel()->inputDirection() == Qt::LeftToRight ?
                                   QQuickTextInput::AlignLeft : QQuickTextInput::AlignRight);
     delete textObject;
 }