diff options
author | Tayou <tayou@gmx.net> | 2022-11-01 15:41:08 +0100 |
---|---|---|
committer | Tayou <tayou@gmx.net> | 2022-11-01 20:17:53 +0100 |
commit | a3f5ea359827abb7949070cdcd8d56be50ab3360 (patch) | |
tree | 65bb5898e45aae3fcad239e0b88673e84adc28aa /launcher/ui | |
parent | fef60a9da0216bdcb266d935bbfea03aba8905b4 (diff) | |
download | PrismLauncher-a3f5ea359827abb7949070cdcd8d56be50ab3360.tar.gz PrismLauncher-a3f5ea359827abb7949070cdcd8d56be50ab3360.tar.bz2 PrismLauncher-a3f5ea359827abb7949070cdcd8d56be50ab3360.zip |
added suggested changes
Signed-off-by: Tayou <tayou@gmx.net>
Diffstat (limited to 'launcher/ui')
-rw-r--r-- | launcher/ui/themes/CustomTheme.cpp | 24 | ||||
-rw-r--r-- | launcher/ui/themes/CustomTheme.h | 3 | ||||
-rw-r--r-- | launcher/ui/themes/SystemTheme.cpp | 10 | ||||
-rw-r--r-- | launcher/ui/themes/ThemeManager.cpp | 60 | ||||
-rw-r--r-- | launcher/ui/themes/ThemeManager.h | 15 |
5 files changed, 60 insertions, 52 deletions
diff --git a/launcher/ui/themes/CustomTheme.cpp b/launcher/ui/themes/CustomTheme.cpp index 3c35bf37..c346d42f 100644 --- a/launcher/ui/themes/CustomTheme.cpp +++ b/launcher/ui/themes/CustomTheme.cpp @@ -66,7 +66,7 @@ static bool readThemeJson(const QString &path, QPalette &palette, double &fadeAm QColor color(colorValue); if(!color.isValid()) { - themeWarningLog << "Color value" << colorValue << "for" << colorName << "was not recognized."; + themeWarningLog() << "Color value" << colorValue << "for" << colorName << "was not recognized."; return QColor(); } return color; @@ -82,7 +82,7 @@ static bool readThemeJson(const QString &path, QPalette &palette, double &fadeAm } else { - themeDebugLog << "Color value for" << colorName << "was not present."; + themeDebugLog() << "Color value for" << colorName << "was not present."; } }; @@ -108,13 +108,13 @@ static bool readThemeJson(const QString &path, QPalette &palette, double &fadeAm } catch (const Exception &e) { - themeWarningLog << "Couldn't load theme json: " << e.cause(); + themeWarningLog() << "Couldn't load theme json: " << e.cause(); return false; } } else { - themeDebugLog << "No theme json present."; + themeDebugLog() << "No theme json present."; return false; } return true; @@ -160,7 +160,7 @@ static bool writeThemeJson(const QString &path, const QPalette &palette, double } catch (const Exception &e) { - themeWarningLog << "Failed to write theme json to" << path; + themeWarningLog() << "Failed to write theme json to" << path; return false; } } @@ -179,7 +179,7 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest if(!FS::ensureFolderPathExists(path) || !FS::ensureFolderPathExists(pathResources)) { - themeWarningLog << "X couldn't create folder for theme!"; + themeWarningLog() << "couldn't create folder for theme!"; m_palette = baseTheme->colorScheme(); m_styleSheet = baseTheme->appStyleSheet(); return; @@ -192,7 +192,7 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest m_palette = baseTheme->colorScheme(); if (!readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath, jsonDataIncomplete)) { - themeDebugLog << "Did not read theme json file correctly, writing new one to: " << themeFilePath; + themeDebugLog() << "Did not read theme json file correctly, writing new one to: " << themeFilePath; m_name = "Custom"; m_palette = baseTheme->colorScheme(); m_fadeColor = baseTheme->fadeColor(); @@ -223,13 +223,13 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest } catch (const Exception &e) { - themeWarningLog << "X Couldn't load css:" << e.cause() << "from" << cssFilePath; + themeWarningLog() << "Couldn't load css:" << e.cause() << "from" << cssFilePath; m_styleSheet = baseTheme->appStyleSheet(); } } else { - themeDebugLog << "X No theme css present."; + themeDebugLog() << "No theme css present."; m_styleSheet = baseTheme->appStyleSheet(); try { @@ -237,7 +237,7 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest } catch (const Exception &e) { - themeWarningLog << "X Couldn't write css:" << e.cause() << "to" << cssFilePath; + themeWarningLog() << "Couldn't write css:" << e.cause() << "to" << cssFilePath; } } } else { @@ -250,7 +250,7 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest if(!FS::ensureFilePathExists(path)) { - themeWarningLog << m_name << " Theme file path doesn't exist!"; + themeWarningLog() << m_name << " Theme file path doesn't exist!"; m_palette = baseTheme->colorScheme(); m_styleSheet = baseTheme->appStyleSheet(); return; @@ -264,7 +264,7 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest } catch (const Exception &e) { - themeWarningLog << "Couldn't load qss:" << e.cause() << "from" << path; + themeWarningLog() << "Couldn't load qss:" << e.cause() << "from" << path; m_styleSheet = baseTheme->appStyleSheet(); } } diff --git a/launcher/ui/themes/CustomTheme.h b/launcher/ui/themes/CustomTheme.h index f4a7b737..6d1f46b4 100644 --- a/launcher/ui/themes/CustomTheme.h +++ b/launcher/ui/themes/CustomTheme.h @@ -39,8 +39,7 @@ #pragma once #include "ITheme.h" -#include <QFile> -#include <QDir> +#include <QFileInfo> class CustomTheme: public ITheme { diff --git a/launcher/ui/themes/SystemTheme.cpp b/launcher/ui/themes/SystemTheme.cpp index b8eb2a3c..ec24c6d7 100644 --- a/launcher/ui/themes/SystemTheme.cpp +++ b/launcher/ui/themes/SystemTheme.cpp @@ -45,25 +45,25 @@ SystemTheme::SystemTheme() { - themeDebugLog << "Determining System Theme..."; + themeDebugLog() << "Determining System Theme..."; const auto & style = QApplication::style(); systemPalette = style->standardPalette(); QString lowerThemeName = style->objectName(); - themeDebugLog << "System theme seems to be:" << lowerThemeName; + themeDebugLog() << "System theme seems to be:" << lowerThemeName; QStringList styles = QStyleFactory::keys(); for(auto &st: styles) { - themeDebugLog << "Considering theme from theme factory:" << st.toLower(); + themeDebugLog() << "Considering theme from theme factory:" << st.toLower(); if(st.toLower() == lowerThemeName) { systemTheme = st; - themeDebugLog << "System theme has been determined to be:" << systemTheme; + themeDebugLog() << "System theme has been determined to be:" << systemTheme; return; } } // fall back to fusion if we can't find the current theme. systemTheme = "Fusion"; - themeDebugLog << "System theme not found, defaulted to Fusion"; + themeDebugLog() << "System theme not found, defaulted to Fusion"; } void SystemTheme::apply(bool initial) diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index 6e1566d2..3c338fd6 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -29,20 +29,25 @@ #include "Application.h"
#ifdef Q_OS_WIN
-#include <versionhelpers.h>
+#include <windows.h>
+// this is needed for versionhelpers.h, it is also included in WinDarkmode, but we can't rely on that.
+// Ultimately this should be included in versionhelpers, but that is outside of the project.
#include "ui/WinDarkmode.h"
+#include <versionhelpers.h>
#endif
ThemeManager::ThemeManager(MainWindow* mainWindow) {
m_mainWindow = mainWindow;
+ InitializeThemes();
}
/// @brief Adds the Theme to the list of themes
/// @param theme The Theme to add
/// @return Theme ID
-QString ThemeManager::AddTheme(ITheme * theme) {
- m_themes.insert(std::make_pair(theme->id(), std::unique_ptr<ITheme>(theme)));
- return theme->id();
+QString ThemeManager::AddTheme(std::unique_ptr<ITheme> theme) {
+ QString id = theme->id();
+ m_themes.emplace(id, std::move(theme));
+ return id;
}
/// @brief Gets the Theme from the List via ID
@@ -62,20 +67,20 @@ void ThemeManager::InitializeThemes() { auto searchPaths = QIcon::themeSearchPaths();
searchPaths.append("iconthemes");
QIcon::setThemeSearchPaths(searchPaths);
- themeDebugLog << "<> Icon themes initialized.";
+ themeDebugLog() << "<> Icon themes initialized.";
}
// Initialize widget themes
{
- themeDebugLog << "<> Initializing Widget Themes";
- themeDebugLog "✓ Loading Built-in Theme:" << AddTheme(new SystemTheme());
- auto darkThemeId = AddTheme(new DarkTheme());
- themeDebugLog "✓ Loading Built-in Theme:" << darkThemeId;
- themeDebugLog "✓ Loading Built-in Theme:" << AddTheme(new BrightTheme());
+ 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? Dunno how to do that though)
- QString themeFolder = (new QDir("./themes/"))->absoluteFilePath("");
- themeDebugLog << "Theme Folder Path: " << themeFolder;
+ // 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()) {
@@ -83,34 +88,30 @@ void ThemeManager::InitializeThemes() { QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
if (themeJson.exists()) {
// Load "theme.json" based themes
- themeDebugLog "✓ Loading JSON Theme from:" << themeJson.absoluteFilePath();
- CustomTheme* theme = new CustomTheme(GetTheme(darkThemeId), themeJson, true);
- AddTheme(theme);
+ 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();
- CustomTheme* theme = new CustomTheme(GetTheme(darkThemeId), customThemeFileInfo, false);
- AddTheme(theme);
+ themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
+ AddTheme(std::make_unique<CustomTheme>(GetTheme(darkThemeId), customThemeFileInfo, false));
}
}
}
- themeDebugLog << "<> Widget themes initialized.";
+ themeDebugLog() << "<> Widget themes initialized.";
}
}
-std::vector<ITheme *> ThemeManager::getValidApplicationThemes()
+QList<ITheme*> ThemeManager::getValidApplicationThemes()
{
- std::vector<ITheme *> ret;
- auto iter = m_themes.cbegin();
- while (iter != m_themes.cend())
- {
- ret.push_back((*iter).second.get());
- iter++;
+ QList<ITheme*> ret;
+ ret.reserve(m_themes.size());
+ for (auto&& [id, theme] : m_themes) {
+ ret.append(theme.get());
}
return ret;
}
@@ -133,7 +134,8 @@ void ThemeManager::setApplicationTheme(const QString& name, bool initial) auto themeIter = m_themes.find(name);
if(themeIter != m_themes.end())
{
- auto & theme = (*themeIter).second;
+ auto & theme = themeIter->second;
+ themeDebugLog() << "applying theme" << theme->name();
theme->apply(initial);
#ifdef Q_OS_WIN
if (m_mainWindow && IsWindows10OrGreater()) {
@@ -147,6 +149,6 @@ void ThemeManager::setApplicationTheme(const QString& name, bool initial) }
else
{
- qWarning() << "Tried to set invalid theme:" << name;
+ themeWarningLog() << "Tried to set invalid theme:" << name;
}
}
diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index fa6ea236..871e6fe2 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -15,21 +15,28 @@ * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#pragma once
#include <QString>
#include "ui/themes/ITheme.h"
#include "ui/MainWindow.h"
-#define themeDebugLog qDebug() << "[Themes]"
-#define themeWarningLog qWarning() << "[Themes]"
+inline auto themeDebugLog() {
+ return qDebug() << "[Theme]";
+}
+inline auto themeWarningLog() {
+ return qWarning() << "[Theme]";
+}
class ThemeManager {
public:
ThemeManager(MainWindow* mainWindow);
+
+ // maybe make private? Or put in ctor?
void InitializeThemes();
- std::vector<ITheme *> getValidApplicationThemes();
+ QList<ITheme*> getValidApplicationThemes();
void setIconTheme(const QString& name);
void applyCurrentlySelectedTheme();
void setApplicationTheme(const QString& name, bool initial);
@@ -38,7 +45,7 @@ private: std::map<QString, std::unique_ptr<ITheme>> m_themes;
MainWindow* m_mainWindow;
- QString AddTheme(ITheme * theme);
+ QString AddTheme(std::unique_ptr<ITheme> theme);
ITheme* GetTheme(QString themeId);
};
|