Qt: Fix style sheet edge case

This commit is contained in:
Megamouse 2018-06-26 02:33:57 +02:00 committed by Ivan
parent 23b10fc16d
commit 19514128e3

View file

@ -319,18 +319,15 @@ void rpcs3_app::InitializeConnects()
* Handle a request to change the stylesheet. May consider adding reporting of errors in future.
* Empty string means default.
*/
void rpcs3_app::OnChangeStyleSheetRequest(const QString& sheetFilePath)
void rpcs3_app::OnChangeStyleSheetRequest(const QString& path)
{
QFile file(sheetFilePath);
if (sheetFilePath == "")
{
auto rgba = [](const QColor& c, int v = 0)
{
return QString("rgba(%1, %2, %3, %4);").arg(c.red() + v).arg(c.green() + v).arg(c.blue() + v).arg(c.alpha() + v);
};
QString rgba_tool_bar = rgba(gui::mw_tool_bar_color);
QString style_sheet = QString
QString style_sheet
(
// main window toolbar search
//"QLineEdit#mw_searchbar { margin-left:14px; background-color: " + rgba_tool_bar + " }"
@ -399,6 +396,16 @@ void rpcs3_app::OnChangeStyleSheetRequest(const QString& sheetFilePath)
"QLabel#gamegrid_font { font-weight: 600; font-size: 8pt; font-family: Lucida Grande; color: rgba(51, 51, 51, 255); }"
);
QFile file(path);
#if !defined(_WIN32) && !defined(__APPLE__)
// If we can't open the file, try the /share folder
QString share_dir = QCoreApplication::applicationDirPath() + "/../share/rpcs3/";
QFile share_file(share_dir + "GuiConfigs/" + QFileInfo(file.fileName()).fileName());
#endif
if (path == "")
{
setStyleSheet(style_sheet);
}
else if (file.open(QIODevice::ReadOnly | QIODevice::Text))
@ -421,19 +428,18 @@ void rpcs3_app::OnChangeStyleSheetRequest(const QString& sheetFilePath)
file.close();
}
#if !defined(_WIN32) && !defined(__APPLE__)
else
else if (share_file.open(QIODevice::ReadOnly | QIODevice::Text))
{
// If we can't open the file, try the /share folder
QString shareDir = QCoreApplication::applicationDirPath() + "/../share/rpcs3/";
QDir::setCurrent(shareDir);
QFile newFile(shareDir + "GuiConfigs/" + QFileInfo(file.fileName()).fileName());
if (newFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
setStyleSheet(newFile.readAll());
newFile.close();
}
QDir::setCurrent(share_dir);
setStyleSheet(share_file.readAll());
share_file.close();
}
#endif
else
{
setStyleSheet(style_sheet);
}
gui::stylesheet = styleSheet();
RPCS3MainWin->RepaintGui();
}