Ensure the cursor delegate position is updated on text changes.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Fri, 25 May 2012 06:41:14 +0000 (16:41 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 5 Jun 2012 01:22:18 +0000 (03:22 +0200)
Change-Id: I7518aa5969ea45538feccb87f4c296db6b7d6944
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
src/quick/items/qquicktextinput.cpp
tests/auto/quick/qquicktextedit/data/cursorTest.qml
tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml
tests/auto/quick/qquicktextedit/data/cursorTestInline.qml
tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
tests/auto/quick/qquicktextinput/data/cursorTest.qml
tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml
tests/auto/quick/qquicktextinput/data/cursorTestInline.qml
tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp

index 95368fd..873cdd4 100644 (file)
@@ -3172,9 +3172,9 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event)
     m_textLayout.setAdditionalFormats(formats);
 
     updateDisplayText(/*force*/ true);
-    if (cursorPositionChanged) {
-        emitCursorPositionChanged();
-    } else if (m_preeditCursor != oldPreeditCursor || isGettingInput) {
+    if ((cursorPositionChanged && !emitCursorPositionChanged())
+            || m_preeditCursor != oldPreeditCursor
+            || isGettingInput) {
         q->updateCursorRectangle();
     }
 
index 7bfc869..afccc68 100644 (file)
@@ -3,6 +3,7 @@ import QtQuick 2.0
 Rectangle { width: 300; height: 300; color: "white"
     property string contextualProperty: "Hello"
     TextEdit {  text: "Hello world!"; id: textEditObject; objectName: "textEditObject"
+        width: 300; height: 300;
         resources: [ Component { id:cursor; Item { id:cursorInstance; objectName: "cursorInstance"; property string localProperty: contextualProperty } } ]
         cursorDelegate: cursor
     }
index 8eed022..0c9679b 100644 (file)
@@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white"
         text: "Hello world!"
         id: textEditObject;
         objectName: "textEditObject"
+        width: 300; height: 300
         wrapMode: TextEdit.WordWrap
         cursorDelegate: Cursor {
             id:cursorInstance;
index bda1710..6e2ed8c 100644 (file)
@@ -7,6 +7,7 @@ Rectangle { width: 300; height: 300; color: "white"
         id: textEditObject
         wrapMode: TextEdit.Wrap
         objectName: "textEditObject"
+        width: 300; height: 300
         cursorDelegate: Item {
             id:cursorInstance
             objectName: "cursorInstance"
index 298a93c..80d81cc 100644 (file)
@@ -2101,6 +2101,8 @@ void tst_qquicktextedit::cursorDelegate()
     QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x());
     QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y());
 
+    textEditObject->setReadOnly(false);
+
     // Delegate moved when text is entered
     textEditObject->setText(QString());
     for (int i = 0; i < 20; ++i) {
@@ -2114,7 +2116,22 @@ void tst_qquicktextedit::cursorDelegate()
     for (int i = 0; i < 20; ++i) {
         QInputMethodEvent event;
         event.setCommitString("a");
-        QGuiApplication::sendEvent(&view, &event);
+        QGuiApplication::sendEvent(textEditObject, &event);
+        QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x());
+        QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y());
+    }
+    // Delegate moved when text is removed by im.
+    for (int i = 19; i > 1; --i) {
+        QInputMethodEvent event;
+        event.setCommitString(QString(), -1, 1);
+        QGuiApplication::sendEvent(textEditObject, &event);
+        QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x());
+        QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y());
+    }
+    {   // Delegate moved the text is changed in place by im.
+        QInputMethodEvent event;
+        event.setCommitString("i", -1, 1);
+        QGuiApplication::sendEvent(textEditObject, &event);
         QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x());
         QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y());
     }
index 71a420e..363d371 100644 (file)
@@ -3,6 +3,7 @@ import QtQuick 2.0
 Rectangle { id:rect; width: 300; height: 300; color: "white"
     property string contextualProperty: "Hello"
     TextInput {  text: "Hello world!"; id: textInputObject; objectName: "textInputObject"
+        width: 300; height: 300
         resources: [ Component { id:cursor; Item { id:cursorInstance; objectName: "cursorInstance"; property string localProperty: contextualProperty } } ]
         cursorDelegate: cursor
     }
index 2f43449..31ee01d 100644 (file)
@@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white"
         text: "Hello world!"
         id: textInputObject;
         objectName: "textInputObject"
+        width: 300; height: 300
         wrapMode: TextInput.Wrap
         cursorDelegate: Cursor {
             id:cursorInstance;
index e51a2f3..b699ed2 100644 (file)
@@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white"
         text: "Hello world!"
         id: textInputObject
         objectName: "textInputObject"
+        width: 300; height: 300
         wrapMode: TextInput.WordWrap
         cursorDelegate: Item {
             id:cursorInstance
index d857d9c..1742335 100644 (file)
@@ -2547,6 +2547,8 @@ void tst_qquicktextinput::cursorDelegate()
     QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
     QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
 
+    textInputObject->setReadOnly(false);
+
     // Delegate moved when text is entered
     textInputObject->setText(QString());
     for (int i = 0; i < 20; ++i) {
@@ -2559,8 +2561,23 @@ void tst_qquicktextinput::cursorDelegate()
     textInputObject->setText(QString());
     for (int i = 0; i < 20; ++i) {
         QInputMethodEvent event;
-        event.setCommitString("a");
-        QGuiApplication::sendEvent(&view, &event);
+        event.setCommitString("w");
+        QGuiApplication::sendEvent(textInputObject, &event);
+        QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+        QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+    }
+    // Delegate moved when text is removed by im.
+    for (int i = 19; i > 1; --i) {
+        QInputMethodEvent event;
+        event.setCommitString(QString(), -1, 1);
+        QGuiApplication::sendEvent(textInputObject, &event);
+        QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+        QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+    }
+    {   // Delegate moved the text is changed in place by im.
+        QInputMethodEvent event;
+        event.setCommitString("i", -1, 1);
+        QGuiApplication::sendEvent(textInputObject, &event);
         QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
         QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
     }