From 5b83c3c27f95f14fba11d905a293797ebc543bf2 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 25 May 2012 16:41:14 +1000 Subject: Ensure the cursor delegate position is updated on text changes. Change-Id: I7518aa5969ea45538feccb87f4c296db6b7d6944 Reviewed-by: Yann Bodson --- src/quick/items/qquicktextinput.cpp | 6 +++--- tests/auto/quick/qquicktextedit/data/cursorTest.qml | 1 + .../qquicktextedit/data/cursorTestExternal.qml | 1 + .../quick/qquicktextedit/data/cursorTestInline.qml | 1 + .../quick/qquicktextedit/tst_qquicktextedit.cpp | 19 ++++++++++++++++++- .../auto/quick/qquicktextinput/data/cursorTest.qml | 1 + .../qquicktextinput/data/cursorTestExternal.qml | 1 + .../quick/qquicktextinput/data/cursorTestInline.qml | 1 + .../quick/qquicktextinput/tst_qquicktextinput.cpp | 21 +++++++++++++++++++-- 9 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 95368fd465..873cdd463c 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -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(); } diff --git a/tests/auto/quick/qquicktextedit/data/cursorTest.qml b/tests/auto/quick/qquicktextedit/data/cursorTest.qml index 7bfc869403..afccc68aed 100644 --- a/tests/auto/quick/qquicktextedit/data/cursorTest.qml +++ b/tests/auto/quick/qquicktextedit/data/cursorTest.qml @@ -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 } diff --git a/tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml b/tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml index 8eed022c2f..0c9679bade 100644 --- a/tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml +++ b/tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml @@ -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; diff --git a/tests/auto/quick/qquicktextedit/data/cursorTestInline.qml b/tests/auto/quick/qquicktextedit/data/cursorTestInline.qml index bda171018a..6e2ed8c7a8 100644 --- a/tests/auto/quick/qquicktextedit/data/cursorTestInline.qml +++ b/tests/auto/quick/qquicktextedit/data/cursorTestInline.qml @@ -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" diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 298a93cf58..80d81ccc0b 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -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()); } diff --git a/tests/auto/quick/qquicktextinput/data/cursorTest.qml b/tests/auto/quick/qquicktextinput/data/cursorTest.qml index 71a420ee7c..363d37174b 100644 --- a/tests/auto/quick/qquicktextinput/data/cursorTest.qml +++ b/tests/auto/quick/qquicktextinput/data/cursorTest.qml @@ -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 } diff --git a/tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml b/tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml index 2f43449052..31ee01db99 100644 --- a/tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml +++ b/tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml @@ -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; diff --git a/tests/auto/quick/qquicktextinput/data/cursorTestInline.qml b/tests/auto/quick/qquicktextinput/data/cursorTestInline.qml index e51a2f3401..b699ed2752 100644 --- a/tests/auto/quick/qquicktextinput/data/cursorTestInline.qml +++ b/tests/auto/quick/qquicktextinput/data/cursorTestInline.qml @@ -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 diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index d857d9ce6b..174233505a 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -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()); } -- cgit v1.2.3