From cf857e0d5dbe9a49e1ebc5699c277ee0824f39fd Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 20 Jun 2023 23:36:23 +0200 Subject: [PATCH] WIP: Avoid using deprecated `QGuiApplication::paletteChanged` Unfortunately this doesn't work; the `QEvent::ApplicationPaletteChange` event is never received. --- syncthingmodel/syncthingicons.cpp | 27 +++++++++++++++++---------- syncthingmodel/syncthingicons.h | 4 ++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/syncthingmodel/syncthingicons.cpp b/syncthingmodel/syncthingicons.cpp index 3f27cde..e341f80 100644 --- a/syncthingmodel/syncthingicons.cpp +++ b/syncthingmodel/syncthingicons.cpp @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -16,6 +17,8 @@ #include #include +#include + #ifndef LIB_SYNCTHING_MODEL_STATIC ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES #endif @@ -315,17 +318,8 @@ IconManager::IconManager(const QPalette *palette) , m_trayIcons(m_statusIcons) , m_commonForkAwesomeIcons( m_forkAwesomeRenderer, (palette ? *palette : QGuiApplication::palette()).color(QPalette::Normal, QPalette::Text), QSize(64, 64)) + , m_usesApplicationPalette(palette == nullptr) { -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - if (!palette) { - QObject::connect(qGuiApp, &QGuiApplication::paletteChanged, this, &IconManager::setPalette); - } -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif } void IconManager::setPalette(const QPalette &palette) @@ -334,6 +328,19 @@ void IconManager::setPalette(const QPalette &palette) m_commonForkAwesomeIcons = ForkAwesomeIcons(m_forkAwesomeRenderer, palette.color(QPalette::Normal, QPalette::Text), QSize(64, 64))); } +bool IconManager::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::ApplicationPaletteChange: + std::cout << "this is unfortunately never executed" << std::endl; + setPalette(QGuiApplication::palette()); + break; + default: + ; + } + return QObject::event(event); +} + IconManager &IconManager::instance(const QPalette *palette) { static auto iconManager = IconManager(palette); diff --git a/syncthingmodel/syncthingicons.h b/syncthingmodel/syncthingicons.h index 85b7c6d..a7022b6 100644 --- a/syncthingmodel/syncthingicons.h +++ b/syncthingmodel/syncthingicons.h @@ -166,6 +166,9 @@ Q_SIGNALS: void statusIconsChanged(const Data::StatusIcons &newStatusIcons, const Data::StatusIcons &newTrayIcons); void forkAwesomeIconsChanged(const Data::ForkAwesomeIcons &newForkAwesomeIcons); +protected: + bool event(QEvent *event) override; + private: explicit IconManager(const QPalette *palette = nullptr); @@ -173,6 +176,7 @@ private: StatusIcons m_trayIcons; QtForkAwesome::Renderer m_forkAwesomeRenderer; ForkAwesomeIcons m_commonForkAwesomeIcons; + bool m_usesApplicationPalette; }; inline void IconManager::applySettings(const StatusIconSettings *statusIconSettings, const StatusIconSettings *trayIconSettings)