Added logic to look for a QResource (rcc) file along side a qss file when loading a new stylesheet.

This commit is contained in:
mjbudd77 2021-03-05 15:09:28 -05:00
parent f7480c8560
commit 0203344802
3 changed files with 39 additions and 45 deletions

View File

@ -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 );

View File

@ -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
{

View File

@ -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