Skip to content

Commit b3a8752

Browse files
committed
Fix after rebase.
1 parent 1608f37 commit b3a8752

12 files changed

Lines changed: 470 additions & 507 deletions

src/extensionlistproxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef EXTENSIONLISTPROXY_H
22
#define EXTENSIONLISTPROXY_H
33

4-
#include <iextensionlist.h>
4+
#include <uibase/extensions/iextensionlist.h>
55

66
#include "extensionmanager.h"
77

src/extensionmanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <boost/fusion/container.hpp>
88
#include <boost/fusion/include/at_key.hpp>
99

10-
#include <extension.h>
10+
#include <uibase/extensions/extension.h>
1111

1212
#include "extensionwatcher.h"
1313

src/extensionwatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef EXTENSIONWATCHER_H
22
#define EXTENSIONWATCHER_H
33

4-
#include <extension.h>
4+
#include <uibase/extensions/extension.h>
55

66
// an extension watcher is a class that watches extensions get loaded/unloaded,
77
// typically to extract information from theme that are needed by MO2

src/organizer_en.ts

Lines changed: 346 additions & 463 deletions
Large diffs are not rendered by default.

src/organizercore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ bool OrganizerCore::previewFileWithAlternatives(QWidget* parent, QString fileNam
10811081
libbsarch::memory_blob fileData =
10821082
archiveLoader.extract_to_memory(fileName.toStdWString());
10831083
QByteArray convertedFileData((char*)(fileData.data), fileData.size);
1084-
QWidget* wid = m_PluginContainer->previewGenerator().genArchivePreview(
1084+
QWidget* wid = m_PluginManager->previewGenerator().genArchivePreview(
10851085
convertedFileData, filePath);
10861086
if (wid == nullptr) {
10871087
reportError(tr("failed to generate preview for %1").arg(filePath));

src/pluginmanager.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
#include <QObject>
1313

14-
#include <extension.h>
15-
#include <iplugin.h>
16-
#include <iplugindiagnose.h>
17-
#include <ipluginfilemapper.h>
18-
#include <iplugingame.h>
19-
#include <iplugininstaller.h>
20-
#include <ipluginloader.h>
21-
#include <ipluginmodpage.h>
22-
#include <ipluginpreview.h>
23-
#include <iplugintool.h>
14+
#include <uibase/extensions/extension.h>
15+
#include <uibase/extensions/ipluginloader.h>
16+
#include <uibase/iplugin.h>
17+
#include <uibase/iplugindiagnose.h>
18+
#include <uibase/ipluginfilemapper.h>
19+
#include <uibase/iplugingame.h>
20+
#include <uibase/iplugininstaller.h>
21+
#include <uibase/ipluginmodpage.h>
22+
#include <uibase/ipluginpreview.h>
23+
#include <uibase/iplugintool.h>
2424

2525
#include "game_features.h"
2626
#include "previewgenerator.h"

src/previewgenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ QWidget* PreviewGenerator::genArchivePreview(const QByteArray& fileData,
6767
const QString& fileName) const
6868
{
6969
const QString ext = QFileInfo(fileName).suffix().toLower();
70-
auto& previews = m_PluginContainer.plugins<IPluginPreview>();
70+
auto& previews = m_PluginManager.plugins<IPluginPreview>();
7171
for (auto* preview : previews) {
72-
if (m_PluginContainer.isEnabled(preview) &&
72+
if (m_PluginManager.isEnabled(preview) &&
7373
preview->supportedExtensions().contains(ext) && preview->supportsArchives()) {
7474
return preview->genDataPreview(fileData, fileName, m_MaxSize);
7575
}

src/proxyqt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <map>
55

6-
#include <ipluginloader.h>
6+
#include <uibase/extensions/ipluginloader.h>
77

88
class ProxyQtLoader : public MOBase::IPluginLoader
99
{

src/settingsdialogextensionrow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <QWidget>
55

6-
#include "extension.h"
6+
#include <uibase/extensions/extension.h>
77

88
namespace Ui
99
{

src/thememanager.cpp

Lines changed: 100 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#include <QDir>
44
#include <QDirIterator>
55
#include <QProxyStyle>
6+
#include <QTextStream>
67

7-
#include <log.h>
8-
#include <utility.h>
8+
#include <uibase/log.h>
9+
#include <uibase/utility.h>
910

1011
#include "shared/appconfig.h"
1112

@@ -60,15 +61,95 @@ class ProxyStyle : public QProxyStyle
6061
}
6162
};
6263

64+
namespace
65+
{
66+
QString readWholeFile(std::filesystem::path const& path)
67+
{
68+
QFile file(path);
69+
if (!file.open(QFile::ReadOnly | QFile::Text)) {
70+
return {};
71+
}
72+
73+
return QTextStream(&file).readAll();
74+
}
75+
76+
QStringList extractTopStyleSheetComments(QString const& stylesheet)
77+
{
78+
QTextStream stream(stylesheet.toUtf8());
79+
QStringList topComments;
80+
81+
while (true) {
82+
const auto byteLine = stream.readLine();
83+
if (byteLine.isNull()) {
84+
break;
85+
}
86+
87+
const auto line = QString(byteLine).trimmed();
88+
89+
// skip empty lines
90+
if (line.isEmpty()) {
91+
continue;
92+
}
93+
94+
// only handle single line comments
95+
if (!line.startsWith("/*")) {
96+
break;
97+
}
98+
99+
topComments.push_back(line.mid(2, line.size() - 4).trimmed());
100+
}
101+
102+
return topComments;
103+
}
104+
105+
QString extractBaseStyleFromStyleSheet(std::filesystem::path const& path,
106+
QString const& stylesheet,
107+
const QString& defaultStyle)
108+
{
109+
// read the first line of the files that are either empty or comments
110+
//
111+
const auto topLines = extractTopStyleSheetComments(stylesheet);
112+
113+
const auto factoryStyles = QStyleFactory::keys();
114+
115+
QString style = defaultStyle;
116+
117+
for (const auto& line : topLines) {
118+
if (!line.startsWith("mo2-base-style")) {
119+
continue;
120+
}
121+
122+
const auto parts = line.split(":");
123+
if (parts.size() != 2) {
124+
log::warn("found invalid top-comment for mo2 in {}: {}", path, line);
125+
continue;
126+
}
127+
128+
const auto tmpStyle = parts[1].trimmed();
129+
const auto index = factoryStyles.indexOf(tmpStyle, 0, Qt::CaseInsensitive);
130+
if (index == -1) {
131+
log::warn("base style '{}' from style '{}' not found", tmpStyle, path, line);
132+
continue;
133+
}
134+
135+
style = factoryStyles[index];
136+
log::info("found base style '{}' for style '{}'", style, path);
137+
break;
138+
}
139+
140+
return style;
141+
}
142+
143+
} // namespace
144+
63145
ThemeManager::ThemeManager(QApplication* application) : m_app{application}
64146
{
65147
// add built-in themes
66148
addQtThemes();
67149

68150
// find the default theme - this might be a built-in Qt theme, or null, in which case
69151
// we just create a default theme
70-
if (auto it =
71-
m_baseThemesByIdentifier.find(m_app->style()->objectName().toStdString());
152+
if (auto it = m_baseThemesByIdentifier.find("windowsvista");
72153
it != m_baseThemesByIdentifier.end()) {
73154
m_defaultTheme = it->second;
74155
} else {
@@ -148,12 +229,14 @@ void ThemeManager::loadQtTheme(std::string_view themeIdentifier)
148229

149230
void ThemeManager::loadExtensionTheme(std::shared_ptr<const Theme> const& theme)
150231
{
232+
auto baseTheme = ToQString(m_defaultTheme->identifier());
233+
const auto stylesheet = buildStyleSheet(theme, baseTheme);
234+
151235
// load the default theme
152-
m_app->setStyle(
153-
new ProxyStyle(QStyleFactory::create(ToQString(m_defaultTheme->identifier()))));
236+
m_app->setStyle(new ProxyStyle(QStyleFactory::create(baseTheme)));
154237

155238
// build the stylesheet and set it
156-
m_app->setStyleSheet(buildStyleSheet(theme));
239+
m_app->setStyleSheet(stylesheet);
157240
}
158241

159242
void ThemeManager::unload()
@@ -198,24 +281,19 @@ void ThemeManager::addQtThemes()
198281
}
199282
}
200283

201-
namespace
284+
QString ThemeManager::buildStyleSheet(std::shared_ptr<const Theme> const& theme,
285+
QString& baseTheme) const
202286
{
203-
QString readWholeFile(std::filesystem::path const& path)
204-
{
205-
QFile file(path);
206-
if (!file.open(QFile::ReadOnly | QFile::Text)) {
207-
return {};
208-
}
287+
// read the file
288+
const auto stylesheetContent = readWholeFile(theme->stylesheet());
209289

210-
return QTextStream(&file).readAll();
211-
}
212-
} // namespace
290+
// check for base theme override
291+
baseTheme =
292+
extractBaseStyleFromStyleSheet(theme->stylesheet(), stylesheetContent, baseTheme);
213293

214-
QString ThemeManager::buildStyleSheet(std::shared_ptr<const Theme> const& theme) const
215-
{
216-
// create the base stylesheet
217-
QString stylesheet = patchStyleSheet(readWholeFile(theme->stylesheet()),
218-
theme->stylesheet().parent_path());
294+
// patch the file
295+
QString stylesheet =
296+
patchStyleSheet(stylesheetContent, theme->stylesheet().parent_path());
219297

220298
for (auto&& themeAddition : m_additions) {
221299
if (themeAddition->isAdditionFor(*theme)) {

0 commit comments

Comments
 (0)