Compare commits

...

1 Commits

Author SHA1 Message Date
Martchus cf857e0d5d WIP: Avoid using deprecated `QGuiApplication::paletteChanged`
Unfortunately this doesn't work; the `QEvent::ApplicationPaletteChange`
event is never received.
2023-06-20 23:36:23 +02:00
2 changed files with 21 additions and 10 deletions

View File

@ -9,6 +9,7 @@
#include <qtforkawesome/icon.h>
#include <QEvent>
#include <QFile>
#include <QGuiApplication>
#include <QPainter>
@ -16,6 +17,8 @@
#include <QStringBuilder>
#include <QSvgRenderer>
#include <iostream>
#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);

View File

@ -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)