Skip to content

Commit

Permalink
Fix failing tst_qquicktextinput::horizontalAlignment_RightToLeft test.
Browse files Browse the repository at this point in the history
How the text is laid out is dependent on the horizontalAlignment so
that needs to be determined before updating the display text and doing
the layout.

Task-number: QTBUG-23485
Change-Id: I1872b1bfc60fd829a0d69c21a19cd3b2b4dc8340
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
  • Loading branch information
Andrew den Exter authored and Qt by Nokia committed Jan 12, 2012
1 parent f895741 commit 21e6e0e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/quick/items/qquicktextinput.cpp
Expand Up @@ -2962,7 +2962,6 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo
m_validInput = true;
m_textDirty = false;
}
updateDisplayText();

if (m_textDirty) {
m_textDirty = false;
Expand All @@ -2971,6 +2970,8 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo
emit q->textChanged();
}

updateDisplayText();

if (m_validInput != wasValidInput)
emit q->acceptableInputChanged();
}
Expand Down
44 changes: 25 additions & 19 deletions tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp
Expand Up @@ -1228,57 +1228,63 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft()

QQuickTextInputPrivate *textInputPrivate = QQuickTextInputPrivate::get(textInput);
QVERIFY(textInputPrivate != 0);
QVERIFY(textInputPrivate->boundingRect.left() > canvas.width()/2);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1);

// implicit alignment should follow the reading direction of RTL text
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight);
QCOMPARE(textInput->effectiveHAlign(), textInput->hAlign());
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll > canvas.width()/2);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1);

// explicitly left aligned
textInput->setHAlign(QQuickTextInput::AlignLeft);
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignLeft);
QCOMPARE(textInput->effectiveHAlign(), textInput->hAlign());
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll < canvas.width()/2);
QCOMPARE(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll, qreal(0));

// explicitly right aligned
textInput->setHAlign(QQuickTextInput::AlignRight);
QCOMPARE(textInput->effectiveHAlign(), textInput->hAlign());
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight);
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll > canvas.width()/2);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1);

// explicitly center aligned
textInput->setHAlign(QQuickTextInput::AlignHCenter);
QCOMPARE(textInput->effectiveHAlign(), textInput->hAlign());
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignHCenter);
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll < canvas.width()/2);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll > canvas.width()/2);
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll > 0);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll < textInput->width());

// reseted alignment should go back to following the text reading direction
textInput->resetHAlign();
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight);
QCOMPARE(textInput->effectiveHAlign(), textInput->hAlign());
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll > canvas.width()/2);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1);

// mirror the text item
QQuickItemPrivate::get(textInput)->setLayoutMirror(true);

// mirrored implicit alignment should continue to follow the reading direction of the text
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight);
QCOMPARE(textInput->effectiveHAlign(), textInput->hAlign());
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll > canvas.width()/2);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1);

// explicitly right aligned behaves as left aligned
textInput->setHAlign(QQuickTextInput::AlignRight);
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight);
QCOMPARE(textInput->effectiveHAlign(), QQuickTextInput::AlignLeft);
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll < canvas.width()/2);
QCOMPARE(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll, qreal(0));

// mirrored explicitly left aligned behaves as right aligned
textInput->setHAlign(QQuickTextInput::AlignLeft);
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignLeft);
QCOMPARE(textInput->effectiveHAlign(), QQuickTextInput::AlignRight);
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll > canvas.width()/2);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll >= textInput->width() - 1);
QVERIFY(textInputPrivate->boundingRect.right() - textInputPrivate->hscroll <= textInput->width() + 1);

// disable mirroring
QQuickItemPrivate::get(textInput)->setLayoutMirror(false);
Expand All @@ -1288,10 +1294,7 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft()
// English text should be implicitly left aligned
textInput->setText("Hello world!");
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignLeft);
#ifdef Q_OS_MAC
QEXPECT_FAIL("", "QTBUG-23485", Abort);
#endif
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll < canvas.width()/2);
QCOMPARE(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll, qreal(0));

canvas.requestActivateWindow();
QTest::qWaitForWindowShown(&canvas);
Expand All @@ -1313,13 +1316,16 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft()
textInput->setText("");
QCOMPARE(textInput->hAlign(), QGuiApplication::keyboardInputDirection() == Qt::LeftToRight ?
QQuickTextInput::AlignLeft : QQuickTextInput::AlignRight);
if (QGuiApplication::keyboardInputDirection() == Qt::LeftToRight)
QVERIFY(textInput->boundingRect().left() < canvas.width()/2);
else
QVERIFY(textInput->boundingRect().left() > canvas.width()/2);
if (QGuiApplication::keyboardInputDirection() == 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);
QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight);
QVERIFY(textInputPrivate->boundingRect.left() - textInputPrivate->hscroll > canvas.width()/2);
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);
Expand Down

0 comments on commit 21e6e0e

Please sign in to comment.