add failsafe theme (#381)
This commit is contained in:
parent
039ec299a6
commit
3552077d5c
|
@ -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();
|
||||
|
||||
|
|
|
@ -119,6 +119,8 @@ QList<PAppTheme> 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;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
#include <memory>
|
||||
#include <QObject>
|
||||
|
||||
class AppTheme;
|
||||
using PAppTheme = std::shared_ptr<AppTheme>;
|
||||
|
||||
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<AppTheme>;
|
||||
|
||||
class ThemeManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Reference in New Issue