Blame SOURCES/0018-QQuickTextInput-update-cursor-rectangle-after-paddin.patch

966857
From 9bb03b5dcc21275986df3d8b0efb6f28cdc583ec Mon Sep 17 00:00:00 2001
966857
From: Wang Chuan <ouchuanm@outlook.com>
966857
Date: Mon, 5 Apr 2021 11:41:48 +0800
966857
Subject: [PATCH 18/20] QQuickTextInput: update cursor rectangle after padding
966857
 changed
966857
966857
The position of cursor delegate needs to be updated when we change
966857
padding, otherwise it will be in a wrong position.
966857
966857
Fixes: QTBUG-91867
966857
Pick-to: 5.12 5.15 6.0 6.1
966857
Change-Id: I89ca84fe893ebf517ab67890196eede14a4055d7
966857
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
966857
(cherry picked from commit d98694c4023881673259ba040c10df7e71ec3d37)
966857
---
966857
 src/quick/items/qquicktextinput.cpp           |  5 ++++
966857
 .../checkCursorDelegateWhenPaddingChanged.qml | 16 ++++++++++
966857
 .../qquicktextinput/tst_qquicktextinput.cpp   | 30 +++++++++++++++++++
966857
 3 files changed, 51 insertions(+)
966857
 create mode 100644 tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml
966857
966857
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
966857
index 079bf58abe..7d0d05700a 100644
966857
--- a/src/quick/items/qquicktextinput.cpp
966857
+++ b/src/quick/items/qquicktextinput.cpp
966857
@@ -2952,6 +2952,7 @@ void QQuickTextInputPrivate::setTopPadding(qreal value, bool reset)
966857
     }
966857
     if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding()))) {
966857
         updateLayout();
966857
+        q->updateCursorRectangle();
966857
         emit q->topPaddingChanged();
966857
     }
966857
 }
966857
@@ -2966,6 +2967,7 @@ void QQuickTextInputPrivate::setLeftPadding(qreal value, bool reset)
966857
     }
966857
     if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding()))) {
966857
         updateLayout();
966857
+        q->updateCursorRectangle();
966857
         emit q->leftPaddingChanged();
966857
     }
966857
 }
966857
@@ -2980,6 +2982,7 @@ void QQuickTextInputPrivate::setRightPadding(qreal value, bool reset)
966857
     }
966857
     if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding()))) {
966857
         updateLayout();
966857
+        q->updateCursorRectangle();
966857
         emit q->rightPaddingChanged();
966857
     }
966857
 }
966857
@@ -2994,6 +2997,7 @@ void QQuickTextInputPrivate::setBottomPadding(qreal value, bool reset)
966857
     }
966857
     if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding()))) {
966857
         updateLayout();
966857
+        q->updateCursorRectangle();
966857
         emit q->bottomPaddingChanged();
966857
     }
966857
 }
966857
@@ -4712,6 +4716,7 @@ void QQuickTextInput::setPadding(qreal padding)
966857
 
966857
     d->extra.value().padding = padding;
966857
     d->updateLayout();
966857
+    updateCursorRectangle();
966857
     emit paddingChanged();
966857
     if (!d->extra.isAllocated() || !d->extra->explicitTopPadding)
966857
         emit topPaddingChanged();
966857
diff --git a/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml b/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml
966857
new file mode 100644
966857
index 0000000000..e6f07b4687
966857
--- /dev/null
966857
+++ b/tests/auto/quick/qquicktextinput/data/checkCursorDelegateWhenPaddingChanged.qml
966857
@@ -0,0 +1,16 @@
966857
+import QtQuick 2.12
966857
+
966857
+Rectangle {
966857
+    width: 200
966857
+    height: 200
966857
+    TextInput {
966857
+        objectName: "textInput"
966857
+        leftPadding: 10
966857
+        focus: true
966857
+        cursorDelegate: Rectangle {
966857
+            objectName: "cursorDelegate"
966857
+            width: 5
966857
+            color: "red"
966857
+        }
966857
+    }
966857
+}
966857
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
966857
index 2e64c80b85..ac502bcb28 100644
966857
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
966857
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
966857
@@ -236,6 +236,7 @@ private slots:
966857
     void QTBUG_51115_readOnlyResetsSelection();
966857
     void QTBUG_77814_InsertRemoveNoSelection();
966857
 
966857
+    void checkCursorDelegateWhenPaddingChanged();
966857
 private:
966857
     void simulateKey(QWindow *, int key);
966857
 
966857
@@ -7054,6 +7055,35 @@ void tst_qquicktextinput::QTBUG_77814_InsertRemoveNoSelection()
966857
     QCOMPARE(textInput->selectedText(), QString());
966857
 }
966857
 
966857
+void tst_qquicktextinput::checkCursorDelegateWhenPaddingChanged()
966857
+{
966857
+    QQuickView view;
966857
+    view.setSource(testFileUrl("checkCursorDelegateWhenPaddingChanged.qml"));
966857
+    view.show();
966857
+    QVERIFY(QTest::qWaitForWindowExposed(&view));
966857
+
966857
+    QQuickTextInput *textInput = view.rootObject()->findChild<QQuickTextInput *>("textInput");
966857
+    QVERIFY(textInput);
966857
+
966857
+    QQuickItem *cursorDelegate = textInput->findChild<QQuickItem *>("cursorDelegate");
966857
+    QVERIFY(cursorDelegate);
966857
+
966857
+    QCOMPARE(cursorDelegate->x(), textInput->leftPadding());
966857
+    QCOMPARE(cursorDelegate->y(), textInput->topPadding());
966857
+
966857
+    textInput->setPadding(5);
966857
+    QCOMPARE(cursorDelegate->x(), textInput->leftPadding());
966857
+    QCOMPARE(cursorDelegate->y(), textInput->topPadding());
966857
+
966857
+    textInput->setTopPadding(10);
966857
+    QCOMPARE(cursorDelegate->x(), textInput->leftPadding());
966857
+    QCOMPARE(cursorDelegate->y(), textInput->topPadding());
966857
+
966857
+    textInput->setLeftPadding(10);
966857
+    QCOMPARE(cursorDelegate->x(), textInput->leftPadding());
966857
+    QCOMPARE(cursorDelegate->y(), textInput->topPadding());
966857
+}
966857
+
966857
 QTEST_MAIN(tst_qquicktextinput)
966857
 
966857
 #include "tst_qquicktextinput.moc"
966857
-- 
966857
2.35.1
966857