diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index ea15177f..caafd093 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -999,32 +999,35 @@ void MainWindow::applySettings() themeManager.prepareCustomeTheme(); } themeManager.setUseCustomTheme(pSettings->environment().useCustomTheme()); + PAppTheme appTheme; try { - PAppTheme appTheme = themeManager.theme(pSettings->environment().theme()); - const QString& style = appTheme->style(); - if (style == "RedPandaDarkFusion") - QApplication::setStyle(new DarkFusionStyle());//app takes the onwership - else if (style == "RedPandaLightFusion") - QApplication::setStyle(new LightFusionStyle());//app takes the onwership - else - QApplication::setStyle(style); - qApp->setPalette(appTheme->palette()); - //fix for qstatusbar bug - mFileEncodingStatus->setPalette(appTheme->palette()); - mFileModeStatus->setPalette(appTheme->palette()); - mFileInfoStatus->setPalette(appTheme->palette()); + 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(); + if (style == "RedPandaDarkFusion") + QApplication::setStyle(new DarkFusionStyle());//app takes the onwership + else if (style == "RedPandaLightFusion") + QApplication::setStyle(new LightFusionStyle());//app takes the onwership + else + QApplication::setStyle(style); + qApp->setPalette(appTheme->palette()); + //fix for qstatusbar bug + mFileEncodingStatus->setPalette(appTheme->palette()); + mFileModeStatus->setPalette(appTheme->palette()); + mFileInfoStatus->setPalette(appTheme->palette()); updateEditorColorSchemes(); diff --git a/RedPandaIDE/thememanager.cpp b/RedPandaIDE/thememanager.cpp index baaa7c5d..22f00ce3 100644 --- a/RedPandaIDE/thememanager.cpp +++ b/RedPandaIDE/thememanager.cpp @@ -119,6 +119,8 @@ QList ThemeManager::getThemes() std::sort(result.begin(),result.end(),[](const PAppTheme &theme1, const PAppTheme &theme2){ return QFileInfo(theme1->filename()).baseName() < QFileInfo(theme2->filename()).baseName(); }); + if (result.isEmpty()) + result.append(AppTheme::fallbackTheme()); return result; } @@ -347,3 +349,18 @@ const QString &AppTheme::style() const { 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; +} diff --git a/RedPandaIDE/thememanager.h b/RedPandaIDE/thememanager.h index 41bd591a..279b5fb7 100644 --- a/RedPandaIDE/thememanager.h +++ b/RedPandaIDE/thememanager.h @@ -22,6 +22,9 @@ #include #include +class AppTheme; +using PAppTheme = std::shared_ptr; + class AppTheme : public QObject{ Q_OBJECT public: @@ -102,6 +105,12 @@ public: const QString& filename() const; +public: + static PAppTheme fallbackTheme(); + +private: + AppTheme(); + private: static QPalette initialPalette(); private: @@ -114,8 +123,6 @@ private: QString mFilename; }; -using PAppTheme = std::shared_ptr; - class ThemeManager : public QObject { Q_OBJECT