Information moved from QGuiApplication into QInputPanel.
Change-Id: Idd80609f4b67bffae7222a1fa27918724ebf60f6
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
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
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
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <QAbstractTextDocumentLayout>
+#include <QtGui/QInputPanel>
#include <qmath.h>
#include <limits.h>
{
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;
? control->textCursor().block().layout()->preeditAreaText()
: QString();
alignToRight = preeditText.isEmpty()
- ? QApplication::keyboardInputDirection() == Qt::RightToLeft
+ ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft
: preeditText.isRightToLeft();
} else {
alignToRight = rightToLeftText;
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);
}
#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>
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;
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;
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;
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;
#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);
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
#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);
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
#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);
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
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);
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;
}
{ 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);
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;
}
{ 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);
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;
}