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

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Mon May 13 10:23:28 UTC 2019


 vcl/inc/qt5/Qt5Frame.hxx    |    1 +
 vcl/inc/qt5/Qt5Instance.hxx |    8 ++++++++
 vcl/inc/qt5/Qt5Widget.hxx   |    2 ++
 vcl/qt5/Qt5Frame.cxx        |    8 ++++++--
 vcl/qt5/Qt5Instance.cxx     |   28 ++++++++++++++++++++++++++++
 vcl/qt5/Qt5Widget.cxx       |   22 ++++++++++++++++++++++
 6 files changed, 67 insertions(+), 2 deletions(-)

New commits:
commit faecfd43646d9910e0409a39fecfd8816fe16cc9
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sun May 12 14:30:06 2019 +0200
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Mon May 13 12:22:46 2019 +0200

    Qt5 handle theming-based change events
    
    Qt generates three change events when changing the KDE theme:
    FontChange, StyleChange and PaletteChange. LO has two:
    SettingChanged and FontChanged. And like Qt LO will inform all
    widgets / windows independently. To prevent several redraws,
    this patch just collects all Qt's change events and notifies LO
    once a bit later via a Timer.
    
    Change-Id: I9b45f543f13a84e39247a642a0e33c9ec008a46a
    Reviewed-on: https://gerrit.libreoffice.org/72196
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx
index 1309c17d10a7..6fe1333bd138 100644
--- a/vcl/inc/qt5/Qt5Frame.hxx
+++ b/vcl/inc/qt5/Qt5Frame.hxx
@@ -66,6 +66,7 @@ class VCLPLUG_QT5_PUBLIC Qt5Frame : public QObject, public SalFrame
     bool m_bNullRegion;
 
     bool m_bGraphicsInUse;
+    bool m_bGraphicsInvalid;
     SalFrameStyleFlags m_nStyle;
     Qt5Frame* m_pParent;
     PointerStyle m_ePointerStyle;
diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx
index a9be3581f64b..52b45b12d2b8 100644
--- a/vcl/inc/qt5/Qt5Instance.hxx
+++ b/vcl/inc/qt5/Qt5Instance.hxx
@@ -22,6 +22,7 @@
 #include <vclpluginapi.h>
 #include <unx/geninst.h>
 #include <salusereventlist.hxx>
+#include <vcl/timer.hxx>
 
 #include <osl/conditn.hxx>
 
@@ -58,6 +59,11 @@ class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject,
     std::unique_ptr<char* []> m_pFakeArgv;
     std::unique_ptr<int> m_pFakeArgc;
 
+    Timer m_aUpdateStyleTimer;
+    bool m_bUpdateFonts;
+
+    DECL_LINK(updateStyleHdl, Timer*, void);
+
 private Q_SLOTS:
     bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
     void ImplRunInMain();
@@ -138,6 +144,8 @@ public:
     CreateClipboard(const css::uno::Sequence<css::uno::Any>& i_rArguments) override;
     virtual css::uno::Reference<css::uno::XInterface> CreateDragSource() override;
     virtual css::uno::Reference<css::uno::XInterface> CreateDropTarget() override;
+
+    void UpdateStyle(bool bFontsChanged);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/Qt5Widget.hxx b/vcl/inc/qt5/Qt5Widget.hxx
index 8879bc10aef2..af48dbe5e4f5 100644
--- a/vcl/inc/qt5/Qt5Widget.hxx
+++ b/vcl/inc/qt5/Qt5Widget.hxx
@@ -27,6 +27,7 @@
 
 class Qt5Frame;
 class Qt5Object;
+class QEvent;
 class QFocusEvent;
 class QInputMethodEvent;
 class QKeyEvent;
@@ -66,6 +67,7 @@ class Qt5Widget : public QWidget
     virtual void showEvent(QShowEvent*) override;
     virtual void wheelEvent(QWheelEvent*) override;
     virtual void closeEvent(QCloseEvent*) override;
+    virtual void changeEvent(QEvent*) override;
 
     void inputMethodEvent(QInputMethodEvent*) override;
     QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index 5ed722aad391..acb43e515983 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -65,6 +65,7 @@ Qt5Frame::Qt5Frame(Qt5Frame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo)
     , m_pSvpGraphics(nullptr)
     , m_bNullRegion(true)
     , m_bGraphicsInUse(false)
+    , m_bGraphicsInvalid(false)
     , m_ePointerStyle(PointerStyle::Arrow)
     , m_pDragSource(nullptr)
     , m_pDropTarget(nullptr)
@@ -215,21 +216,23 @@ SalGraphics* Qt5Frame::AcquireGraphics()
 
     if (m_bUseCairo)
     {
-        if (!m_pOurSvpGraphics.get())
+        if (!m_pOurSvpGraphics.get() || m_bGraphicsInvalid)
         {
             m_pOurSvpGraphics.reset(new SvpSalGraphics());
             InitSvpSalGraphics(m_pOurSvpGraphics.get());
+            m_bGraphicsInvalid = false;
         }
         return m_pOurSvpGraphics.get();
     }
     else
     {
-        if (!m_pQt5Graphics.get())
+        if (!m_pQt5Graphics.get() || m_bGraphicsInvalid)
         {
             m_pQt5Graphics.reset(new Qt5Graphics(this));
             m_pQImage.reset(new QImage(m_pQWidget->size(), Qt5_DefaultFormat32));
             m_pQImage->fill(Qt::transparent);
             m_pQt5Graphics->ChangeQImage(m_pQImage.get());
+            m_bGraphicsInvalid = false;
         }
         return m_pQt5Graphics.get();
     }
@@ -1015,6 +1018,7 @@ void Qt5Frame::UpdateSettings(AllSettings& rSettings)
     style.SetShadowColor(toColor(pal.color(QPalette::Disabled, QPalette::WindowText)));
     style.SetDarkShadowColor(toColor(pal.color(QPalette::Inactive, QPalette::WindowText)));
 
+    m_bGraphicsInvalid = true;
     rSettings.SetStyleSettings(style);
 }
 
diff --git a/vcl/qt5/Qt5Instance.cxx b/vcl/qt5/Qt5Instance.cxx
index dd0edddc97cf..1949d426de69 100644
--- a/vcl/qt5/Qt5Instance.cxx
+++ b/vcl/qt5/Qt5Instance.cxx
@@ -205,6 +205,8 @@ Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo)
     , m_postUserEventId(-1)
     , m_bUseCairo(bUseCairo)
     , m_pQApplication(std::move(pQApp))
+    , m_aUpdateStyleTimer("vcl::qt5 m_aUpdateStyleTimer")
+    , m_bUpdateFonts(false)
 {
     ImplSVData* pSVData = ImplGetSVData();
     if (bUseCairo)
@@ -226,6 +228,9 @@ Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo)
     connect(this, &Qt5Instance::deleteObjectLaterSignal, this,
             [](QObject* pObject) { Qt5Instance::deleteObjectLater(pObject); },
             Qt::QueuedConnection);
+
+    m_aUpdateStyleTimer.SetTimeout(50);
+    m_aUpdateStyleTimer.SetInvokeHandler(LINK(this, Qt5Instance, updateStyleHdl));
 }
 
 Qt5Instance::~Qt5Instance()
@@ -440,6 +445,29 @@ Reference<XInterface> Qt5Instance::CreateDropTarget()
     return Reference<XInterface>(static_cast<cppu::OWeakObject*>(new Qt5DropTarget()));
 }
 
+IMPL_LINK_NOARG(Qt5Instance, updateStyleHdl, Timer*, void)
+{
+    SolarMutexGuard aGuard;
+    SalFrame* pFrame = anyFrame();
+    if (pFrame)
+    {
+        pFrame->CallCallback(SalEvent::SettingsChanged, nullptr);
+        if (m_bUpdateFonts)
+        {
+            pFrame->CallCallback(SalEvent::FontChanged, nullptr);
+            m_bUpdateFonts = false;
+        }
+    }
+}
+
+void Qt5Instance::UpdateStyle(bool bFontsChanged)
+{
+    if (bFontsChanged)
+        m_bUpdateFonts = true;
+    if (!m_aUpdateStyleTimer.IsActive())
+        m_aUpdateStyleTimer.Start();
+}
+
 void Qt5Instance::AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv,
                                        std::unique_ptr<int>& rFakeArgc,
                                        std::vector<FreeableCStr>& rFakeArgvFreeable)
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index a4c01cdede32..23afbea688fd 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -22,6 +22,7 @@
 
 #include <Qt5Frame.hxx>
 #include <Qt5Graphics.hxx>
+#include <Qt5Instance.hxx>
 #include <Qt5Tools.hxx>
 
 #include <QtCore/QMimeData>
@@ -576,4 +577,25 @@ void Qt5Widget::endExtTextInput()
     }
 }
 
+void Qt5Widget::changeEvent(QEvent* pEvent)
+{
+    switch (pEvent->type())
+    {
+        case QEvent::FontChange:
+            [[fallthrough]];
+        case QEvent::PaletteChange:
+            [[fallthrough]];
+        case QEvent::StyleChange:
+        {
+            auto* pSalInst(static_cast<Qt5Instance*>(GetSalData()->m_pInstance));
+            assert(pSalInst);
+            pSalInst->UpdateStyle(QEvent::FontChange == pEvent->type());
+            break;
+        }
+        default:
+            break;
+    }
+    QWidget::changeEvent(pEvent);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list