diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2011-03-08 04:33:29 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2011-03-08 06:58:11 (GMT) |
commit | 54de06c6f3bd7ef74a10bfab9bff5416078edd6f (patch) | |
tree | 80e49e446f417138bae41750a0b179b4a0e5299c | |
parent | c783cbfe3839d7a4c0f75613d2a94e8cfb7a29d1 (diff) | |
download | Qt-54de06c6f3bd7ef74a10bfab9bff5416078edd6f.zip Qt-54de06c6f3bd7ef74a10bfab9bff5416078edd6f.tar.gz Qt-54de06c6f3bd7ef74a10bfab9bff5416078edd6f.tar.bz2 |
Base empty QML editor horizontal alignment on QApplication::keyboardInputDirection()
Task-number: QTBUG-15880
Reviewed-by: Martin Jones
Change-Id: I240d53c8572fd3d1222b555e93812a3ee38e2558
6 files changed, 28 insertions, 11 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 4a931fd..f0d0221 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -1120,7 +1120,8 @@ bool QDeclarativeTextPrivate::determineHorizontalAlignment() Q_Q(QDeclarativeText); if (hAlignImplicit && q->isComponentComplete()) { // if no explicit alignment has been set, follow the natural layout direction of the text - return setHAlign(text.isRightToLeft() ? QDeclarativeText::AlignRight : QDeclarativeText::AlignLeft); + bool isRightToLeft = text.isEmpty() ? QApplication::keyboardInputDirection() == Qt::RightToLeft : text.isRightToLeft(); + return setHAlign(isRightToLeft ? QDeclarativeText::AlignRight : QDeclarativeText::AlignLeft); } return false; } diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 75a22d1..d1d2351 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -550,7 +550,8 @@ bool QDeclarativeTextEditPrivate::determineHorizontalAlignment() Q_Q(QDeclarativeTextEdit); if (hAlignImplicit && q->isComponentComplete()) { // if no explicit alignment has been set, follow the natural layout direction of the text - return setHAlign(text.isRightToLeft() ? QDeclarativeTextEdit::AlignRight : QDeclarativeTextEdit::AlignLeft); + bool isRightToLeft = text.isEmpty() ? QApplication::keyboardInputDirection() == Qt::RightToLeft : text.isRightToLeft(); + return setHAlign(isRightToLeft ? QDeclarativeTextEdit::AlignRight : QDeclarativeTextEdit::AlignLeft); } return false; } diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 6305eaa..850c212 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -411,7 +411,9 @@ bool QDeclarativeTextInputPrivate::determineHorizontalAlignment() { if (hAlignImplicit) { // if no explicit alignment has been set, follow the natural layout direction of the text - return setHAlign(control->text().isRightToLeft() ? QDeclarativeTextInput::AlignRight : QDeclarativeTextInput::AlignLeft); + QString text = control->text(); + bool isRightToLeft = text.isEmpty() ? QApplication::keyboardInputDirection() == Qt::RightToLeft : text.isRightToLeft(); + return setHAlign(isRightToLeft ? QDeclarativeTextInput::AlignRight : QDeclarativeTextInput::AlignLeft); } return false; } @@ -1872,6 +1874,7 @@ void QDeclarativeTextInputPrivate::init() QPalette p = control->palette(); selectedTextColor = p.color(QPalette::HighlightedText); selectionColor = p.color(QPalette::Highlight); + determineHorizontalAlignment(); } void QDeclarativeTextInput::cursorPosChanged() diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 261dc51..c854f86 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -576,9 +576,11 @@ void tst_qdeclarativetext::horizontalAlignment_RightToLeft() QCOMPARE(text->hAlign(), QDeclarativeText::AlignLeft); QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() < canvas->width()/2); - // empty text is also implicitly left aligned + // empty text with implicit alignment follows the system locale-based + // keyboard input direction from QApplication::keyboardInputDirection text->setText(""); - QCOMPARE(text->hAlign(), QDeclarativeText::AlignLeft); + QCOMPARE(text->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QDeclarativeText::AlignLeft : QDeclarativeText::AlignRight); text->setHAlign(QDeclarativeText::AlignRight); QCOMPARE(text->hAlign(), QDeclarativeText::AlignRight); diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 7a0ca12..4d94dae 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -500,10 +500,15 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft() QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignLeft); QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2); - // empty text is also implicitly left aligned + // empty text with implicit alignment follows the system locale-based + // keyboard input direction from QApplication::keyboardInputDirection textEdit->setText(""); - QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignLeft); - QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2); + QCOMPARE(textEdit->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QDeclarativeTextEdit::AlignLeft : QDeclarativeTextEdit::AlignRight); + if (QApplication::keyboardInputDirection() == Qt::LeftToRight) + QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2); + else + QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2); textEdit->setHAlign(QDeclarativeTextEdit::AlignRight); QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight); QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2); diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 5c8b59c..caada13 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1110,10 +1110,15 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignLeft); QVERIFY(-textInputPrivate->hscroll < canvas->width()/2); - // empty text is also implicitly left aligned + // empty text with implicit alignment follows the system locale-based + // keyboard input direction from QApplication::keyboardInputDirection textInput->setText(""); - QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignLeft); - QVERIFY(-textInputPrivate->hscroll < canvas->width()/2); + QCOMPARE(textInput->hAlign(), QApplication::keyboardInputDirection() == Qt::LeftToRight ? + QDeclarativeTextInput::AlignLeft : QDeclarativeTextInput::AlignRight); + if (QApplication::keyboardInputDirection() == Qt::LeftToRight) + QVERIFY(-textInputPrivate->hscroll < canvas->width()/2); + else + QVERIFY(-textInputPrivate->hscroll > canvas->width()/2); textInput->setHAlign(QDeclarativeTextInput::AlignRight); QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignRight); QVERIFY(-textInputPrivate->hscroll > canvas->width()/2); |