aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-05-25 16:41:14 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-05 03:22:18 +0200
commit5b83c3c27f95f14fba11d905a293797ebc543bf2 (patch)
tree0447a2b3741a81d968f87b0754292318c33351d2
parent1346c668cb65a8906cf31fc7e5a3a5f817f15af6 (diff)
Ensure the cursor delegate position is updated on text changes.
Change-Id: I7518aa5969ea45538feccb87f4c296db6b7d6944 Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
-rw-r--r--src/quick/items/qquicktextinput.cpp6
-rw-r--r--tests/auto/quick/qquicktextedit/data/cursorTest.qml1
-rw-r--r--tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml1
-rw-r--r--tests/auto/quick/qquicktextedit/data/cursorTestInline.qml1
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp19
-rw-r--r--tests/auto/quick/qquicktextinput/data/cursorTest.qml1
-rw-r--r--tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml1
-rw-r--r--tests/auto/quick/qquicktextinput/data/cursorTestInline.qml1
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp21
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());
}