From 6daa45783894fc7517917d6f6df0deaac1a41ba3 Mon Sep 17 00:00:00 2001 From: Tayou Date: Mon, 9 Jan 2023 16:58:27 +0100 Subject: Implement Suggestions from flow & Scrumplex Signed-off-by: Tayou --- launcher/ui/themes/ThemeManager.cpp | 35 ++++++++++++++++++++++++++--------- launcher/ui/themes/ThemeManager.h | 9 +++++---- 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'launcher/ui/themes') diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index a6cebc6f..44c13f40 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -31,13 +31,13 @@ ThemeManager::ThemeManager(MainWindow* mainWindow) { m_mainWindow = mainWindow; - InitializeThemes(); + initializeThemes(); } /// @brief Adds the Theme to the list of themes /// @param theme The Theme to add /// @return Theme ID -QString ThemeManager::AddTheme(std::unique_ptr theme) +QString ThemeManager::addTheme(std::unique_ptr theme) { QString id = theme->id(); m_themes.emplace(id, std::move(theme)); @@ -47,12 +47,12 @@ QString ThemeManager::AddTheme(std::unique_ptr theme) /// @brief Gets the Theme from the List via ID /// @param themeId Theme ID of theme to fetch /// @return Theme at themeId -ITheme* ThemeManager::GetTheme(QString themeId) +ITheme* ThemeManager::getTheme(QString themeId) { return m_themes[themeId].get(); } -void ThemeManager::InitializeThemes() +void ThemeManager::initializeThemes() { // Icon themes { @@ -67,10 +67,10 @@ void ThemeManager::InitializeThemes() // Initialize widget themes { themeDebugLog() << "<> Initializing Widget Themes"; - themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique()); - auto darkThemeId = AddTheme(std::make_unique()); + themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); + auto darkThemeId = addTheme(std::make_unique()); themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; - themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique()); + themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in // dropdown?) @@ -84,7 +84,7 @@ void ThemeManager::InitializeThemes() if (themeJson.exists()) { // Load "theme.json" based themes themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath(); - AddTheme(std::make_unique(GetTheme(darkThemeId), themeJson, true)); + addTheme(std::make_unique(getTheme(darkThemeId), themeJson, true)); } else { // Load pure QSS Themes QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files); @@ -92,7 +92,7 @@ void ThemeManager::InitializeThemes() QFile customThemeFile(stylesheetFileIterator.next()); QFileInfo customThemeFileInfo(customThemeFile); themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath(); - AddTheme(std::make_unique(GetTheme(darkThemeId), customThemeFileInfo, false)); + addTheme(std::make_unique(getTheme(darkThemeId), customThemeFileInfo, false)); } } } @@ -136,3 +136,20 @@ void ThemeManager::setApplicationTheme(const QString& name) themeWarningLog() << "Tried to set invalid theme:" << name; } } + +QString ThemeManager::getCatImage(QString catName) +{ + QDateTime now = QDateTime::currentDateTime(); + QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0)); + QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0)); + QDateTime halloween(QDate(now.date().year(), 10, 31), QTime(0, 0)); + QString cat = catName == "" ? APPLICATION->settings()->get("BackgroundCat").toString() : catName; + if (std::abs(now.daysTo(xmas)) <= 4) { + cat += "-xmas"; + } else if (std::abs(now.daysTo(halloween)) <= 4) { + cat += "-spooky"; + } else if (std::abs(now.daysTo(birthday)) <= 12) { + cat += "-bday"; + } + return cat; +} \ No newline at end of file diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index bb10cd48..4f36bffa 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -40,12 +40,13 @@ class ThemeManager { void applyCurrentlySelectedTheme(); void setApplicationTheme(const QString& name); + static QString getCatImage(QString catName = ""); + private: std::map> m_themes; MainWindow* m_mainWindow; - bool m_firstThemeInitialized; - void InitializeThemes(); - QString AddTheme(std::unique_ptr theme); - ITheme* GetTheme(QString themeId); + void initializeThemes(); + QString addTheme(std::unique_ptr theme); + ITheme* getTheme(QString themeId); }; -- cgit