vcl/inc/qt5/QtGraphics_Controls.hxx |    3 ++-
 vcl/qt5/QtGraphics_Controls.cxx     |   30 ++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)

New commits:
commit 43c1de9f68a589304f060d2e662dc37c842a2a67
Author:     Rafael Lima <rafael.palma.l...@gmail.com>
AuthorDate: Thu Feb 2 15:27:37 2023 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Fri Feb 10 09:03:39 2023 +0000

    tdf#150451 Fix borders in Editbox controls (kf5)
    
    The bounding rectangle calculated for an Editbox in
    QtGraphics_Controls::getNativeControlRegion was not
    always enough to accommodate content and the borders.
    
    The KDE Breeze does not draw any borders if the total
    height of the bounding rectangle is smaller than the
    minimum size needed for content + frame at top and bottom,
    s. Style::drawFrameLineEditPrimitive in the Breeze
    style [1].
    
    Therefore, ensure a minimum height of that size.
    The Breeze style also considers the type of the
    passed widget when retrieving the frame width using
    QStyle::pixelMetric [2], so pass a dummy `QLineEdit`
    in order to get the actual frame width of 6
    that the Breeze style uses for line edits, rather
    than the default value of 2 that is returned when not
    passing any widget.
    
    Just do that for the minimum size calculation for now
    and not everywhere, because the handling for edit boxes
    here in the qt VCL plugins and in the calling code
    currently does all kinds of "interesting" things like doing
    extra size adjustments or passing the content rect where the
    bounding rect would be expected,...
    
    Ideally this should be cleaned up in the callers and all
    platform integrations in a follow-up commit
    to adhere to what the doc in vcl/inc/WidgetDrawInterface.hxx
    says, but this here keeps it working with existing code for now.
    
    (s.a. discussion in the Gerrit change for more details)
    
    Tested using various scaling factors: 1, 1.25, 1.5, 1.75 and 2.0.
    
    [1] 
https://invent.kde.org/plasma/breeze/-/blob/144ea45018d28758db07afd987d97318d56c4981/kstyle/breezestyle.cpp#L3527
    [2] 
https://invent.kde.org/plasma/breeze/-/blob/144ea45018d28758db07afd987d97318d56c4981/kstyle/breezestyle.cpp#L555
    
    Co-authored-by: Michael Weghorn <m.wegh...@posteo.de>
    
    Change-Id: If8cb4794c7f3ce1be4d1ee421c9c27ad5adf5da2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146516
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    (cherry picked from commit 5c96e813bed3293605f8d746f188cc051d1e5949)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146706
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/inc/qt5/QtGraphics_Controls.hxx 
b/vcl/inc/qt5/QtGraphics_Controls.hxx
index 17039f9d6038..dd1865e34008 100644
--- a/vcl/inc/qt5/QtGraphics_Controls.hxx
+++ b/vcl/inc/qt5/QtGraphics_Controls.hxx
@@ -59,7 +59,8 @@ public:
                                 tools::Rectangle& rNativeContentRegion) 
override;
 
 private:
-    static int pixelMetric(QStyle::PixelMetric metric, const QStyleOption* 
option = nullptr);
+    static int pixelMetric(QStyle::PixelMetric metric, const QStyleOption* 
option = nullptr,
+                           const QWidget* pWidget = nullptr);
     static QSize sizeFromContents(QStyle::ContentsType type, const 
QStyleOption* option,
                                   const QSize& contentsSize);
     static QRect subControlRect(QStyle::ComplexControl control, const 
QStyleOptionComplex* option,
diff --git a/vcl/qt5/QtGraphics_Controls.cxx b/vcl/qt5/QtGraphics_Controls.cxx
index e08b84719e61..f2e48f655149 100644
--- a/vcl/qt5/QtGraphics_Controls.cxx
+++ b/vcl/qt5/QtGraphics_Controls.cxx
@@ -23,6 +23,7 @@
 #include <QtWidgets/QApplication>
 #include <QtWidgets/QFrame>
 #include <QtWidgets/QLabel>
+#include <QtWidgets/QLineEdit>
 
 #include <QtTools.hxx>
 #include <QtGraphicsBase.hxx>
@@ -129,9 +130,10 @@ bool 
QtGraphics_Controls::isNativeControlSupported(ControlType type, ControlPart
     return false;
 }
 
-inline int QtGraphics_Controls::pixelMetric(QStyle::PixelMetric metric, const 
QStyleOption* option)
+inline int QtGraphics_Controls::pixelMetric(QStyle::PixelMetric metric, const 
QStyleOption* option,
+                                            const QWidget* pWidget)
 {
-    return QApplication::style()->pixelMetric(metric, option);
+    return QApplication::style()->pixelMetric(metric, option, pWidget);
 }
 
 inline QSize QtGraphics_Controls::sizeFromContents(QStyle::ContentsType type,
@@ -759,6 +761,30 @@ bool 
QtGraphics_Controls::getNativeControlRegion(ControlType type, ControlPart p
             int nRight = qMax(nLine, upscale(fo.rect.right() - 
aSubRect.right(), Round::Ceil));
             int nBottom = qMax(nLine, upscale(fo.rect.bottom() - 
aSubRect.bottom(), Round::Ceil));
             boundingRect.adjust(nLeft, nTop, nRight, nBottom);
+
+            // tdf#150451: ensure a minimium size that fits text content + 
frame at top and bottom.
+            // Themes may use the widget type for determining the actual frame 
width to use,
+            // so pass a dummy QLineEdit
+            //
+            // NOTE: This is currently only done here for the minimum size 
calculation and
+            // not above because the handling for edit boxes here and in the 
calling code
+            // currently does all kinds of "interesting" things like doing 
extra size adjustments
+            // or passing the content rect where the bounding rect would be 
expected,...
+            // Ideally this should be cleaned up in the callers and all 
platform integrations
+            // to adhere to what the doc in vcl/inc/WidgetDrawInterface.hxx 
says, but this
+            // here keeps it working with existing code for now.
+            // (s.a. discussion in 
https://gerrit.libreoffice.org/c/core/+/146516 for more details)
+            QLineEdit aDummyEdit;
+            const int nFrameWidth = pixelMetric(QStyle::PM_DefaultFrameWidth, 
nullptr, &aDummyEdit);
+            QFontMetrics aFontMetrics(QApplication::font());
+            const int minHeight = upscale(aFontMetrics.height() + 2 * 
nFrameWidth, Round::Floor);
+            if (boundingRect.height() < minHeight)
+            {
+                const int nDiff = minHeight - boundingRect.height();
+                boundingRect.setHeight(boundingRect.height() + nDiff);
+                contentRect.setHeight(contentRect.height() + nDiff);
+            }
+
             retVal = true;
             break;
         }

Reply via email to