summaryrefslogtreecommitdiff
path: root/vcl/qt5
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2019-05-12 14:30:06 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2019-05-13 12:22:46 +0200
commitfaecfd43646d9910e0409a39fecfd8816fe16cc9 (patch)
treedd2f705c305425cbbf85147794b925a71f12ed39 /vcl/qt5
parent022deeb79ef693550ea762c9cc899806ae4b374c (diff)
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@fbihome.de>
Diffstat (limited to 'vcl/qt5')
-rw-r--r--vcl/qt5/Qt5Frame.cxx8
-rw-r--r--vcl/qt5/Qt5Instance.cxx28
-rw-r--r--vcl/qt5/Qt5Widget.cxx22
3 files changed, 56 insertions, 2 deletions
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: */