Minor stylesheet utils improvements

This commit is contained in:
Klaus Basan
2019-06-30 18:05:00 +02:00
committed by Mat Sutcliffe
parent 58b7c875bc
commit b8efe93cd8
2 changed files with 21 additions and 9 deletions

View File

@@ -27,6 +27,7 @@
#include <QTextStream> #include <QTextStream>
#include <QWidget> #include <QWidget>
#include <QtGlobal> #include <QtGlobal>
#include <QStringBuilder>
using namespace BlackConfig; using namespace BlackConfig;
using namespace BlackMisc; using namespace BlackMisc;
@@ -143,6 +144,8 @@ namespace BlackGui
QMap<QString, QString> newStyleSheets; QMap<QString, QString> newStyleSheets;
const QFileInfoList fileInfoList = directory.entryInfoList(); const QFileInfoList fileInfoList = directory.entryInfoList();
// here we generate the style sheets
for (const QFileInfo &fileInfo : fileInfoList) for (const QFileInfo &fileInfo : fileInfoList)
{ {
const QString absolutePath = fileInfo.absoluteFilePath(); const QString absolutePath = fileInfo.absoluteFilePath();
@@ -154,6 +157,13 @@ namespace BlackGui
const QString c = removeComments(in.readAll(), true, true); const QString c = removeComments(in.readAll(), true, true);
const QString f = fileInfo.fileName().toLower(); const QString f = fileInfo.fileName().toLower();
// save files for debugging
if (CBuildConfig::isLocalDeveloperDebugBuild())
{
const QString fn = CFileUtils::appendFilePaths(CDirectoryUtils::logDirectory(), f);
CFileUtils::writeStringToFile(c, fn);
}
// keep even empty files as placeholders // keep even empty files as placeholders
newStyleSheets.insert(f, c); // set an empty string here to disable all stylesheet newStyleSheets.insert(f, c); // set an empty string here to disable all stylesheet
} }
@@ -199,10 +209,12 @@ namespace BlackGui
{ {
s = m_styleSheets[key]; s = m_styleSheets[key];
} }
if (s.isEmpty()) continue; if (s.isEmpty()) { continue; }
if (!style.isEmpty()) style.append("\n\n");
style.append("/** file: ").append(fileName).append(" **/\n"); style +=
style.append(s); (style.isEmpty() ? QString() : "\n\n") %
u"/** file: " % fileName % " **/\n" %
s;
} }
return style; return style;
} }
@@ -476,15 +488,15 @@ namespace BlackGui
QString specific; QString specific;
if (CBuildConfig::isRunningOnWindowsNtPlatform()) if (CBuildConfig::isRunningOnWindowsNtPlatform())
{ {
specific = fn + ".win" + qss; specific = fn % u".win" % qss;
} }
else if (CBuildConfig::isRunningOnMacOSPlatform()) else if (CBuildConfig::isRunningOnMacOSPlatform())
{ {
specific = fn + ".mac" + qss; specific = fn % u".mac" % qss;
} }
else if (CBuildConfig::isRunningOnLinuxPlatform()) else if (CBuildConfig::isRunningOnLinuxPlatform())
{ {
specific = fn + ".linux" + qss; specific = fn % u".linux" % qss;
} }
return qssFileExists(specific) ? specific : fn + qss; return qssFileExists(specific) ? specific : fn + qss;
} }

View File

@@ -171,8 +171,8 @@ namespace BlackGui
//! Check existance of qss file //! Check existance of qss file
static bool qssFileExists(const QString &filename); static bool qssFileExists(const QString &filename);
QMap<QString, QString> m_styleSheets; //!< filename, stylesheet QMap<QString, QString> m_styleSheets; //!< filename, stylesheet
QFileSystemWatcher m_fileWatcher {this}; //!< Monitor my qss files QFileSystemWatcher m_fileWatcher { this }; //!< monitor my qss files
}; };
} }
#endif // guard #endif // guard