diff --git a/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp b/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp index 23446489..99477506 100644 --- a/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp +++ b/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp @@ -92,7 +92,7 @@ void EnvironmentAppearanceWidget::init() ThemeManager themeManager; QList appThemes = themeManager.getThemes(); foreach(const PAppTheme& appTheme, appThemes) { - ui->cbTheme->addItem(appTheme->displayName(),appTheme->name()); + ui->cbTheme->addItem(appTheme->categoryIcon() + " " + appTheme->displayName(), appTheme->name()); } ui->cbLanguage->addItem(tr("English"),"en"); ui->cbLanguage->addItem(tr("Portuguese"),"pt_BR"); @@ -109,7 +109,6 @@ void EnvironmentAppearanceWidget::on_cbTheme_currentIndexChanged(int /* index */ { ThemeManager themeManager; PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString()); - ui->lblThemeCategory->setText(appTheme->category()); if(!appTheme->defaultIconSet().isEmpty()) { for (int i=0; icbIconSet->count();i++) { if (ui->cbIconSet->itemData(i) == appTheme->defaultIconSet()) { diff --git a/RedPandaIDE/settingsdialog/environmentappearancewidget.ui b/RedPandaIDE/settingsdialog/environmentappearancewidget.ui index 9bf0128d..71cf07e1 100644 --- a/RedPandaIDE/settingsdialog/environmentappearancewidget.ui +++ b/RedPandaIDE/settingsdialog/environmentappearancewidget.ui @@ -135,13 +135,6 @@ - - - - theme category - - - diff --git a/RedPandaIDE/thememanager.cpp b/RedPandaIDE/thememanager.cpp index cc86de10..60168bf9 100644 --- a/RedPandaIDE/thememanager.cpp +++ b/RedPandaIDE/thememanager.cpp @@ -45,9 +45,9 @@ PAppTheme ThemeManager::theme(const QString &themeName) PAppTheme appTheme = nullptr; // custom overrides built-in - if (tryLoadThemeFromDir(customThemeDir, tr("custom"), themeName, appTheme)) + if (tryLoadThemeFromDir(customThemeDir, AppTheme::ThemeCategory::Custom, themeName, appTheme)) return appTheme; - if (tryLoadThemeFromDir(builtInThemeDir, tr("built-in"), themeName, appTheme)) + if (tryLoadThemeFromDir(builtInThemeDir, AppTheme::ThemeCategory::BuiltIn, themeName, appTheme)) return appTheme; return AppTheme::fallbackTheme(); } @@ -59,8 +59,8 @@ QList ThemeManager::getThemes() std::set themes; // custom overrides built-in - loadThemesFromDir(customThemeDir, tr("custom"), themes); - loadThemesFromDir(builtInThemeDir, tr("built-in"), themes); + loadThemesFromDir(customThemeDir, AppTheme::ThemeCategory::Custom, themes); + loadThemesFromDir(builtInThemeDir, AppTheme::ThemeCategory::BuiltIn, themes); QList result(themes.begin(), themes.end()); return result; @@ -71,18 +71,14 @@ bool ThemeManager::ThemeCompare::operator()(const PAppTheme &lhs, const PAppThem return QFileInfo(lhs->filename()).baseName() < QFileInfo(rhs->filename()).baseName(); } -bool ThemeManager::tryLoadThemeFromDir(const QString &dir, const QString &dirType, const QString &themeName, PAppTheme &theme) +bool ThemeManager::tryLoadThemeFromDir(const QString &dir, AppTheme::ThemeCategory category, const QString &themeName, PAppTheme &theme) { for (const auto &[extension, type] : searchTypes) { QString filename = QString("%2.%3").arg(themeName, extension); QString fullPath = QString("%1/%2").arg(dir, filename); if (QFile::exists(fullPath)) { try { - theme = std::make_shared(fullPath, type); - if (theme->displayName().isEmpty()) { - theme->setDisplayName(themeName); - } - theme->setCategory(QString("%1 %2").arg(dirType, filename)); + theme = std::make_shared(fullPath, type, category); return true; } catch(FileError e) { //just skip it @@ -97,7 +93,7 @@ bool ThemeManager::tryLoadThemeFromDir(const QString &dir, const QString &dirTyp return false; } -void ThemeManager::loadThemesFromDir(const QString &dir, const QString &dirType, std::set &themes) +void ThemeManager::loadThemesFromDir(const QString &dir, AppTheme::ThemeCategory category, std::set &themes) { for (const auto &[extension, type] : searchTypes) { QDirIterator it(dir); @@ -106,12 +102,7 @@ void ThemeManager::loadThemesFromDir(const QString &dir, const QString &dirType, QFileInfo fileInfo = it.fileInfo(); if (fileInfo.suffix().compare(extension, PATH_SENSITIVITY) == 0) { try { - PAppTheme appTheme = std::make_shared(fileInfo.absoluteFilePath(), type); - if (appTheme->displayName().isEmpty()) { - QString baseName = fileInfo.baseName(); - appTheme->setDisplayName(baseName); - } - appTheme->setCategory(QString("%1 %2").arg(dirType, fileInfo.fileName())); + PAppTheme appTheme = std::make_shared(fileInfo.absoluteFilePath(), type, category); themes.insert(appTheme); } catch(FileError e) { //just skip it @@ -198,9 +189,11 @@ QPalette AppTheme::palette() const return pal; } -AppTheme::AppTheme(const QString &filename, ThemeType type, QObject *parent):QObject(parent) +AppTheme::AppTheme(const QString &filename, ThemeType type, ThemeCategory category, QObject *parent):QObject(parent) { mFilename = filename; + mType = type; + mCategory = category; QFile file(filename); if (!file.exists()) { throw FileError(tr("Theme file '%1' doesn't exist!") @@ -213,6 +206,8 @@ AppTheme::AppTheme(const QString &filename, ThemeType type, QObject *parent):QOb QJsonObject obj; switch (type) { + case ThemeType::HardCoded: + __builtin_unreachable(); case ThemeType::JSON: { QJsonParseError error; QJsonDocument doc(QJsonDocument::fromJson(content, &error)); @@ -255,6 +250,8 @@ AppTheme::AppTheme(const QString &filename, ThemeType type, QObject *parent):QOb QFileInfo fileInfo(filename); mName = fileInfo.baseName(); mDisplayName = obj["name"].toString(); + if (mDisplayName.isEmpty()) + mDisplayName = mName; mStyle = obj["style"].toString(); mDefaultColorScheme = obj["default scheme"].toString(); mDefaultIconSet = obj["default iconset"].toString(); @@ -316,6 +313,22 @@ const QString &AppTheme::filename() const return mFilename; } +const QString AppTheme::categoryIcon() const +{ + switch (mCategory) { + case ThemeCategory::FailSafe: + return "❌"; + case ThemeCategory::BuiltIn: + return "📦"; + case ThemeCategory::Custom: + return "📄"; + case ThemeCategory::Shared: + return "🌐"; + default: + return ""; + } +} + const QString &AppTheme::defaultIconSet() const { return mDefaultIconSet; @@ -336,21 +349,6 @@ const QString &AppTheme::displayName() const return mDisplayName; } -void AppTheme::setDisplayName(const QString &newDisplayName) -{ - mDisplayName = newDisplayName; -} - -const QString &AppTheme::category() const -{ - return mCategory; -} - -void AppTheme::setCategory(const QString &newCategory) -{ - mCategory = newCategory; -} - const QString &AppTheme::defaultColorScheme() const { return mDefaultColorScheme; @@ -369,10 +367,11 @@ const QString &AppTheme::style() const AppTheme::AppTheme() : mName("__failsafe__theme__"), mDisplayName("Fusion"), - mCategory("fail-safe hard-coded"), mStyle("fusion"), mDefaultColorScheme("Adaptive"), - mDefaultIconSet("newlook") + mDefaultIconSet("newlook"), + mType(ThemeType::HardCoded), + mCategory(ThemeCategory::FailSafe) { } diff --git a/RedPandaIDE/thememanager.h b/RedPandaIDE/thememanager.h index bc90408e..cbdbe031 100644 --- a/RedPandaIDE/thememanager.h +++ b/RedPandaIDE/thememanager.h @@ -78,13 +78,21 @@ public: Q_ENUM(ColorRole) enum class ThemeType { + HardCoded, JSON, #ifdef ENABLE_LUA_ADDON Lua, #endif }; - AppTheme(const QString& filename, ThemeType type, QObject* parent=nullptr); + enum class ThemeCategory { + FailSafe, + BuiltIn, + Custom, + Shared, + }; + + AppTheme(const QString& filename, ThemeType type, ThemeCategory category, QObject* parent=nullptr); QColor color(ColorRole role) const; QPalette palette() const; @@ -95,10 +103,6 @@ public: void setDefaultColorScheme(const QString &newDefaultColorScheme); const QString &displayName() const; - void setDisplayName(const QString &newDisplayName); - - const QString &category() const; - void setCategory(const QString &newCategory); const QString &name() const; @@ -110,6 +114,8 @@ public: const QString& filename() const; + const QString categoryIcon() const; + public: static PAppTheme fallbackTheme(); @@ -122,11 +128,12 @@ private: QHash mColors; QString mName; QString mDisplayName; - QString mCategory; QString mStyle; QString mDefaultColorScheme; QString mDefaultIconSet; QString mFilename; + ThemeType mType; + ThemeCategory mCategory; }; class ThemeManager : public QObject @@ -143,8 +150,8 @@ private: }; private: - bool tryLoadThemeFromDir(const QString &dir, const QString &dirType, const QString &themeName, PAppTheme &theme); - void loadThemesFromDir(const QString &dir, const QString &dirType, std::set &themes); + bool tryLoadThemeFromDir(const QString &dir, AppTheme::ThemeCategory category, const QString &themeName, PAppTheme &theme); + void loadThemesFromDir(const QString &dir, AppTheme::ThemeCategory category, std::set &themes); // lua overrides json inline static const std::pair searchTypes[] = {