[Libreoffice-commits] core.git: vcl/inc vcl/qt5

Michael Weghorn (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 17 15:16:23 UTC 2020


 vcl/inc/qt5/Qt5Graphics_Controls.hxx |   12 ++--
 vcl/qt5/Qt5Graphics_Controls.cxx     |  101 +++++++++++++++++++++--------------
 2 files changed, 69 insertions(+), 44 deletions(-)

New commits:
commit 391f17a5fbcf9cd918efa10321219f87409d2412
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Thu Sep 17 09:42:38 2020 +0200
Commit:     Michael Weghorn <m.weghorn at posteo.de>
CommitDate: Thu Sep 17 17:15:38 2020 +0200

    tdf#136094 qt5: Handle bg color in drawNativeControl
    
    This adds handling for the background color when
    drawing controls in the qt5 VCL plugin, as was done
    in the following commit for the gtk3 VCL plugin:
    
        commit 2c9052802ea411dffbf5906c4914611fcbfbc6a5
        Author: Michael Weghorn <m.weghorn at posteo.de>
        Date:   Mon Aug 24 17:18:03 2020 +0200
    
            tdf#136094 Handle background color in drawNativeControl
    
    For some reason, the proper background color is not passed
    to 'Qt5Graphics_Controls::drawNativeControl' for the
    multiline edit in the sample document ('rBackgroundColor
    is 'COL_AUTO' instead), while it works as expected for the
    gtk3 case. Setting a color inside
    'Qt5Graphics_Controls::drawNativeControl' for testing purposes
    made that one show up, so the problem is elsewhere.
    I'll create a separate bug report to keep track of this and
    reference it in tdf#136094.
    
    Change-Id: I4df0d803c017422e0a2f5c05c6b4d2d8a8fa68c6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102911
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.weghorn at posteo.de>

diff --git a/vcl/inc/qt5/Qt5Graphics_Controls.hxx b/vcl/inc/qt5/Qt5Graphics_Controls.hxx
index 325e5c351046..b9034fd8ea03 100644
--- a/vcl/inc/qt5/Qt5Graphics_Controls.hxx
+++ b/vcl/inc/qt5/Qt5Graphics_Controls.hxx
@@ -67,13 +67,15 @@ private:
     static QRect subElementRect(QStyle::SubElement element, const QStyleOption* option);
 
     void draw(QStyle::ControlElement element, QStyleOption* option, QImage* image,
-              QStyle::State const state = QStyle::State_None, QRect rect = QRect());
+              const Color& rBackgroundColor, QStyle::State const state = QStyle::State_None,
+              QRect rect = QRect());
     void draw(QStyle::PrimitiveElement element, QStyleOption* option, QImage* image,
-              QStyle::State const state = QStyle::State_None, QRect rect = QRect());
+              const Color& rBackgroundColor, QStyle::State const state = QStyle::State_None,
+              QRect rect = QRect());
     void draw(QStyle::ComplexControl element, QStyleOptionComplex* option, QImage* image,
-              QStyle::State const state = QStyle::State_None);
-    void drawFrame(QStyle::PrimitiveElement element, QImage* image, QStyle::State const& state,
-                   bool bClip = true,
+              const Color& rBackgroundColor, QStyle::State const state = QStyle::State_None);
+    void drawFrame(QStyle::PrimitiveElement element, QImage* image, const Color& rBackGroundColor,
+                   QStyle::State const& state, bool bClip = true,
                    QStyle::PixelMetric eLineMetric = QStyle::PM_DefaultFrameWidth);
 
     static void fillQStyleOptionTab(const ImplControlValue& value, QStyleOptionTab& sot);
diff --git a/vcl/qt5/Qt5Graphics_Controls.cxx b/vcl/qt5/Qt5Graphics_Controls.cxx
index dce9c1687e42..361050929d77 100644
--- a/vcl/qt5/Qt5Graphics_Controls.cxx
+++ b/vcl/qt5/Qt5Graphics_Controls.cxx
@@ -63,6 +63,17 @@ static QStyle::State vclStateValue2StateFlag(ControlState nControlState,
     return nState;
 }
 
+static void lcl_ApplyBackgroundColorToStyleOption(QStyleOption* pOption,
+                                                  const Color& rBackgroundColor)
+{
+    if (rBackgroundColor != COL_AUTO)
+    {
+        QColor aColor = toQColor(rBackgroundColor);
+        for (QPalette::ColorRole role : { QPalette::Window, QPalette::Button, QPalette::Base })
+            pOption->palette.setColor(role, aColor);
+    }
+}
+
 Qt5Graphics_Controls::Qt5Graphics_Controls(const Qt5GraphicsBase& rGraphics)
     : m_rGraphics(rGraphics)
 {
@@ -144,44 +155,53 @@ inline QRect Qt5Graphics_Controls::subElementRect(QStyle::SubElement element,
 }
 
 void Qt5Graphics_Controls::draw(QStyle::ControlElement element, QStyleOption* option, QImage* image,
-                                QStyle::State const state, QRect rect)
+                                const Color& rBackgroundColor, QStyle::State const state,
+                                QRect rect)
 {
     const QRect& targetRect = !rect.isNull() ? rect : image->rect();
 
     option->state |= state;
     option->rect = downscale(targetRect);
 
+    lcl_ApplyBackgroundColorToStyleOption(option, rBackgroundColor);
+
     QPainter painter(image);
     QApplication::style()->drawControl(element, option, &painter);
 }
 
 void Qt5Graphics_Controls::draw(QStyle::PrimitiveElement element, QStyleOption* option,
-                                QImage* image, QStyle::State const state, QRect rect)
+                                QImage* image, const Color& rBackgroundColor,
+                                QStyle::State const state, QRect rect)
 {
     const QRect& targetRect = !rect.isNull() ? rect : image->rect();
 
     option->state |= state;
     option->rect = downscale(targetRect);
 
+    lcl_ApplyBackgroundColorToStyleOption(option, rBackgroundColor);
+
     QPainter painter(image);
     QApplication::style()->drawPrimitive(element, option, &painter);
 }
 
 void Qt5Graphics_Controls::draw(QStyle::ComplexControl element, QStyleOptionComplex* option,
-                                QImage* image, QStyle::State const state)
+                                QImage* image, const Color& rBackgroundColor,
+                                QStyle::State const state)
 {
     const QRect& targetRect = image->rect();
 
     option->state |= state;
     option->rect = downscale(targetRect);
 
+    lcl_ApplyBackgroundColorToStyleOption(option, rBackgroundColor);
+
     QPainter painter(image);
     QApplication::style()->drawComplexControl(element, option, &painter);
 }
 
 void Qt5Graphics_Controls::drawFrame(QStyle::PrimitiveElement element, QImage* image,
-                                     QStyle::State const& state, bool bClip,
-                                     QStyle::PixelMetric eLineMetric)
+                                     const Color& rBackgroundColor, QStyle::State const& state,
+                                     bool bClip, QStyle::PixelMetric eLineMetric)
 {
     const int fw = pixelMetric(eLineMetric);
     QStyleOptionFrame option;
@@ -192,6 +212,8 @@ void Qt5Graphics_Controls::drawFrame(QStyle::PrimitiveElement element, QImage* i
     QRect aRect = downscale(image->rect());
     option.rect = aRect;
 
+    lcl_ApplyBackgroundColorToStyleOption(&option, rBackgroundColor);
+
     QPainter painter(image);
     if (bClip)
         painter.setClipRegion(QRegion(aRect).subtracted(aRect.adjusted(fw, fw, -fw, -fw)));
@@ -225,7 +247,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
                                              const tools::Rectangle& rControlRegion,
                                              ControlState nControlState,
                                              const ImplControlValue& value, const OUString&,
-                                             const Color& /*rBackgroundColor*/)
+                                             const Color& rBackgroundColor)
 {
     bool nativeSupport = isNativeControlSupported(type, part);
     if (!nativeSupport)
@@ -286,7 +308,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
     {
         assert(part == ControlPart::Entire);
         QStyleOptionButton option;
-        draw(QStyle::CE_PushButton, &option, m_image.get(),
+        draw(QStyle::CE_PushButton, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value));
     }
     else if (type == ControlType::Menubar)
@@ -303,12 +325,12 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
                 & ControlState::SELECTED) // Passing State_Sunken is currently not documented.
                 option.state |= QStyle::State_Sunken; // But some kinds of QStyle interpret it.
 
-            draw(QStyle::CE_MenuBarItem, &option, m_image.get());
+            draw(QStyle::CE_MenuBarItem, &option, m_image.get(), rBackgroundColor);
         }
         else if (part == ControlPart::Entire)
         {
             QStyleOptionMenuItem option;
-            draw(QStyle::CE_MenuBarEmptyArea, &option, m_image.get(),
+            draw(QStyle::CE_MenuBarEmptyArea, &option, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState, value));
         }
         else
@@ -323,7 +345,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         if (part == ControlPart::MenuItem)
         {
             QStyleOptionMenuItem option;
-            draw(QStyle::CE_MenuItem, &option, m_image.get(),
+            draw(QStyle::CE_MenuItem, &option, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState, value));
             // HACK: LO core first paints the entire popup and only then it paints menu items,
             // but QMenu::paintEvent() paints popup frame after all items. That means highlighted
@@ -333,7 +355,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
             QRect framerect(m_lastPopupRect.topLeft() - widgetRect.topLeft(),
                             widgetRect.size().expandedTo(m_lastPopupRect.size()));
             QStyleOptionFrame frame;
-            draw(QStyle::PE_FrameMenu, &frame, m_image.get(),
+            draw(QStyle::PE_FrameMenu, &frame, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState, value), framerect);
         }
         else if (part == ControlPart::Separator)
@@ -377,18 +399,18 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
             // checkboxes are always displayed next to images in menus, so are never centered
             const int focus_size = pixelMetric(QStyle::PM_FocusFrameHMargin);
             rect.moveTo(-focus_size, rect.y());
-            draw(QStyle::CE_MenuItem, &option, m_image.get(),
+            draw(QStyle::CE_MenuItem, &option, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState & ~ControlState::PRESSED, value), rect);
         }
         else if (part == ControlPart::Entire)
         {
             QStyleOptionMenuItem option;
             option.state = vclStateValue2StateFlag(nControlState, value);
-            draw(QStyle::PE_PanelMenu, &option, m_image.get());
+            draw(QStyle::PE_PanelMenu, &option, m_image.get(), rBackgroundColor);
             // Try hard to get any frame!
             QStyleOptionFrame frame;
-            draw(QStyle::PE_FrameMenu, &frame, m_image.get());
-            draw(QStyle::PE_FrameWindow, &frame, m_image.get());
+            draw(QStyle::PE_FrameMenu, &frame, m_image.get(), rBackgroundColor);
+            draw(QStyle::PE_FrameWindow, &frame, m_image.get(), rBackgroundColor);
             m_lastPopupRect = widgetRect;
         }
         else
@@ -403,12 +425,12 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         option.state = vclStateValue2StateFlag(nControlState, value);
         option.state |= QStyle::State_Raised | QStyle::State_Enabled | QStyle::State_AutoRaise;
 
-        draw(QStyle::CC_ToolButton, &option, m_image.get());
+        draw(QStyle::CC_ToolButton, &option, m_image.get(), rBackgroundColor);
     }
     else if ((type == ControlType::Toolbar) && (part == ControlPart::Entire))
     {
         QStyleOptionToolBar option;
-        draw(QStyle::CE_ToolBar, &option, m_image.get(),
+        draw(QStyle::CE_ToolBar, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value));
     }
     else if ((type == ControlType::Toolbar)
@@ -425,19 +447,19 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         }
         else
             aRect.setHeight(handleExtend);
-        draw(QStyle::PE_IndicatorToolBarHandle, &option, m_image.get(),
+        draw(QStyle::PE_IndicatorToolBarHandle, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value), aRect);
     }
     else if (type == ControlType::Editbox || type == ControlType::MultilineEditbox)
     {
-        drawFrame(QStyle::PE_FrameLineEdit, m_image.get(),
+        drawFrame(QStyle::PE_FrameLineEdit, m_image.get(), rBackgroundColor,
                   vclStateValue2StateFlag(nControlState, value), false);
     }
     else if (type == ControlType::Combobox)
     {
         QStyleOptionComboBox option;
         option.editable = true;
-        draw(QStyle::CC_ComboBox, &option, m_image.get(),
+        draw(QStyle::CC_ComboBox, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value));
     }
     else if (type == ControlType::Listbox)
@@ -447,21 +469,21 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         switch (part)
         {
             case ControlPart::ListboxWindow:
-                drawFrame(QStyle::PE_Frame, m_image.get(),
+                drawFrame(QStyle::PE_Frame, m_image.get(), rBackgroundColor,
                           vclStateValue2StateFlag(nControlState, value), true,
                           QStyle::PM_ComboBoxFrameWidth);
                 break;
             case ControlPart::SubEdit:
-                draw(QStyle::CE_ComboBoxLabel, &option, m_image.get(),
+                draw(QStyle::CE_ComboBoxLabel, &option, m_image.get(), rBackgroundColor,
                      vclStateValue2StateFlag(nControlState, value));
                 break;
             case ControlPart::Entire:
-                draw(QStyle::CC_ComboBox, &option, m_image.get(),
+                draw(QStyle::CC_ComboBox, &option, m_image.get(), rBackgroundColor,
                      vclStateValue2StateFlag(nControlState, value));
                 break;
             case ControlPart::ButtonDown:
                 option.subControls = QStyle::SC_ComboBoxArrow;
-                draw(QStyle::CC_ComboBox, &option, m_image.get(),
+                draw(QStyle::CC_ComboBox, &option, m_image.get(), rBackgroundColor,
                      vclStateValue2StateFlag(nControlState, value));
                 break;
             default:
@@ -478,12 +500,12 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         if (value.getTristateVal() == ButtonValue::On)
             option.state |= QStyle::State_Open;
 
-        draw(QStyle::PE_IndicatorBranch, &option, m_image.get());
+        draw(QStyle::PE_IndicatorBranch, &option, m_image.get(), rBackgroundColor);
     }
     else if (type == ControlType::ListHeader)
     {
         QStyleOptionHeader option;
-        draw(QStyle::CE_HeaderSection, &option, m_image.get(),
+        draw(QStyle::CE_HeaderSection, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value));
     }
     else if (type == ControlType::Checkbox)
@@ -493,13 +515,13 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
             QStyleOptionButton option;
             // clear FOCUSED bit, focus is drawn separately
             nControlState &= ~ControlState::FOCUSED;
-            draw(QStyle::CE_CheckBox, &option, m_image.get(),
+            draw(QStyle::CE_CheckBox, &option, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState, value));
         }
         else if (part == ControlPart::Focus)
         {
             QStyleOptionFocusRect option;
-            draw(QStyle::PE_FrameFocusRect, &option, m_image.get(),
+            draw(QStyle::PE_FrameFocusRect, &option, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState, value));
         }
     }
@@ -542,7 +564,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
             if (sbVal->mnThumbState & ControlState::ROLLOVER)
                 option.activeSubControls = QStyle::SC_ScrollBarSlider;
 
-            draw(QStyle::CC_ScrollBar, &option, m_image.get(),
+            draw(QStyle::CC_ScrollBar, &option, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState, value));
         }
         else
@@ -573,7 +595,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
                 option.state = QStyle::State_MouseOver;
         }
 
-        draw(QStyle::CC_SpinBox, &option, m_image.get(),
+        draw(QStyle::CC_SpinBox, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value));
     }
     else if (type == ControlType::Radiobutton)
@@ -583,25 +605,26 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
             QStyleOptionButton option;
             // clear FOCUSED bit, focus is drawn separately
             nControlState &= ~ControlState::FOCUSED;
-            draw(QStyle::CE_RadioButton, &option, m_image.get(),
+            draw(QStyle::CE_RadioButton, &option, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState, value));
         }
         else if (part == ControlPart::Focus)
         {
             QStyleOptionFocusRect option;
-            draw(QStyle::PE_FrameFocusRect, &option, m_image.get(),
+            draw(QStyle::PE_FrameFocusRect, &option, m_image.get(), rBackgroundColor,
                  vclStateValue2StateFlag(nControlState, value));
         }
     }
     else if (type == ControlType::Tooltip)
     {
         QStyleOption option;
-        draw(QStyle::PE_PanelTipLabel, &option, m_image.get(),
+        draw(QStyle::PE_PanelTipLabel, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value));
     }
     else if (type == ControlType::Frame)
     {
-        drawFrame(QStyle::PE_Frame, m_image.get(), vclStateValue2StateFlag(nControlState, value));
+        drawFrame(QStyle::PE_Frame, m_image.get(), rBackgroundColor,
+                  vclStateValue2StateFlag(nControlState, value));
     }
     else if (type == ControlType::WindowBackground)
     {
@@ -614,7 +637,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         option.state = vclStateValue2StateFlag(nControlState, value);
         option.state |= QStyle::State_Item;
 
-        draw(QStyle::CE_MenuItem, &option, m_image.get());
+        draw(QStyle::CE_MenuItem, &option, m_image.get(), rBackgroundColor);
     }
     else if (type == ControlType::Slider
              && (part == ControlPart::TrackHorzArea || part == ControlPart::TrackVertArea))
@@ -632,7 +655,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         if (horizontal)
             option.state |= QStyle::State_Horizontal;
 
-        draw(QStyle::CC_Slider, &option, m_image.get());
+        draw(QStyle::CC_Slider, &option, m_image.get(), rBackgroundColor);
     }
     else if (type == ControlType::Progress && part == ControlPart::Entire)
     {
@@ -643,14 +666,14 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         option.maximum = widgetRect.width();
         option.progress = value.getNumericVal();
 
-        draw(QStyle::CE_ProgressBar, &option, m_image.get(),
+        draw(QStyle::CE_ProgressBar, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value));
     }
     else if (type == ControlType::TabItem && part == ControlPart::Entire)
     {
         QStyleOptionTab sot;
         fillQStyleOptionTab(value, sot);
-        draw(QStyle::CE_TabBarTabShape, &sot, m_image.get(),
+        draw(QStyle::CE_TabBarTabShape, &sot, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value));
     }
     else if (type == ControlType::TabPane && part == ControlPart::Entire)
@@ -670,7 +693,7 @@ bool Qt5Graphics_Controls::drawNativeControl(ControlType type, ControlPart part,
         option.tabBarSize = toQSize(rValue.m_aTabHeaderRect.GetSize());
         option.rect = m_image->rect();
         QRect aRect = subElementRect(QStyle::SE_TabWidgetTabPane, &option);
-        draw(QStyle::PE_FrameTabWidget, &option, m_image.get(),
+        draw(QStyle::PE_FrameTabWidget, &option, m_image.get(), rBackgroundColor,
              vclStateValue2StateFlag(nControlState, value), aRect);
     }
     else


More information about the Libreoffice-commits mailing list