Fix right aligned cursor position in TextInput with geometry changes
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Wed, 13 Jun 2012 11:51:00 +0000 (14:51 +0300)
committerQt by Nokia <qt-info@nokia.com>
Mon, 25 Jun 2012 01:19:10 +0000 (03:19 +0200)
Updating the text layout cannot be omitted with NoWrap because line width
needs to be updated even with empty content.

Change-Id: Ia9b168d6cfe7680cc1c9e7fa641ce7528d2b6d5e
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
src/quick/items/qquicktextinput.cpp
tests/auto/quick/qquicktextinput/data/horizontalAlignment_RightToLeft.qml
tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp

index 0d05d6f..30512a1 100644 (file)
@@ -1588,7 +1588,7 @@ void QQuickTextInput::geometryChanged(const QRectF &newGeometry,
 {
     Q_D(QQuickTextInput);
     if (!d->inLayout) {
-        if (newGeometry.width() != oldGeometry.width() && d->wrapMode != NoWrap)
+        if (newGeometry.width() != oldGeometry.width())
             d->updateLayout();
         updateCursorRectangle();
     }
index d14caea..cf09250 100644 (file)
@@ -16,7 +16,9 @@ Rectangle {
         TextInput {
             id: text
             objectName: "text"
-            anchors.fill: parent
+            anchors.left: parent.left
+            anchors.top: parent.top
+            width: 180
             text: top.text
             focus: true
 
index 5044f48..a87cbeb 100644 (file)
@@ -1441,6 +1441,11 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft()
     QCOMPARE(textInput->effectiveHAlign(), QQuickTextInput::AlignLeft);
     platformInputContext.setInputDirection(Qt::RightToLeft);
     QCOMPARE(textInput->effectiveHAlign(), QQuickTextInput::AlignRight);
+
+    // changing width keeps right aligned cursor on proper position
+    textInput->setText("");
+    textInput->setWidth(500);
+    QVERIFY(textInput->positionToRectangle(0).x() > textInput->width() / 2);
 }
 
 void tst_qquicktextinput::verticalAlignment()