Fix expected failure in TextEdit hAlign_RightToLeft test.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Wed, 9 Nov 2011 05:09:12 +0000 (15:09 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 9 Nov 2011 08:55:01 +0000 (09:55 +0100)
Send events to the input item instead of the canvas.  And apply the fix
from 4.8 for the tested condition which somehow wasn't applied when the
test itself was.

Change-Id: I0f5bfe8fc13fc426b395fa8ef87cb5549789a92e
Reviewed-by: Martin Jones <martin.jones@nokia.com>

src/declarative/items/qquicktextedit.cpp
tests/auto/declarative/qquicktextedit/tst_qquicktextedit.cpp

index 6d66ed9..18d2cb8 100644 (file)
@@ -550,7 +550,15 @@ bool QQuickTextEditPrivate::determineHorizontalAlignment()
 {
     Q_Q(QQuickTextEdit);
     if (hAlignImplicit && q->isComponentComplete()) {
-        bool alignToRight = text.isEmpty() ? QGuiApplication::keyboardInputDirection() == Qt::RightToLeft : rightToLeftText;
+        bool alignToRight;
+        if (text.isEmpty()) {
+            const QString preeditText = control->textCursor().block().layout()->preeditAreaText();
+            alignToRight = preeditText.isEmpty()
+                    ? QGuiApplication::keyboardInputDirection() == Qt::RightToLeft
+                    : preeditText.isRightToLeft();
+        } else {
+            alignToRight = rightToLeftText;
+        }
         return setHAlign(alignToRight ? QQuickTextEdit::AlignRight : QQuickTextEdit::AlignLeft);
     }
     return false;
index a23fc76..edb3eb3 100644 (file)
@@ -572,12 +572,15 @@ void tst_qquicktextedit::hAlign_RightToLeft()
     QTRY_COMPARE(&canvas, qGuiApp->focusWindow());
 
     textEdit->setText(QString());
-    { QInputMethodEvent ev(rtlText, QList<QInputMethodEvent::Attribute>()); QGuiApplication::sendEvent(&canvas, &ev); }
-    QEXPECT_FAIL("", "QTBUG-21691", Abort);
+    { QInputMethodEvent ev(rtlText, QList<QInputMethodEvent::Attribute>()); QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); }
     QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignRight);
-    { QInputMethodEvent ev("Hello world!", QList<QInputMethodEvent::Attribute>()); QGuiApplication::sendEvent(&canvas, &ev); }
+    { QInputMethodEvent ev("Hello world!", QList<QInputMethodEvent::Attribute>()); QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); }
     QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignLeft);
 
+    // Clear pre-edit text.  TextEdit should maybe do this itself on setText, but that may be
+    // redundant as an actual input method may take care of it.
+    { QInputMethodEvent ev; QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); }
+
 #ifndef Q_OS_MAC    // QTBUG-18040
     // empty text with implicit alignment follows the system locale-based
     // keyboard input direction from QGuiApplication::keyboardInputDirection