add failsafe theme (#381)

This commit is contained in:
Cyano Hao 2024-04-13 09:06:13 +08:00 committed by GitHub
parent 039ec299a6
commit 3552077d5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 15 deletions

View File

@ -999,8 +999,23 @@ void MainWindow::applySettings()
themeManager.prepareCustomeTheme(); themeManager.prepareCustomeTheme();
} }
themeManager.setUseCustomTheme(pSettings->environment().useCustomTheme()); themeManager.setUseCustomTheme(pSettings->environment().useCustomTheme());
PAppTheme appTheme;
try { try {
PAppTheme appTheme = themeManager.theme(pSettings->environment().theme()); appTheme = themeManager.theme(pSettings->environment().theme());
} catch (FileError e) {
QMessageBox::critical(this,
tr("Load Theme Error"),
e.reason());
appTheme = AppTheme::fallbackTheme();
}
#ifdef ENABLE_LUA_ADDON
catch (AddOn::LuaError e) {
QMessageBox::critical(this,
tr("Load Theme Error"),
e.reason());
appTheme = AppTheme::fallbackTheme();
}
#endif
const QString& style = appTheme->style(); const QString& style = appTheme->style();
if (style == "RedPandaDarkFusion") if (style == "RedPandaDarkFusion")
QApplication::setStyle(new DarkFusionStyle());//app takes the onwership QApplication::setStyle(new DarkFusionStyle());//app takes the onwership
@ -1013,18 +1028,6 @@ void MainWindow::applySettings()
mFileEncodingStatus->setPalette(appTheme->palette()); mFileEncodingStatus->setPalette(appTheme->palette());
mFileModeStatus->setPalette(appTheme->palette()); mFileModeStatus->setPalette(appTheme->palette());
mFileInfoStatus->setPalette(appTheme->palette()); mFileInfoStatus->setPalette(appTheme->palette());
} catch (FileError e) {
QMessageBox::critical(this,
tr("Load Theme Error"),
e.reason());
}
#ifdef ENABLE_LUA_ADDON
catch (AddOn::LuaError e) {
QMessageBox::critical(this,
tr("Load Theme Error"),
e.reason());
}
#endif
updateEditorColorSchemes(); updateEditorColorSchemes();

View File

@ -119,6 +119,8 @@ QList<PAppTheme> ThemeManager::getThemes()
std::sort(result.begin(),result.end(),[](const PAppTheme &theme1, const PAppTheme &theme2){ std::sort(result.begin(),result.end(),[](const PAppTheme &theme1, const PAppTheme &theme2){
return QFileInfo(theme1->filename()).baseName() < QFileInfo(theme2->filename()).baseName(); return QFileInfo(theme1->filename()).baseName() < QFileInfo(theme2->filename()).baseName();
}); });
if (result.isEmpty())
result.append(AppTheme::fallbackTheme());
return result; return result;
} }
@ -347,3 +349,18 @@ const QString &AppTheme::style() const
{ {
return mStyle; return mStyle;
} }
AppTheme::AppTheme() :
mName("__failsafe__theme__"),
mDisplayName("Fusion [fail-safe hard-coded]"),
mStyle("fusion"),
mDefaultColorScheme("Adaptive"),
mDefaultIconSet("newlook")
{
}
PAppTheme AppTheme::fallbackTheme()
{
static PAppTheme theme = PAppTheme(new AppTheme());
return theme;
}

View File

@ -22,6 +22,9 @@
#include <memory> #include <memory>
#include <QObject> #include <QObject>
class AppTheme;
using PAppTheme = std::shared_ptr<AppTheme>;
class AppTheme : public QObject{ class AppTheme : public QObject{
Q_OBJECT Q_OBJECT
public: public:
@ -102,6 +105,12 @@ public:
const QString& filename() const; const QString& filename() const;
public:
static PAppTheme fallbackTheme();
private:
AppTheme();
private: private:
static QPalette initialPalette(); static QPalette initialPalette();
private: private:
@ -114,8 +123,6 @@ private:
QString mFilename; QString mFilename;
}; };
using PAppTheme = std::shared_ptr<AppTheme>;
class ThemeManager : public QObject class ThemeManager : public QObject
{ {
Q_OBJECT Q_OBJECT