Fix TextEdit with right aligned text when size changes
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Fri, 20 Apr 2012 14:18:53 +0000 (17:18 +0300)
committerQt by Nokia <qt-info@nokia.com>
Fri, 27 Apr 2012 11:47:21 +0000 (13:47 +0200)
Geometry change was avoiding updating size of the QTextDocument, thus
it was not able to right align before something else triggered size
change, e.g. a modification to the text. Also removed unnecessary
cursorRectangleChanged signal that was emitted when moving focus with
mouse.

Change-Id: I293fd5119473eb3def5acd1b3fbb951c12e14412
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
src/quick/items/qquicktextcontrol.cpp
src/quick/items/qquicktextedit.cpp
tests/auto/quick/qquicktextedit/data/horizontalAlignment_RightToLeft.qml
tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp

index 7fa990b..8bc94b9 100644 (file)
@@ -1206,18 +1206,14 @@ void QQuickTextControlPrivate::mousePressEvent(QMouseEvent *e, const QPointF &po
         }
     }
 
-    if (interactionFlags & Qt::TextEditable) {
+    if (cursor.position() != oldCursorPos) {
         q->updateCursorRectangle(true);
-        if (cursor.position() != oldCursorPos)
-            emit q->cursorPositionChanged();
+        emit q->cursorPositionChanged();
+    }
+    if (interactionFlags & Qt::TextEditable)
         _q_updateCurrentCharFormatAndSelection();
-    } else {
-        if (cursor.position() != oldCursorPos) {
-            emit q->cursorPositionChanged();
-            q->updateCursorRectangle(true);
-        }
+    else
         selectionChanged();
-    }
     repaintOldAndNewSelection(oldSelection);
     hadSelectionOnMousePress = cursor.hasSelection();
 }
index cd5f262..fc02815 100644 (file)
@@ -1144,7 +1144,7 @@ void QQuickTextEdit::geometryChanged(const QRectF &newGeometry,
                                   const QRectF &oldGeometry)
 {
     Q_D(QQuickTextEdit);
-    if (newGeometry.width() != oldGeometry.width() && d->wrapMode != NoWrap && widthValid() && !d->inLayout) {
+    if (newGeometry.width() != oldGeometry.width() && widthValid() && !d->inLayout) {
         updateSize();
         moveCursorDelegate();
     }
index 2163838..8231e3f 100644 (file)
@@ -8,6 +8,7 @@ Rectangle {
     property string text: "اختبا"
 
     Rectangle {
+        id: arabicContainer
         anchors.centerIn: parent
         width: 200
         height: 20
@@ -22,4 +23,19 @@ Rectangle {
             textFormat: TextEdit.AutoText
         }
     }
+
+    Rectangle {
+        anchors.top: arabicContainer.bottom
+        anchors.left: arabicContainer.left
+        width: 200
+        height: 20
+        color: "green"
+
+        TextEdit {
+            id: emptyTextEdit
+            objectName: "emptyTextEdit"
+            anchors.fill: parent
+            textFormat: TextEdit.AutoText
+        }
+    }
 }
index 9c34a7c..0bc48c9 100644 (file)
@@ -772,6 +772,14 @@ void tst_qquicktextedit::hAlign_RightToLeft()
     textEdit->setHAlign(QQuickTextEdit::AlignRight);
     QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignRight);
     QVERIFY(textEdit->positionToRectangle(0).x() > canvas.width()/2);
+
+    // make sure editor doesn't rely on input for updating size
+    QQuickTextEdit *emptyEdit = canvas.rootObject()->findChild<QQuickTextEdit*>("emptyTextEdit");
+    QVERIFY(emptyEdit != 0);
+    platformInputContext.setInputDirection(Qt::RightToLeft);
+    emptyEdit->setFocus(true);
+    QCOMPARE(emptyEdit->hAlign(), QQuickTextEdit::AlignRight);
+    QVERIFY(emptyEdit->cursorRectangle().left() > canvas.width()/2);
 }
 
 void tst_qquicktextedit::vAlign()