Skip to content

Commit

Permalink
Make PaletteChangeNotifier a QQuickItem, reducing quantity of palette…
Browse files Browse the repository at this point in the history
…Changed signal emissions
  • Loading branch information
timangus committed Oct 21, 2023
1 parent e1083e8 commit 6516836
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions source/shared/utils/palettechangenotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
#include <QApplication>
#include <QQmlEngine>

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
Expand Down
8 changes: 4 additions & 4 deletions source/shared/utils/palettechangenotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
#ifndef PALETTECHANGENOTIFIER_H
#define PALETTECHANGENOTIFIER_H

#include <QObject>
#include <QQuickItem>
#include <QEvent>

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

0 comments on commit 6516836

Please sign in to comment.