Update the cursor rectangle when password echo timer expires.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Fri, 25 May 2012 06:02:41 +0000 (16:02 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 29 May 2012 06:54:52 +0000 (08:54 +0200)
Ensures the cursor is positioned correctly is if the echo mask glyph
has a different width to the character it replaced.

Change-Id: I924234d4ae29cbb2e61638918005fcc3dc230993
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
src/quick/items/qquicktextinput.cpp
tests/auto/quick/qquicktextinput/data/echoMode.qml
tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp

index 06a5726..95368fd 100644 (file)
@@ -3995,6 +3995,7 @@ void QQuickTextInput::timerEvent(QTimerEvent *event)
     } else if (event->timerId() == d->m_passwordEchoTimer.timerId()) {
         d->m_passwordEchoTimer.stop();
         d->updateDisplayText();
+        updateCursorRectangle();
     }
 }
 
index f8a6cf1..94e0a0e 100644 (file)
@@ -6,6 +6,10 @@ Rectangle {
     width: 400; height: 200; color: "green"
 
     TextInput { id: input; focus: true
+        width: 400; height: 200
         text: "ABCDefgh"
+        cursorDelegate: Rectangle {
+            objectName: "cursor"
+        }
     }
 }
index 0a213d7..d857d9c 100644 (file)
@@ -2970,6 +2970,10 @@ void tst_qquicktextinput::passwordEchoDelay()
     QVERIFY(canvas.rootObject() != 0);
 
     QQuickTextInput *input = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(canvas.rootObject()->property("myInput")));
+    QVERIFY(input);
+
+    QQuickItem *cursor = input->findChild<QQuickItem *>("cursor");
+    QVERIFY(cursor);
 
     QChar fillChar = QLatin1Char('*');
 
@@ -2989,8 +2993,17 @@ void tst_qquicktextinput::passwordEchoDelay()
     QCOMPARE(input->displayText(), QString(4, fillChar));
     QTest::keyPress(&canvas, '4');
     QCOMPARE(input->displayText(), QString(4, fillChar) + QLatin1Char('4'));
+    QCOMPARE(input->cursorRectangle().topLeft(), cursor->pos());
+
+    // Verify the last character entered is replaced by the fill character after a delay.
+    // Also check the cursor position is updated to accomdate a size difference between
+    // the fill character and the replaced character.
+    QSignalSpy cursorSpy(input, SIGNAL(cursorRectangleChanged()));
     QTest::qWait(maskDelay);
     QTRY_COMPARE(input->displayText(), QString(5, fillChar));
+    QCOMPARE(cursorSpy.count(), 1);
+    QCOMPARE(input->cursorRectangle().topLeft(), cursor->pos());
+
     QTest::keyPress(&canvas, '5');
     QCOMPARE(input->displayText(), QString(5, fillChar) + QLatin1Char('5'));
     input->setFocus(false);