Implement Suggestions from flow & Scrumplex

Signed-off-by: Tayou <tayou@gmx.net>
This commit is contained in:
Tayou
2023-01-09 16:58:27 +01:00
parent 49d317b19a
commit 6daa457838
9 changed files with 97 additions and 171 deletions

View File

@ -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<ITheme> theme)
QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
{
QString id = theme->id();
m_themes.emplace(id, std::move(theme));
@ -47,12 +47,12 @@ QString ThemeManager::AddTheme(std::unique_ptr<ITheme> 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<SystemTheme>());
auto darkThemeId = AddTheme(std::make_unique<DarkTheme>());
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>());
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?)
@ -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<CustomTheme>(GetTheme(darkThemeId), themeJson, true));
addTheme(std::make_unique<CustomTheme>(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<CustomTheme>(GetTheme(darkThemeId), customThemeFileInfo, false));
addTheme(std::make_unique<CustomTheme>(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;
}

View File

@ -40,12 +40,13 @@ class ThemeManager {
void applyCurrentlySelectedTheme();
void setApplicationTheme(const QString& name);
static QString getCatImage(QString catName = "");
private:
std::map<QString, std::unique_ptr<ITheme>> m_themes;
MainWindow* m_mainWindow;
bool m_firstThemeInitialized;
void InitializeThemes();
QString AddTheme(std::unique_ptr<ITheme> theme);
ITheme* GetTheme(QString themeId);
void initializeThemes();
QString addTheme(std::unique_ptr<ITheme> theme);
ITheme* getTheme(QString themeId);
};