From 02033448023dcb2371b6bfe309fb2a41e6c88f29 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Fri, 5 Mar 2021 15:09:28 -0500 Subject: [PATCH] Added logic to look for a QResource (rcc) file along side a qss file when loading a new stylesheet. --- src/drivers/Qt/ConsoleWindow.cpp | 45 ++------------------------------ src/drivers/Qt/GuiConf.cpp | 35 +++++++++++++++++++++++-- src/drivers/Qt/GuiConf.h | 4 +++ 3 files changed, 39 insertions(+), 45 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 91f422a0..984fdb43 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -90,53 +90,12 @@ consoleWin_t::consoleWin_t(QWidget *parent) int opt, xWinSize = 256, yWinSize = 240; int use_SDL_video = false; int setFullScreen = false; - //int useCustomQss = false; - //const char *styleSheetEnv = NULL; - //std::string guiStyle; - //g_config->getOption("SDL.GuiStyle", &guiStyle ); + //QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath); + //printf("LibPath: '%s'\n", libpath.toStdString().c_str() ); QApplication::setStyle( new fceuStyle() ); - //if ( guiStyle.size() > 0 ) - //{ - // QStyle *sty = QStyleFactory::create( tr(guiStyle.c_str()) ); - - // if ( sty != nullptr ) - // { - // QApplication::setStyle(sty); - // } - //} - - //styleSheetEnv = ::getenv("FCEUX_QT_STYLESHEET"); - - //if ( styleSheetEnv ) - //{ - // g_config->setOption("SDL.UseCustomQss", 1); - // g_config->setOption("SDL.QtStyleSheet", styleSheetEnv); - //} - - //g_config->getOption("SDL.UseCustomQss", &useCustomQss); - - //if ( useCustomQss ) - //{ - // g_config->getOption("SDL.QtStyleSheet", &guiStyle ); - - // if ( guiStyle.size() > 0 ) - // { - // QFile File(guiStyle.c_str()); - // - // if ( File.open(QFile::ReadOnly) ) - // { - // QString StyleSheet = QLatin1String(File.readAll()); - // - // setStyleSheet(StyleSheet); - // - // //printf("Using Qt Stylesheet file '%s'\n", filepath ); - // } - // } - //} - createMainMenu(); g_config->getOption( "SDL.VideoDriver", &use_SDL_video ); diff --git a/src/drivers/Qt/GuiConf.cpp b/src/drivers/Qt/GuiConf.cpp index 7a2aa48c..e4715e1f 100644 --- a/src/drivers/Qt/GuiConf.cpp +++ b/src/drivers/Qt/GuiConf.cpp @@ -370,15 +370,29 @@ void GuiConfDialog_t::openQss(void) // Custom Style Wrapper Class //---------------------------------------------------- //---------------------------------------------------- -fceuStyle::fceuStyle() : fceuStyle(styleBase()){} +fceuStyle::fceuStyle(void) : fceuStyle(styleBase()){} fceuStyle::fceuStyle(QStyle *style) : QProxyStyle(style) { - printf("New Style!!!\n"); + //printf("New Style!!!\n"); setObjectName( style->objectName() ); } +fceuStyle::~fceuStyle(void) +{ + //printf("Style Deleted: %s\n", objectName().toStdString().c_str() ); + + if ( rccFilePath.size() > 0 ) + { + if ( QResource::unregisterResource( QString::fromStdString(rccFilePath) ) ) + { + //printf("Removed Resource: '%s'\n", rccFilePath.c_str() ); + rccFilePath.clear(); + } + } +} + QStyle *fceuStyle::styleBase(QStyle *style) const { std::string s; @@ -474,6 +488,23 @@ void fceuStyle::polish(QApplication *app) app->setStyleSheet(qsStylesheet); file.close(); } + + if ( rccFilePath.size() == 0 ) + { + char dir[1024], rccBase[256], tmpFile[2048]; + + parseFilepath( s.c_str(), dir, rccBase, NULL ); + + sprintf( tmpFile, "%s%s.rcc", dir, rccBase ); + + //printf("RCC: '%s%s'\n", dir, rccBase ); + + if ( QResource::registerResource( tmpFile ) ) + { + //printf("Loaded RCC File: '%s'\n", tmpFile ); + rccFilePath.assign( tmpFile ); + } + } } else { diff --git a/src/drivers/Qt/GuiConf.h b/src/drivers/Qt/GuiConf.h index 930e8b36..f16bffdf 100644 --- a/src/drivers/Qt/GuiConf.h +++ b/src/drivers/Qt/GuiConf.h @@ -28,6 +28,8 @@ public: fceuStyle(void); fceuStyle(QStyle *style); + ~fceuStyle(void); + QStyle *baseStyle() const; void polish(QPalette &palette) override; @@ -35,6 +37,8 @@ public: private: QStyle *styleBase(QStyle *style = Q_NULLPTR) const; + + std::string rccFilePath; }; class GuiConfDialog_t : public QDialog