diff options
-rw-r--r-- | launcher/Application.cpp | 29 | ||||
-rw-r--r-- | launcher/Application.h | 10 | ||||
-rw-r--r-- | launcher/DesktopServices.cpp | 2 | ||||
-rw-r--r-- | launcher/ui/MainWindow.cpp | 8 | ||||
-rw-r--r-- | launcher/ui/themes/ThemeManager.cpp | 44 | ||||
-rw-r--r-- | launcher/ui/themes/ThemeManager.h | 8 | ||||
-rw-r--r-- | launcher/ui/widgets/ThemeCustomizationWidget.cpp | 35 | ||||
-rw-r--r-- | launcher/ui/widgets/ThemeCustomizationWidget.ui | 94 |
8 files changed, 132 insertions, 98 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp index ea706d6f..40d506e3 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -900,7 +900,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) return; } - applyCurrentlySelectedTheme(true); + m_themeManager->applyCurrentlySelectedTheme(true); performMainStartupAction(); } @@ -942,7 +942,7 @@ bool Application::createSetupWizard() if (!validWidgets) settings()->set("ApplicationTheme", QString("system")); - applyCurrentlySelectedTheme(true); + m_themeManager->applyCurrentlySelectedTheme(true); m_setupWizard = new SetupWizard(nullptr); if (languageRequired) @@ -1167,31 +1167,6 @@ std::shared_ptr<JavaInstallList> Application::javalist() return m_javalist; } -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); -} - -void Application::setApplicationTheme(const QString& name) -{ - m_themeManager->setApplicationTheme(name); -} - -void Application::setIconTheme(const QString& name) -{ - m_themeManager->setIconTheme(name); -} - QIcon Application::getThemedIcon(const QString& name) { if(name == "logo") { diff --git a/launcher/Application.h b/launcher/Application.h index 0b953f0a..b8996022 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -119,15 +119,7 @@ public: QIcon getThemedIcon(const QString& name); - void setIconTheme(const QString& name); - - void applyCurrentlySelectedTheme(bool initial = false); - - QList<ITheme*> getValidApplicationThemes(); - - QList<IconTheme*> getValidIconThemes(); - - void setApplicationTheme(const QString& name); + ThemeManager* themeManager() { return m_themeManager.get(); } shared_qobject_ptr<ExternalUpdater> updater() { return m_updater; diff --git a/launcher/DesktopServices.cpp b/launcher/DesktopServices.cpp index 2984a1b4..4939161f 100644 --- a/launcher/DesktopServices.cpp +++ b/launcher/DesktopServices.cpp @@ -109,7 +109,7 @@ bool openDirectory(const QString &path, bool ensureExists) qDebug() << "Opening directory" << path; QDir parentPath; QDir dir(path); - if (!dir.exists()) + if (ensureExists && !dir.exists()) { parentPath.mkpath(dir.absolutePath()); } diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 600d245d..00bb296f 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -627,7 +627,7 @@ void MainWindow::updateThemeMenu() themeMenu = new QMenu(this); } - auto themes = APPLICATION->getValidApplicationThemes(); + auto themes = APPLICATION->themeManager()->getValidApplicationThemes(); QActionGroup* themesGroup = new QActionGroup(this); @@ -641,7 +641,7 @@ void MainWindow::updateThemeMenu() themeAction->setActionGroup(themesGroup); connect(themeAction, &QAction::triggered, [theme]() { - APPLICATION->setApplicationTheme(theme->id()); + APPLICATION->themeManager()->setApplicationTheme(theme->id()); APPLICATION->settings()->set("ApplicationTheme", theme->id()); }); } @@ -1152,12 +1152,12 @@ void MainWindow::on_actionViewCentralModsFolder_triggered() void MainWindow::on_actionViewIconThemeFolder_triggered() { - DesktopServices::openDirectory("iconthemes"); + DesktopServices::openDirectory(APPLICATION->themeManager()->getIconThemesFolder().path()); } void MainWindow::on_actionViewWidgetThemeFolder_triggered() { - DesktopServices::openDirectory("themes"); + DesktopServices::openDirectory(APPLICATION->themeManager()->getApplicationThemesFolder().path()); } void MainWindow::refreshInstances() diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index a9fae589..32585618 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -73,13 +73,12 @@ void ThemeManager::initializeIcons() // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies! // set icon theme search path! - QDir themeFolder("iconthemes"); - if (!themeFolder.mkpath(".")) + if (!m_iconThemeFolder.mkpath(".")) themeWarningLog() << "Couldn't create icon theme folder"; - themeDebugLog() << "Icon Theme Folder Path: " << themeFolder.absolutePath(); + themeDebugLog() << "Icon Theme Folder Path: " << m_iconThemeFolder.absolutePath(); auto searchPaths = QIcon::themeSearchPaths(); - searchPaths.append(themeFolder.path()); + searchPaths.append(m_iconThemeFolder.path()); QIcon::setThemeSearchPaths(searchPaths); themeDebugLog() << "<> Initializing Icon Themes"; @@ -95,7 +94,7 @@ void ThemeManager::initializeIcons() themeDebugLog() << "Loaded Built-In Icon Theme" << id; } - QDirIterator directoryIterator(themeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot); + QDirIterator directoryIterator(m_iconThemeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot); while (directoryIterator.hasNext()) { QDir dir(directoryIterator.next()); IconTheme theme(dir.dirName(), dir.path()); @@ -120,12 +119,11 @@ void ThemeManager::initializeWidgets() // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in // dropdown?) - QDir themeFolder("themes"); - if (!themeFolder.mkpath(".")) + if (!m_applicationThemeFolder.mkpath(".")) themeWarningLog() << "Couldn't create theme folder"; - themeDebugLog() << "Theme Folder Path: " << themeFolder.absolutePath(); + themeDebugLog() << "Theme Folder Path: " << m_applicationThemeFolder.absolutePath(); - QDirIterator directoryIterator(themeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + QDirIterator directoryIterator(m_applicationThemeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); while (directoryIterator.hasNext()) { QDir dir(directoryIterator.next()); QFileInfo themeJson(dir.absoluteFilePath("theme.json")); @@ -148,6 +146,16 @@ void ThemeManager::initializeWidgets() themeDebugLog() << "<> Widget themes initialized."; } +QList<IconTheme*> ThemeManager::getValidIconThemes() +{ + QList<IconTheme*> ret; + ret.reserve(m_icons.size()); + for (auto&& [id, theme] : m_icons) { + ret.append(&theme); + } + return ret; +} + QList<ITheme*> ThemeManager::getValidApplicationThemes() { QList<ITheme*> ret; @@ -158,14 +166,9 @@ QList<ITheme*> ThemeManager::getValidApplicationThemes() return ret; } -QList<IconTheme*> ThemeManager::getValidIconThemes() +bool ThemeManager::isValidIconTheme(const QString& id) { - QList<IconTheme*> ret; - ret.reserve(m_icons.size()); - for (auto&& [id, theme] : m_icons) { - ret.append(&theme); - } - return ret; + return !id.isEmpty() && m_icons.find(id) != m_icons.end(); } bool ThemeManager::isValidApplicationTheme(const QString& id) @@ -173,9 +176,14 @@ bool ThemeManager::isValidApplicationTheme(const QString& id) return !id.isEmpty() && m_themes.find(id) != m_themes.end(); } -bool ThemeManager::isValidIconTheme(const QString& id) +QDir ThemeManager::getIconThemesFolder() { - return !id.isEmpty() && m_icons.find(id) != m_icons.end(); + return m_iconThemeFolder; +} + +QDir ThemeManager::getApplicationThemesFolder() +{ + return m_applicationThemeFolder; } void ThemeManager::setIconTheme(const QString& name) diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index 627fdc75..5634a81a 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -37,10 +37,12 @@ class ThemeManager { public: ThemeManager(); - QList<ITheme*> getValidApplicationThemes(); QList<IconTheme*> getValidIconThemes(); - bool isValidApplicationTheme(const QString& id); + QList<ITheme*> getValidApplicationThemes(); bool isValidIconTheme(const QString& id); + bool isValidApplicationTheme(const QString& id); + QDir getIconThemesFolder(); + QDir getApplicationThemesFolder(); void applyCurrentlySelectedTheme(bool initial = false); void setIconTheme(const QString& name); void setApplicationTheme(const QString& name, bool initial = false); @@ -55,6 +57,8 @@ class ThemeManager { private: std::map<QString, std::unique_ptr<ITheme>> m_themes; std::map<QString, IconTheme> m_icons; + QDir m_iconThemeFolder{ "iconthemes" }; + QDir m_applicationThemeFolder{ "themes" }; void initializeThemes(); QString addTheme(std::unique_ptr<ITheme> theme); diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.cpp b/launcher/ui/widgets/ThemeCustomizationWidget.cpp index 455cbb7b..106a9ca3 100644 --- a/launcher/ui/widgets/ThemeCustomizationWidget.cpp +++ b/launcher/ui/widgets/ThemeCustomizationWidget.cpp @@ -19,17 +19,22 @@ #include "ui_ThemeCustomizationWidget.h" #include "Application.h" +#include "DesktopServices.h" #include "ui/themes/ITheme.h" #include "ui/themes/ThemeManager.h" -ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget) +ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget* parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget) { ui->setupUi(this); loadSettings(); connect(ui->iconsComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyIconTheme); - connect(ui->widgetStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyWidgetTheme); + connect(ui->widgetStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, + &ThemeCustomizationWidget::applyWidgetTheme); connect(ui->backgroundCatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyCatTheme); + + connect(ui->iconsFolder, &QPushButton::clicked, this, [] { DesktopServices::openDirectory(APPLICATION->themeManager()->getIconThemesFolder().path()); }); + connect(ui->widgetStyleFolder, &QPushButton::clicked, this, [] { DesktopServices::openDirectory(APPLICATION->themeManager()->getApplicationThemesFolder().path()); }); } ThemeCustomizationWidget::~ThemeCustomizationWidget() @@ -40,7 +45,7 @@ ThemeCustomizationWidget::~ThemeCustomizationWidget() /// <summary> /// The layout was not quite right, so currently this just disables the UI elements, which should be hidden instead /// TODO FIXME -/// +/// /// Original Method One: /// ui->iconsComboBox->setVisible(features& ThemeFields::ICONS); /// ui->iconsLabel->setVisible(features& ThemeFields::ICONS); @@ -48,7 +53,7 @@ ThemeCustomizationWidget::~ThemeCustomizationWidget() /// ui->widgetThemeLabel->setVisible(features& ThemeFields::WIDGETS); /// ui->backgroundCatComboBox->setVisible(features& ThemeFields::CAT); /// ui->backgroundCatLabel->setVisible(features& ThemeFields::CAT); -/// +/// /// original Method Two: /// if (!(features & ThemeFields::ICONS)) { /// ui->formLayout->setRowVisible(0, false); @@ -61,40 +66,44 @@ ThemeCustomizationWidget::~ThemeCustomizationWidget() /// } /// </summary> /// <param name="features"></param> -void ThemeCustomizationWidget::showFeatures(ThemeFields features) { +void ThemeCustomizationWidget::showFeatures(ThemeFields features) +{ ui->iconsComboBox->setEnabled(features & ThemeFields::ICONS); ui->iconsLabel->setEnabled(features & ThemeFields::ICONS); ui->widgetStyleComboBox->setEnabled(features & ThemeFields::WIDGETS); - ui->widgetThemeLabel->setEnabled(features & ThemeFields::WIDGETS); + ui->widgetStyleLabel->setEnabled(features & ThemeFields::WIDGETS); ui->backgroundCatComboBox->setEnabled(features & ThemeFields::CAT); ui->backgroundCatLabel->setEnabled(features & ThemeFields::CAT); } -void ThemeCustomizationWidget::applyIconTheme(int index) { +void ThemeCustomizationWidget::applyIconTheme(int index) +{ auto settings = APPLICATION->settings(); auto originalIconTheme = settings->get("IconTheme").toString(); auto newIconTheme = ui->iconsComboBox->currentData().toString(); if (originalIconTheme != newIconTheme) { settings->set("IconTheme", newIconTheme); - APPLICATION->applyCurrentlySelectedTheme(); + APPLICATION->themeManager()->applyCurrentlySelectedTheme(); } emit currentIconThemeChanged(index); } -void ThemeCustomizationWidget::applyWidgetTheme(int index) { +void ThemeCustomizationWidget::applyWidgetTheme(int index) +{ auto settings = APPLICATION->settings(); auto originalAppTheme = settings->get("ApplicationTheme").toString(); auto newAppTheme = ui->widgetStyleComboBox->currentData().toString(); if (originalAppTheme != newAppTheme) { settings->set("ApplicationTheme", newAppTheme); - APPLICATION->applyCurrentlySelectedTheme(); + APPLICATION->themeManager()->applyCurrentlySelectedTheme(); } emit currentWidgetThemeChanged(index); } -void ThemeCustomizationWidget::applyCatTheme(int index) { +void ThemeCustomizationWidget::applyCatTheme(int index) +{ auto settings = APPLICATION->settings(); settings->set("BackgroundCat", m_catOptions[index].first); @@ -113,7 +122,7 @@ void ThemeCustomizationWidget::loadSettings() { auto currentIconTheme = settings->get("IconTheme").toString(); - auto iconThemes = APPLICATION->getValidIconThemes(); + auto iconThemes = APPLICATION->themeManager()->getValidIconThemes(); int idx = 0; for (auto iconTheme : iconThemes) { QIcon iconForComboBox = QIcon(iconTheme->path() + "/scalable/settings"); @@ -127,7 +136,7 @@ void ThemeCustomizationWidget::loadSettings() { auto currentTheme = settings->get("ApplicationTheme").toString(); - auto themes = APPLICATION->getValidApplicationThemes(); + auto themes = APPLICATION->themeManager()->getValidApplicationThemes(); int idx = 0; for (auto& theme : themes) { ui->widgetStyleComboBox->addItem(theme->name(), theme->id()); diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.ui b/launcher/ui/widgets/ThemeCustomizationWidget.ui index 6b2c87f9..700c530c 100644 --- a/launcher/ui/widgets/ThemeCustomizationWidget.ui +++ b/launcher/ui/widgets/ThemeCustomizationWidget.ui @@ -40,20 +40,40 @@ </widget> </item> <item row="0" column="1"> - <widget class="QComboBox" name="iconsComboBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="focusPolicy"> - <enum>Qt::StrongFocus</enum> - </property> - </widget> + <layout class="QHBoxLayout" name="iconsLayout"> + <item> + <widget class="QComboBox" name="iconsComboBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="focusPolicy"> + <enum>Qt::StrongFocus</enum> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="iconsFolder"> + <property name="toolTip"> + <string>View icon themes folder.</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="viewfolder"/> + </property> + <property name="flat"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> </item> <item row="1" column="0"> - <widget class="QLabel" name="widgetThemeLabel"> + <widget class="QLabel" name="widgetStyleLabel"> <property name="text"> <string>&Widgets</string> </property> @@ -63,17 +83,37 @@ </widget> </item> <item row="1" column="1"> - <widget class="QComboBox" name="widgetStyleComboBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="focusPolicy"> - <enum>Qt::StrongFocus</enum> - </property> - </widget> + <layout class="QHBoxLayout" name="widgetStyleLayout"> + <item> + <widget class="QComboBox" name="widgetStyleComboBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="focusPolicy"> + <enum>Qt::StrongFocus</enum> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="widgetStyleFolder"> + <property name="toolTip"> + <string>View widget themes folder.</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="viewfolder"/> + </property> + <property name="flat"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> </item> <item row="2" column="0"> <widget class="QLabel" name="backgroundCatLabel"> @@ -89,7 +129,7 @@ </widget> </item> <item row="2" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout"> + <layout class="QHBoxLayout" name="catLayout"> <item> <widget class="QComboBox" name="backgroundCatComboBox"> <property name="sizePolicy"> @@ -127,6 +167,12 @@ </item> </layout> </widget> + <tabstops> + <tabstop>iconsComboBox</tabstop> + <tabstop>widgetStyleComboBox</tabstop> + <tabstop>backgroundCatComboBox</tabstop> + <tabstop>catInfoLabel</tabstop> + </tabstops> <resources/> <connections/> </ui> |