aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorTheKodeToad <TheKodeToad@proton.me>2023-07-18 22:50:43 +0100
committerTheKodeToad <TheKodeToad@proton.me>2023-07-18 22:51:34 +0100
commit97662f5c8ecdf32403939e427c74310f9175fb9e (patch)
tree1370d4efc8a2d8f03eaca33981f41d3f7a4877e7 /launcher
parente8c44e700d68078ec4242347b505ed2bddabbe06 (diff)
downloadPrismLauncher-97662f5c8ecdf32403939e427c74310f9175fb9e.tar.gz
PrismLauncher-97662f5c8ecdf32403939e427c74310f9175fb9e.tar.bz2
PrismLauncher-97662f5c8ecdf32403939e427c74310f9175fb9e.zip
Multiple icon themes!
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Application.cpp5
-rw-r--r--launcher/Application.h3
-rw-r--r--launcher/CMakeLists.txt2
-rw-r--r--launcher/resources/multimc/index.theme2
-rw-r--r--launcher/resources/pe_blue/index.theme2
-rw-r--r--launcher/resources/pe_colored/index.theme2
-rw-r--r--launcher/resources/pe_dark/index.theme2
-rw-r--r--launcher/resources/pe_light/index.theme2
-rw-r--r--launcher/ui/themes/IconTheme.cpp35
-rw-r--r--launcher/ui/themes/IconTheme.h18
-rw-r--r--launcher/ui/themes/ThemeManager.cpp121
-rw-r--r--launcher/ui/themes/ThemeManager.h8
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.cpp22
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.h19
14 files changed, 173 insertions, 70 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index d6c135de..df8a2363 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -1163,6 +1163,11 @@ QList<ITheme*> Application::getValidApplicationThemes()
return m_themeManager->getValidApplicationThemes();
}
+QList<IconTheme*> Application::getValidIconThemes()
+{
+ return m_themeManager->getValidIconThemes();
+}
+
void Application::applyCurrentlySelectedTheme(bool initial)
{
m_themeManager->applyCurrentlySelectedTheme(initial);
diff --git a/launcher/Application.h b/launcher/Application.h
index 527c536b..0b953f0a 100644
--- a/launcher/Application.h
+++ b/launcher/Application.h
@@ -70,6 +70,7 @@ class TranslationsModel;
class ITheme;
class MCEditTool;
class ThemeManager;
+class IconTheme;
namespace Meta {
class Index;
@@ -124,6 +125,8 @@ public:
QList<ITheme*> getValidApplicationThemes();
+ QList<IconTheme*> getValidIconThemes();
+
void setApplicationTheme(const QString& name);
shared_qobject_ptr<ExternalUpdater> updater() {
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 7cba97b4..89fc901b 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -759,6 +759,8 @@ SET(LAUNCHER_SOURCES
ui/themes/ITheme.h
ui/themes/SystemTheme.cpp
ui/themes/SystemTheme.h
+ ui/themes/IconTheme.cpp
+ ui/themes/IconTheme.h
ui/themes/ThemeManager.cpp
ui/themes/ThemeManager.h
diff --git a/launcher/resources/multimc/index.theme b/launcher/resources/multimc/index.theme
index 070e23f1..4da8072d 100644
--- a/launcher/resources/multimc/index.theme
+++ b/launcher/resources/multimc/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=multimc
+Name=Legacy
Comment=Default Icons
Inherits=default
Directories=8x8,16x16,22x22,24x24,32x32,32x32/instances,48x48,50x50/instances,64x64,128x128/instances,256x256,scalable,scalable/instances
diff --git a/launcher/resources/pe_blue/index.theme b/launcher/resources/pe_blue/index.theme
index c9e0d93a..6d842b5d 100644
--- a/launcher/resources/pe_blue/index.theme
+++ b/launcher/resources/pe_blue/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=pe_blue
+Name=Simple (Blue)
Comment=Icons by pexner (blue)
Inherits=multimc
Directories=scalable
diff --git a/launcher/resources/pe_colored/index.theme b/launcher/resources/pe_colored/index.theme
index b757bbd7..bca5494f 100644
--- a/launcher/resources/pe_colored/index.theme
+++ b/launcher/resources/pe_colored/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=pe_colored
+Name=Simple (Colored)
Comment=Icons by pexner (colored)
Inherits=multimc
Directories=scalable
diff --git a/launcher/resources/pe_dark/index.theme b/launcher/resources/pe_dark/index.theme
index b7d1ad01..4cfbf09c 100644
--- a/launcher/resources/pe_dark/index.theme
+++ b/launcher/resources/pe_dark/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=pe_dark
+Name=Simple (Dark)
Comment=Icons by pexner (dark)
Inherits=multimc
Directories=scalable
diff --git a/launcher/resources/pe_light/index.theme b/launcher/resources/pe_light/index.theme
index c106acc8..87b76d13 100644
--- a/launcher/resources/pe_light/index.theme
+++ b/launcher/resources/pe_light/index.theme
@@ -1,5 +1,5 @@
[Icon Theme]
-Name=pe_light
+Name=Simple (Light)
Comment=Icons by pexner (light)
Inherits=multimc
Directories=scalable
diff --git a/launcher/ui/themes/IconTheme.cpp b/launcher/ui/themes/IconTheme.cpp
new file mode 100644
index 00000000..ef245505
--- /dev/null
+++ b/launcher/ui/themes/IconTheme.cpp
@@ -0,0 +1,35 @@
+#include "IconTheme.h"
+
+#include <QFile>
+#include <QSettings>
+
+IconTheme::IconTheme(const QString& id, const QString& path) : m_id(id), m_path(path) {}
+
+bool IconTheme::load()
+{
+ QString path = m_path + "/index.theme";
+
+ if (!QFile::exists(path))
+ return false;
+
+ QSettings settings(path, QSettings::IniFormat);
+ settings.beginGroup("Icon Theme");
+ m_name = settings.value("Name").toString();
+ settings.endGroup();
+ return !m_name.isNull();
+}
+
+QString IconTheme::id()
+{
+ return m_id;
+}
+
+QString IconTheme::path()
+{
+ return m_path;
+}
+
+QString IconTheme::name()
+{
+ return m_name;
+} \ No newline at end of file
diff --git a/launcher/ui/themes/IconTheme.h b/launcher/ui/themes/IconTheme.h
new file mode 100644
index 00000000..cb05d8c7
--- /dev/null
+++ b/launcher/ui/themes/IconTheme.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <QString>
+
+class IconTheme {
+ public:
+ IconTheme(const QString& id, const QString& path);
+
+ bool load();
+ QString id();
+ QString path();
+ QString name();
+
+ private:
+ QString m_id;
+ QString m_path;
+ QString m_name;
+}; \ No newline at end of file
diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp
index b50c6157..3453a246 100644
--- a/launcher/ui/themes/ThemeManager.cpp
+++ b/launcher/ui/themes/ThemeManager.cpp
@@ -55,50 +55,84 @@ ITheme* ThemeManager::getTheme(QString themeId)
void ThemeManager::initializeThemes()
{
// Icon themes
- {
- // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
- // set icon theme search path!
- auto searchPaths = QIcon::themeSearchPaths();
- searchPaths.append("iconthemes");
- QIcon::setThemeSearchPaths(searchPaths);
- themeDebugLog() << "<> Icon themes initialized.";
- }
+ initializeIcons();
// Initialize widget themes
- {
- themeDebugLog() << "<> Initializing Widget Themes";
- themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
- auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
- themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
- themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
-
- // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
- // dropdown?)
- QString themeFolder = QDir("./themes/").absoluteFilePath("");
- themeDebugLog() << "Theme Folder Path: " << themeFolder;
-
- QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
- while (directoryIterator.hasNext()) {
- QDir dir(directoryIterator.next());
- QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
- if (themeJson.exists()) {
- // Load "theme.json" based themes
- themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
- addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
- } else {
- // Load pure QSS Themes
- QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
- while (stylesheetFileIterator.hasNext()) {
- QFile customThemeFile(stylesheetFileIterator.next());
- QFileInfo customThemeFileInfo(customThemeFile);
- themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
- addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
- }
- }
+ initializeWidgets();
+}
+
+void ThemeManager::initializeIcons()
+{
+ // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
+ // set icon theme search path!
+
+ QString themeFolder = "iconthemes";
+
+ auto searchPaths = QIcon::themeSearchPaths();
+ searchPaths.append(themeFolder);
+ QIcon::setThemeSearchPaths(searchPaths);
+
+ themeDebugLog() << "<> Initializing Icon Themes";
+
+ for (const QString& id : builtinIcons) {
+ IconTheme theme(id, QString(":/icons/%1").arg(id));
+ if (!theme.load()) {
+ themeWarningLog() << "Couldn't load built-in icon theme" << id;
+ continue;
}
- themeDebugLog() << "<> Widget themes initialized.";
+ m_icons.append(theme);
+ themeDebugLog() << "Loaded Built-In Icon Theme" << id;
+ }
+
+ QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
+ while (directoryIterator.hasNext()) {
+ QDir dir(directoryIterator.next());
+ IconTheme theme(dir.dirName(), dir.path());
+ if (!theme.load())
+ continue;
+
+ m_icons.append(theme);
+ themeDebugLog() << "Loaded Custom Icon Theme from" << dir.path();
+ }
+
+ themeDebugLog() << "<> Icon themes initialized.";
+}
+
+void ThemeManager::initializeWidgets()
+{
+ themeDebugLog() << "<> Initializing Widget Themes";
+ themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
+ auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
+ themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
+ themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
+
+ // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
+ // dropdown?)
+ QString themeFolder = QDir("./themes/").absoluteFilePath("");
+ themeDebugLog() << "Theme Folder Path: " << themeFolder;
+
+ QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
+ while (directoryIterator.hasNext()) {
+ QDir dir(directoryIterator.next());
+ QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
+ if (themeJson.exists()) {
+ // Load "theme.json" based themes
+ themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
+ addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
+ } else {
+ // Load pure QSS Themes
+ QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
+ while (stylesheetFileIterator.hasNext()) {
+ QFile customThemeFile(stylesheetFileIterator.next());
+ QFileInfo customThemeFileInfo(customThemeFile);
+ themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
+ addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
+ }
+ }
}
+
+ themeDebugLog() << "<> Widget themes initialized.";
}
QList<ITheme*> ThemeManager::getValidApplicationThemes()
@@ -111,6 +145,15 @@ QList<ITheme*> ThemeManager::getValidApplicationThemes()
return ret;
}
+QList<IconTheme*> ThemeManager::getValidIconThemes()
+{
+ QList<IconTheme*> ret;
+ ret.reserve(m_icons.size());
+ for (IconTheme& theme : m_icons)
+ ret.append(&theme);
+ return ret;
+}
+
void ThemeManager::setIconTheme(const QString& name)
{
QIcon::setThemeName(name);
diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h
index d2a6fb70..7509377c 100644
--- a/launcher/ui/themes/ThemeManager.h
+++ b/launcher/ui/themes/ThemeManager.h
@@ -19,6 +19,7 @@
#include <QString>
+#include "IconTheme.h"
#include "ui/MainWindow.h"
#include "ui/themes/ITheme.h"
@@ -36,6 +37,7 @@ class ThemeManager {
ThemeManager(MainWindow* mainWindow);
QList<ITheme*> getValidApplicationThemes();
+ QList<IconTheme*> getValidIconThemes();
void setIconTheme(const QString& name);
void applyCurrentlySelectedTheme(bool initial = false);
void setApplicationTheme(const QString& name, bool initial = false);
@@ -49,9 +51,15 @@ class ThemeManager {
private:
std::map<QString, std::unique_ptr<ITheme>> m_themes;
+ QList<IconTheme> m_icons;
MainWindow* m_mainWindow;
void initializeThemes();
QString addTheme(std::unique_ptr<ITheme> theme);
ITheme* getTheme(QString themeId);
+ void initializeIcons();
+ void initializeWidgets();
+
+ const QStringList builtinIcons{ "pe_colored", "pe_light", "pe_dark", "pe_blue", "breeze_light", "breeze_dark",
+ "OSX", "iOS", "flat", "flat_white", "multimc" };
};
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.cpp b/launcher/ui/widgets/ThemeCustomizationWidget.cpp
index 3bfcd821..455cbb7b 100644
--- a/launcher/ui/widgets/ThemeCustomizationWidget.cpp
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.cpp
@@ -73,10 +73,9 @@ void ThemeCustomizationWidget::showFeatures(ThemeFields features) {
void ThemeCustomizationWidget::applyIconTheme(int index) {
auto settings = APPLICATION->settings();
auto originalIconTheme = settings->get("IconTheme").toString();
- auto& newIconTheme = m_iconThemeOptions[index].first;
- settings->set("IconTheme", newIconTheme);
-
+ auto newIconTheme = ui->iconsComboBox->currentData().toString();
if (originalIconTheme != newIconTheme) {
+ settings->set("IconTheme", newIconTheme);
APPLICATION->applyCurrentlySelectedTheme();
}
@@ -112,12 +111,17 @@ void ThemeCustomizationWidget::loadSettings()
{
auto settings = APPLICATION->settings();
- auto iconTheme = settings->get("IconTheme").toString();
- for (auto& iconThemeFromList : m_iconThemeOptions) {
- QIcon iconForComboBox = QIcon(QString(":/icons/%1/scalable/settings").arg(iconThemeFromList.first));
- ui->iconsComboBox->addItem(iconForComboBox, iconThemeFromList.second);
- if (iconTheme == iconThemeFromList.first) {
- ui->iconsComboBox->setCurrentIndex(ui->iconsComboBox->count() - 1);
+ {
+ auto currentIconTheme = settings->get("IconTheme").toString();
+ auto iconThemes = APPLICATION->getValidIconThemes();
+ int idx = 0;
+ for (auto iconTheme : iconThemes) {
+ QIcon iconForComboBox = QIcon(iconTheme->path() + "/scalable/settings");
+ ui->iconsComboBox->addItem(iconForComboBox, iconTheme->name(), iconTheme->id());
+ if (currentIconTheme == iconTheme->id()) {
+ ui->iconsComboBox->setCurrentIndex(idx);
+ }
+ idx++;
}
}
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.h b/launcher/ui/widgets/ThemeCustomizationWidget.h
index 6c33c3c5..976ede43 100644
--- a/launcher/ui/widgets/ThemeCustomizationWidget.h
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.h
@@ -31,7 +31,7 @@ class ThemeCustomizationWidget : public QWidget {
public:
explicit ThemeCustomizationWidget(QWidget* parent = nullptr);
- ~ThemeCustomizationWidget();
+ ~ThemeCustomizationWidget() override;
void showFeatures(ThemeFields features);
@@ -53,22 +53,7 @@ class ThemeCustomizationWidget : public QWidget {
private:
Ui::ThemeCustomizationWidget* ui;
- //TODO finish implementing
- QList<std::pair<QString, QString>> m_iconThemeOptions{
- { "pe_colored", QObject::tr("Simple (Colored Icons)") },
- { "pe_light", QObject::tr("Simple (Light Icons)") },
- { "pe_dark", QObject::tr("Simple (Dark Icons)") },
- { "pe_blue", QObject::tr("Simple (Blue Icons)") },
- { "breeze_light", QObject::tr("Breeze Light") },
- { "breeze_dark", QObject::tr("Breeze Dark") },
- { "OSX", QObject::tr("OSX") },
- { "iOS", QObject::tr("iOS") },
- { "flat", QObject::tr("Flat") },
- { "flat_white", QObject::tr("Flat (White)") },
- { "multimc", QObject::tr("Legacy") },
- { "custom", QObject::tr("Custom") }
- };
- QList<std::pair<QString, QString>> m_catOptions{
+ QList<std::pair<QString, QString>> m_catOptions{
{ "kitteh", QObject::tr("Background Cat (from MultiMC)") },
{ "rory", QObject::tr("Rory ID 11 (drawn by Ashtaka)") },
{ "rory-flat", QObject::tr("Rory ID 11 (flat edition, drawn by Ashtaka)") },