Skip to content

Commit

Permalink
Use relative path to stylesheet fix #4130
Browse files Browse the repository at this point in the history
  • Loading branch information
triplus authored and wwmayer committed Mar 19, 2020
1 parent 1fcab29 commit af5e7ab
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
21 changes: 19 additions & 2 deletions src/Gui/Application.cpp
Expand Up @@ -2100,8 +2100,25 @@ void Application::runApplication(void)
style = it->second;
}
if (!style.empty()) {
QFile f(QLatin1String(style.c_str()));
if (f.open(QFile::ReadOnly)) {
// Search for stylesheet in user, system and resources location
QString user = QString::fromUtf8((App::Application::getUserAppDataDir() + "Gui/Stylesheets/").c_str());
QString system = QString::fromUtf8((App::Application::getResourceDir() + "Gui/Stylesheets/").c_str());
QString resources = QLatin1String(":/stylesheets/");

QFile f;
if (QFile::exists(user + QLatin1String(style.c_str()))) {
f.setFileName(user + QLatin1String(style.c_str()));
}
else if (QFile::exists(system + QLatin1String(style.c_str()))) {
f.setFileName(system + QLatin1String(style.c_str()));
}
else if (QFile::exists(resources + QLatin1String(style.c_str()))) {
f.setFileName(resources + QLatin1String(style.c_str()));
}
else {
}

if (f.open(QFile::ReadOnly | QFile::Text)) {
mdi->setBackground(QBrush(Qt::NoBrush));
QTextStream str(&f);
qApp->setStyleSheet(str.readAll());
Expand Down
21 changes: 19 additions & 2 deletions src/Gui/DlgGeneralImp.cpp
Expand Up @@ -171,7 +171,24 @@ void DlgGeneralImp::saveSettings()
hGrp->SetASCII("StyleSheet", (const char*)sheet.toByteArray());

if (!sheet.toString().isEmpty()) {
QFile f(sheet.toString());
// Search for stylesheet in user, system and resources location
QString user = QString::fromUtf8((App::Application::getUserAppDataDir() + "Gui/Stylesheets/").c_str());
QString system = QString::fromUtf8((App::Application::getResourceDir() + "Gui/Stylesheets/").c_str());
QString resources = QLatin1String(":/stylesheets/");

QFile f;
if (QFile::exists(user + sheet.toString())) {
f.setFileName(user + sheet.toString());
}
else if (QFile::exists(system + sheet.toString())) {
f.setFileName(system + sheet.toString());
}
else if (QFile::exists(resources + sheet.toString())) {
f.setFileName(resources + sheet.toString());
}
else {
}

if (f.open(QFile::ReadOnly)) {
mdi->setBackground(QBrush(Qt::NoBrush));
QTextStream str(&f);
Expand Down Expand Up @@ -307,7 +324,7 @@ void DlgGeneralImp::loadSettings()
fileNames = dir.entryInfoList(filter, QDir::Files, QDir::Name);
for (QFileInfoList::iterator jt = fileNames.begin(); jt != fileNames.end(); ++jt) {
if (cssFiles.find(jt->baseName()) == cssFiles.end()) {
cssFiles[jt->baseName()] = jt->absoluteFilePath();
cssFiles[jt->baseName()] = jt->fileName();
}
}
}
Expand Down
29 changes: 26 additions & 3 deletions src/Mod/Start/StartPage/StartPage.py
Expand Up @@ -299,9 +299,32 @@ def handle():
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("UseStyleSheet",False):
qssfile = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/MainWindow").GetString("StyleSheet","")
if qssfile:
with open(qssfile, 'r') as f:
ALTCSS = encode(f.read())
HTML = HTML.replace("<!--QSS-->","<style type=\"text/css\">"+ALTCSS+"</style>")
# Search for stylesheet in user, system and resources locations
user = os.path.join(FreeCAD.getUserAppDataDir(), "Gui", "Stylesheets")
system = os.path.join(FreeCAD.getResourceDir(), "Gui", "Stylesheets")
resources = ":/stylesheets"

res = False
if QtCore.QFile.exists(os.path.join(user, qssfile)):
path = os.path.join(user, qssfile)
elif QtCore.QFile.exists(os.path.join(system, qssfile)):
path = os.path.join(system, qssfile)
elif QtCore.QFile.exists(os.path.join(resources, qssfile)):
res = True
path = os.path.join(resources, qssfile)
else:
path = None

if path:
if res:
f = QtCore.QFile(path)
if f.open(QtCore.QIODevice.ReadOnly | QtCore.QFile.Text):
ALTCSS = encode(QtCore.QTextStream(f).readAll())
else:
with open(path, 'r') as f:
ALTCSS = encode(f.read())

HTML = HTML.replace("<!--QSS-->","<style type=\"text/css\">"+ALTCSS+"</style>")

# turn tips off if needed

Expand Down

0 comments on commit af5e7ab

Please sign in to comment.