Reload stylesheet when CSS file changes (#6331)
* Reload stylesheet when CSS file changes --------- Co-authored-by: Tres Finocchiaro <tres.finocchiaro@gmail.com>
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#ifndef LMMS_GUI_LMMS_STYLE_H
|
||||
#define LMMS_GUI_LMMS_STYLE_H
|
||||
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QProxyStyle>
|
||||
|
||||
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
private:
|
||||
QImage colorizeXpm( const char * const * xpm, const QBrush& fill ) const;
|
||||
void hoverColors( bool sunken, bool hover, bool active, QColor& color, QColor& blend ) const;
|
||||
QFileSystemWatcher m_styleReloader;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -25,14 +25,17 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QStyleFactory>
|
||||
#include <QStyleOption>
|
||||
|
||||
#include "embed.h"
|
||||
#include "LmmsStyle.h"
|
||||
#include "TextFloat.h"
|
||||
|
||||
|
||||
namespace lmms::gui
|
||||
@@ -137,6 +140,29 @@ LmmsStyle::LmmsStyle() :
|
||||
file.open( QIODevice::ReadOnly );
|
||||
qApp->setStyleSheet( file.readAll() );
|
||||
|
||||
m_styleReloader.addPath(QFileInfo{file}.absoluteFilePath());
|
||||
connect(&m_styleReloader, &QFileSystemWatcher::fileChanged, this,
|
||||
[this](const QString& path)
|
||||
{
|
||||
if (auto file = QFile{path}; file.exists())
|
||||
{
|
||||
file.open(QIODevice::ReadOnly);
|
||||
qApp->setStyleSheet(file.readAll());
|
||||
TextFloat::displayMessage(
|
||||
tr("Theme updated"),
|
||||
tr("LMMS theme file %1 has been reloaded.").arg(file.fileName()),
|
||||
embed::getIconPixmap("colorize"),
|
||||
3000
|
||||
);
|
||||
// Handle delete + overwrite events
|
||||
if (!m_styleReloader.files().contains(path))
|
||||
{
|
||||
m_styleReloader.addPath(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if( s_palette != nullptr ) { qApp->setPalette( *s_palette ); }
|
||||
|
||||
setBaseStyle( QStyleFactory::create( "Fusion" ) );
|
||||
|
||||
Reference in New Issue
Block a user