Added custom events for changing icon theme in Linux because not all widgets are redrawn,
This commit is contained in:
parent
ca8f19215f
commit
5622eab98c
4 changed files with 78 additions and 0 deletions
|
@ -1,5 +1,9 @@
|
||||||
|
// for testing
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "gui/formmain.h"
|
#include "gui/formmain.h"
|
||||||
#include "gui/formsettings.h"
|
#include "gui/formsettings.h"
|
||||||
|
#include "gui/themefactory.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "qtsingleapplication/qtsingleapplication.h"
|
#include "qtsingleapplication/qtsingleapplication.h"
|
||||||
|
|
||||||
|
@ -29,6 +33,22 @@ void FormMain::cleanupResources() {
|
||||||
qDebug("Cleaning up resources before the application exits.");
|
qDebug("Cleaning up resources before the application exits.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
bool FormMain::event(QEvent *event) {
|
||||||
|
if (event->type() == ThemeFactoryEvent::type()) {
|
||||||
|
// Handle the change of icon theme.
|
||||||
|
setupIcons();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QMainWindow::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormMain::setupIcons() {
|
||||||
|
// NOTE: Call QIcon::fromTheme for all needed widgets here.
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void FormMain::createConnections() {
|
void FormMain::createConnections() {
|
||||||
// Menu "File" connections.
|
// Menu "File" connections.
|
||||||
connect(m_ui->m_actionQuit, &QAction::triggered, this, &FormMain::quit);
|
connect(m_ui->m_actionQuit, &QAction::triggered, this, &FormMain::quit);
|
||||||
|
|
|
@ -16,6 +16,13 @@ class FormMain : public QMainWindow {
|
||||||
protected:
|
protected:
|
||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
bool event(QEvent *event);
|
||||||
|
|
||||||
|
// Sets up proper icons for this widget.
|
||||||
|
void setupIcons();
|
||||||
|
#endif
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void processExecutionMessage(const QString &message);
|
void processExecutionMessage(const QString &message);
|
||||||
void quit();
|
void quit();
|
||||||
|
|
|
@ -4,10 +4,36 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#include "gui/themefactory.h"
|
#include "gui/themefactory.h"
|
||||||
|
#include "qtsingleapplication/qtsingleapplication.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
|
|
||||||
|
|
||||||
|
QEvent::Type ThemeFactoryEvent::m_typeOfEvent = QEvent::None;
|
||||||
|
|
||||||
|
//
|
||||||
|
// ThemeFactoryEvent class
|
||||||
|
//
|
||||||
|
|
||||||
|
ThemeFactoryEvent::ThemeFactoryEvent() : QEvent(ThemeFactoryEvent::type()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ThemeFactoryEvent::~ThemeFactoryEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
QEvent::Type ThemeFactoryEvent::type() {
|
||||||
|
if (m_typeOfEvent == QEvent::None) {
|
||||||
|
m_typeOfEvent = static_cast<QEvent::Type>(QEvent::registerEventType(2000));
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_typeOfEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// ThemeFactory class
|
||||||
|
//
|
||||||
|
|
||||||
ThemeFactory::ThemeFactory() {
|
ThemeFactory::ThemeFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +90,15 @@ void ThemeFactory::loadCurrentIconTheme() {
|
||||||
else {
|
else {
|
||||||
qDebug("Loading theme '%s'.", qPrintable(theme_name));
|
qDebug("Loading theme '%s'.", qPrintable(theme_name));
|
||||||
QIcon::setThemeName(theme_name);
|
QIcon::setThemeName(theme_name);
|
||||||
|
|
||||||
|
// In Linux, we need to deliver custom event for all widgets
|
||||||
|
// to make sure they get a chance to redraw their icons.
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
foreach (QWidget *widget, QtSingleApplication::allWidgets()) {
|
||||||
|
QtSingleApplication::postEvent((QObject*) widget,
|
||||||
|
new ThemeFactoryEvent());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define THEMEFACTORY_H
|
#define THEMEFACTORY_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QEvent>
|
||||||
|
|
||||||
|
|
||||||
class ThemeFactory {
|
class ThemeFactory {
|
||||||
|
@ -36,4 +37,19 @@ class ThemeFactory {
|
||||||
static void setCurrentIconTheme(const QString &theme_name);
|
static void setCurrentIconTheme(const QString &theme_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ThemeFactoryEvent : public QEvent {
|
||||||
|
public:
|
||||||
|
enum Type {
|
||||||
|
IconThemeChange = 2000
|
||||||
|
};
|
||||||
|
|
||||||
|
ThemeFactoryEvent();
|
||||||
|
virtual ~ThemeFactoryEvent();
|
||||||
|
|
||||||
|
static QEvent::Type type();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static QEvent::Type m_typeOfEvent;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // THEMEFACTORY_H
|
#endif // THEMEFACTORY_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue