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

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