diff --git a/src/moapplication.cpp b/src/moapplication.cpp
index 3d294c7be..da06a3afc 100644
--- a/src/moapplication.cpp
+++ b/src/moapplication.cpp
@@ -44,6 +44,7 @@ along with Mod Organizer. If not, see .
#include
#include
#include
+#include
#include
// see addDllsToPath() below
@@ -558,14 +559,91 @@ bool MOApplication::notify(QObject* receiver, QEvent* event)
}
}
+namespace
+{
+QStringList extractTopStyleSheetComments(QFile& stylesheet)
+{
+ if (!stylesheet.open(QFile::ReadOnly)) {
+ log::error("failed to open stylesheet file {}", stylesheet.fileName());
+ return {};
+ }
+ ON_BLOCK_EXIT([&stylesheet]() {
+ stylesheet.close();
+ });
+
+ QStringList topComments;
+
+ while (true) {
+ const auto byteLine = stylesheet.readLine();
+ if (byteLine.isNull()) {
+ break;
+ }
+
+ const auto line = QString(byteLine).trimmed();
+
+ // skip empty lines
+ if (line.isEmpty()) {
+ continue;
+ }
+
+ // only handle single line comments
+ if (!line.startsWith("/*")) {
+ break;
+ }
+
+ topComments.push_back(line.mid(2, line.size() - 4).trimmed());
+ }
+
+ return topComments;
+}
+
+QString extractBaseStyleFromStyleSheet(QFile& stylesheet, const QString& defaultStyle)
+{
+ // read the first line of the files that are either empty or comments
+ //
+ const auto topLines = extractTopStyleSheetComments(stylesheet);
+
+ QString style = defaultStyle;
+
+ for (const auto& line : topLines) {
+ if (!line.startsWith("mo2-base-style")) {
+ continue;
+ }
+
+ const auto parts = line.split(":");
+ if (parts.size() != 2) {
+ log::warn("found invalid top-comment for mo2 in {}: {}", stylesheet.fileName(),
+ line);
+ continue;
+ }
+
+ const auto tmpStyle = parts[1].trimmed();
+ if (QStyleFactory::keys().count(tmpStyle) == 0) {
+ log::warn("base style '{}' from style '{}' not found", tmpStyle,
+ stylesheet.fileName(), line);
+ continue;
+ }
+
+ log::info("found base style '{}' for style '{}'", tmpStyle, stylesheet.fileName());
+ style = tmpStyle;
+ break;
+ }
+
+ return style;
+}
+
+} // namespace
+
void MOApplication::updateStyle(const QString& fileName)
{
if (QStyleFactory::keys().contains(fileName)) {
setStyleSheet("");
setStyle(new ProxyStyle(QStyleFactory::create(fileName)));
} else {
- setStyle(new ProxyStyle(QStyleFactory::create(m_defaultStyle)));
- if (QFile::exists(fileName)) {
+ QFile stylesheet(fileName);
+ if (stylesheet.exists()) {
+ setStyle(new ProxyStyle(QStyleFactory::create(
+ extractBaseStyleFromStyleSheet(stylesheet, m_defaultStyle))));
setStyleSheet(QString("file:///%1").arg(fileName));
} else {
log::warn("invalid stylesheet: {}", fileName);
diff --git a/src/organizer_en.ts b/src/organizer_en.ts
index 361eed9a7..dc4bc55e2 100644
--- a/src/organizer_en.ts
+++ b/src/organizer_en.ts
@@ -2901,37 +2901,37 @@ This is likely due to a corrupted or incompatible download or unrecognized archi
MOApplication
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -7639,12 +7639,12 @@ Destination:
-
+
-
+