From 6516836a1b0c3289de9a86429d7708fa244a540f Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Sat, 21 Oct 2023 18:03:01 +0100 Subject: [PATCH] Make PaletteChangeNotifier a QQuickItem, reducing quantity of paletteChanged signal emissions --- source/shared/utils/palettechangenotifier.cpp | 13 +++++++------ source/shared/utils/palettechangenotifier.h | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/source/shared/utils/palettechangenotifier.cpp b/source/shared/utils/palettechangenotifier.cpp index c3609eb73..cbee26082 100644 --- a/source/shared/utils/palettechangenotifier.cpp +++ b/source/shared/utils/palettechangenotifier.cpp @@ -23,17 +23,18 @@ #include #include -PaletteChangeNotifier::PaletteChangeNotifier(QObject* parent) : QObject(parent) -{ - QCoreApplication::instance()->installEventFilter(this); -} +PaletteChangeNotifier::PaletteChangeNotifier(QQuickItem* parent) : QQuickItem(parent) +{} -bool PaletteChangeNotifier::eventFilter(QObject* watched, QEvent* event) +bool PaletteChangeNotifier::event(QEvent* event) { if(event->type() == QEvent::ApplicationPaletteChange) + { emit paletteChanged(); + return true; + } - return QObject::eventFilter(watched, event); + return QObject::event(event); } static_block diff --git a/source/shared/utils/palettechangenotifier.h b/source/shared/utils/palettechangenotifier.h index 0d1bb96a4..bcc88abba 100644 --- a/source/shared/utils/palettechangenotifier.h +++ b/source/shared/utils/palettechangenotifier.h @@ -19,21 +19,21 @@ #ifndef PALETTECHANGENOTIFIER_H #define PALETTECHANGENOTIFIER_H -#include +#include #include -class PaletteChangeNotifier : public QObject +class PaletteChangeNotifier : public QQuickItem { Q_OBJECT public: - explicit PaletteChangeNotifier(QObject* parent = nullptr); + explicit PaletteChangeNotifier(QQuickItem* parent = nullptr); signals: void paletteChanged(); protected: - bool eventFilter(QObject* watched, QEvent* event) override; + bool event(QEvent* event) override; }; #endif // PALETTECHANGENOTIFIER_H