[neon/qt/qtbase/Neon/release] debian: Restore the previous patch and add a new one to fix the regression.

Dmitry Shachnev null at kde.org
Thu May 5 10:59:24 BST 2022


Git commit b0864a5e6524246bc8eb5cac0e84031b8b6cc54f by Dmitry Shachnev, on behalf of Lu Yaning.
Committed on 10/08/2021 at 11:41.
Pushed by jriddell into branch 'Neon/release'.

Restore the previous patch and add a new one to fix the regression.

M  +4    -0    debian/changelog
A  +53   -0    debian/patches/fix-misplacement-of-placeholder-text-in-QLineEdit.diff
A  +144  -0    debian/patches/fix-placement-of-placeholder-text-in-QLineEdits-with-action-icons.diff
M  +2    -0    debian/patches/series

https://invent.kde.org/neon/qt/qtbase/commit/b0864a5e6524246bc8eb5cac0e84031b8b6cc54f

diff --git a/debian/changelog b/debian/changelog
index b0ebad0..55050ad 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,9 @@
 qtbase-opensource-src (5.15.2+dfsg-10) UNRELEASED; urgency=medium
 
+  [ Lu Yaning ]
+  * Restore fix-misplacement-of-placeholder-text-in-QLineEdit.diff.
+  * Backport upstream patch to fix the regression with placement of
+    placeholder text in QLineEdits with action icons.
 
  -- Debian Qt/KDE Maintainers <debian-qt-kde at lists.debian.org>  Tue, 10 Aug 2021 14:22:02 +0300
 
diff --git a/debian/patches/fix-misplacement-of-placeholder-text-in-QLineEdit.diff b/debian/patches/fix-misplacement-of-placeholder-text-in-QLineEdit.diff
new file mode 100644
index 0000000..3a14d54
--- /dev/null
+++ b/debian/patches/fix-misplacement-of-placeholder-text-in-QLineEdit.diff
@@ -0,0 +1,53 @@
+Description: fix misplacement of placeholder text in QLineEdit with RTL content
+ The placeholder text was rendered in the wrong position after clicking
+ on the clear button in a QLineEdit with right-to-left content. The
+ button was still taking up space while it was fading out, so the first
+ paintEvent rendered the placeholder with space reserved for the clear
+ button. Once the button gets hidden, no new update was issued, so
+ garbage was left behind.
+ .
+ Fix this by not giving a fading-out clear button any margin space. The
+ result of this is that the placeholder text is visible underneath the
+ fading-out clear button. This is preferable to the placeholder text
+ being first rendered next to the fading-out clear button, and then
+ popping to the edge when the clear button is hidden (which would have
+ been the result of issuing a complete update for the line edit at the
+ end of the fade-out animation).
+Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=dc794f7622bc00f7
+Last-Update: 2021-06-16
+
+--- a/src/widgets/widgets/qlineedit_p.cpp
++++ b/src/widgets/widgets/qlineedit_p.cpp
+@@ -664,10 +664,18 @@ static int effectiveTextMargin(int defau
+     if (widgets.empty())
+         return defaultMargin;
+ 
+-    return defaultMargin + (parameters.margin + parameters.widgetWidth) *
+-           int(std::count_if(widgets.begin(), widgets.end(),
++    const auto visibleSideWidgetCount = std::count_if(widgets.begin(), widgets.end(),
+                              [](const QLineEditPrivate::SideWidgetEntry &e) {
+-                                 return e.widget->isVisibleTo(e.widget->parentWidget()); }));
++#if QT_CONFIG(animation)
++        // a button that's fading out doesn't get any space
++        if (auto* iconButton = qobject_cast<QLineEditIconButton*>(e.widget))
++            return iconButton->needsSpace();
++
++#endif
++        return e.widget->isVisibleTo(e.widget->parentWidget());
++    });
++
++    return defaultMargin + (parameters.margin + parameters.widgetWidth) * visibleSideWidgetCount;
+ }
+ 
+ QMargins QLineEditPrivate::effectiveTextMargins() const
+--- a/src/widgets/widgets/qlineedit_p.h
++++ b/src/widgets/widgets/qlineedit_p.h
+@@ -95,6 +95,8 @@ public:
+ 
+     bool shouldHideWithText() const;
+     void setHideWithText(bool hide);
++    // m_wasHidden is true unless the button is fading out
++    bool needsSpace() const { return m_wasHidden; }
+ #endif
+ 
+ protected:
diff --git a/debian/patches/fix-placement-of-placeholder-text-in-QLineEdits-with-action-icons.diff b/debian/patches/fix-placement-of-placeholder-text-in-QLineEdits-with-action-icons.diff
new file mode 100644
index 0000000..5edbc66
--- /dev/null
+++ b/debian/patches/fix-placement-of-placeholder-text-in-QLineEdits-with-action-icons.diff
@@ -0,0 +1,144 @@
+Description: fix placement of placeholder text in QLineEdits with action icons
+ After dc794f7622bc00f7ca50fab65d6965695d6d2972, side widgets only got
+ space if they were not fading out, but the logic was not correctly
+ accounting for side widgets that never fade, such as buttons added via
+ QLineEdit::addAction.
+ .
+ Fix this to give visible widgets space, unless they are fading out. That
+ was the intent of the original change. Rename the variable to make its
+ purpose clearer, and reset it at the end of the fade-out animation.
+ .
+ Add a much-needed test that relies on private APIs to verify that the
+ effective margins are calculated correctly.
+Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=0e6b31019f01c72e
+Last-Update: 2021-08-10
+
+--- a/src/widgets/widgets/qlineedit_p.cpp
++++ b/src/widgets/widgets/qlineedit_p.cpp
+@@ -407,8 +407,9 @@ void QLineEditIconButton::setHideWithTex
+ 
+ void QLineEditIconButton::onAnimationFinished()
+ {
+-    if (shouldHideWithText() && isVisible() && !m_wasHidden) {
++    if (shouldHideWithText() && isVisible() && m_fadingOut) {
+         hide();
++        m_fadingOut = false;
+ 
+         // Invalidate previous geometry to take into account new size of side widgets
+         if (auto le = lineEditPrivate())
+@@ -418,7 +419,7 @@ void QLineEditIconButton::onAnimationFin
+ 
+ void QLineEditIconButton::animateShow(bool visible)
+ {
+-    m_wasHidden = visible;
++    m_fadingOut = !visible;
+ 
+     if (shouldHideWithText() && !isVisible()) {
+         show();
+--- a/src/widgets/widgets/qlineedit_p.h
++++ b/src/widgets/widgets/qlineedit_p.h
+@@ -95,8 +95,11 @@ public:
+ 
+     bool shouldHideWithText() const;
+     void setHideWithText(bool hide);
+-    // m_wasHidden is true unless the button is fading out
+-    bool needsSpace() const { return m_wasHidden; }
++    bool needsSpace() const {
++        if (m_fadingOut)
++            return false;
++        return isVisibleTo(parentWidget());
++    }
+ #endif
+ 
+ protected:
+@@ -120,7 +123,7 @@ private:
+ 
+ #if QT_CONFIG(animation)
+     bool m_hideWithText = false;
+-    bool m_wasHidden = false;
++    bool m_fadingOut = false;
+ #endif
+ 
+ };
+--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
++++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+@@ -292,6 +292,7 @@ private slots:
+     void clearButtonVisibleAfterSettingText_QTBUG_45518();
+     void sideWidgets();
+     void sideWidgetsActionEvents();
++    void sideWidgetsEffectiveMargins();
+ 
+     void shouldShowPlaceholderText_data();
+     void shouldShowPlaceholderText();
+@@ -4646,6 +4647,71 @@ void tst_QLineEdit::sideWidgetsActionEve
+     QCOMPARE(toolButton2->x(), toolButton1X);
+ }
+ 
++/*!
++    Verify that side widgets are positioned correctly and result in
++    correct effective text margins.
++*/
++void tst_QLineEdit::sideWidgetsEffectiveMargins()
++{
++#ifndef QT_BUILD_INTERNAL
++    QSKIP("This test requires a developer build.");
++#else
++    QLineEdit edit;
++    edit.setPlaceholderText("placeholder");
++    edit.setClearButtonEnabled(true);
++    edit.show();
++    QLineEditPrivate *priv = QLineEditPrivate::get(&edit);
++    const auto sideWidgetParameters = priv->sideWidgetParameters();
++    const int sideWidgetWidth = sideWidgetParameters.widgetWidth + sideWidgetParameters.margin;
++    QVERIFY(QTest::qWaitForWindowExposed(&edit));
++
++    QCOMPARE(priv->effectiveTextMargins().left(), 0);
++    QCOMPARE(priv->effectiveTextMargins().right(), 0);
++
++    edit.setText("Left to right"); // clear button fades in on the right
++    QCOMPARE(priv->effectiveTextMargins().left(), 0);
++    QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
++    edit.clear();
++    QCOMPARE(priv->effectiveTextMargins().left(), 0);
++    QCOMPARE(priv->effectiveTextMargins().right(), 0);
++
++    edit.setLayoutDirection(Qt::RightToLeft);
++    edit.setText("ئۇيغۇر تىلى"); // clear button fades in on the left
++    QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
++    QCOMPARE(priv->effectiveTextMargins().right(), 0);
++    edit.clear();
++    QCOMPARE(priv->effectiveTextMargins().left(), 0);
++    QCOMPARE(priv->effectiveTextMargins().right(), 0);
++
++    edit.setLayoutDirection(Qt::LeftToRight);
++
++    const QIcon leftIcon = edit.style()->standardIcon(QStyle::SP_FileIcon);
++    const QIcon rightIcon = edit.style()->standardIcon(QStyle::SP_DirIcon);
++    edit.addAction(leftIcon, QLineEdit::ActionPosition::LeadingPosition);
++    QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
++    QCOMPARE(priv->effectiveTextMargins().right(), 0);
++
++    edit.addAction(rightIcon, QLineEdit::ActionPosition::TrailingPosition);
++    QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
++    QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
++
++    edit.setText("Left to right"); // clear button on the right
++    QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
++    QCOMPARE(priv->effectiveTextMargins().right(), 2 * sideWidgetWidth);
++    edit.clear();
++    QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
++    QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
++
++    edit.setLayoutDirection(Qt::RightToLeft);
++    edit.setText("ئۇيغۇر تىلى"); // clear button fades in on the left
++    QCOMPARE(priv->effectiveTextMargins().left(), 2 * sideWidgetWidth);
++    QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
++    edit.clear();
++    QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
++    QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
++#endif
++}
++
+ Q_DECLARE_METATYPE(Qt::AlignmentFlag)
+ void tst_QLineEdit::shouldShowPlaceholderText_data()
+ {
diff --git a/debian/patches/series b/debian/patches/series
index 7cf8202..60097f5 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -5,6 +5,8 @@ gcc_11_limits.diff
 qiodevice_readline_memory.diff
 mime_globs.diff
 fix-invalid-pointer-return-with-QGridLayout.diff
+fix-misplacement-of-placeholder-text-in-QLineEdit.diff
+fix-placement-of-placeholder-text-in-QLineEdits-with-action-icons.diff
 
 # Debian specific.
 gnukfreebsd.diff



More information about the Neon-commits mailing list