diff --git a/gui/codeeditorstyle.cpp b/gui/codeeditorstyle.cpp index 52edec392..414c50356 100644 --- a/gui/codeeditorstyle.cpp +++ b/gui/codeeditorstyle.cpp @@ -29,6 +29,7 @@ CodeEditorStyle::CodeEditorStyle( const QColor& CmtFGColor, const QFont::Weight& CmtWeight, const QColor& SymbFGColor, const QColor& SymbBGColor, const QFont::Weight& SymbWeight) : + mSystemTheme(false), widgetFGColor(CtrlFGColor), widgetBGColor(CtrlBGColor), highlightBGColor(HiLiBGColor), @@ -49,6 +50,7 @@ CodeEditorStyle::CodeEditorStyle( bool CodeEditorStyle::operator==(const CodeEditorStyle& rhs) const { + if (mSystemTheme != rhs.mSystemTheme) return false; if (widgetFGColor != rhs.widgetFGColor) return false; if (widgetBGColor != rhs.widgetBGColor) return false; if (highlightBGColor != rhs.highlightBGColor) return false; @@ -73,10 +75,18 @@ bool CodeEditorStyle::operator!=(const CodeEditorStyle& rhs) const return !(*this == rhs); } -CodeEditorStyle CodeEditorStyle::loadSettings(QSettings *settings) +CodeEditorStyle CodeEditorStyle::getSystemTheme() { CodeEditorStyle theStyle(defaultStyleLight); - if (!settings) return theStyle; + theStyle.mSystemTheme = true; + return theStyle; +} + +CodeEditorStyle CodeEditorStyle::loadSettings(QSettings *settings) +{ + CodeEditorStyle theStyle(CodeEditorStyle::getSystemTheme()); + if (!settings) + return theStyle; if (!settings->childGroups().contains(SETTINGS_STYLE_GROUP)) return theStyle; @@ -153,10 +163,13 @@ CodeEditorStyle CodeEditorStyle::loadSettings(QSettings *settings) void CodeEditorStyle::saveSettings(QSettings *settings, const CodeEditorStyle& theStyle) { - if (!settings) return; + if (!settings) + return; if (settings->childGroups().contains(SETTINGS_STYLE_GROUP)) { settings->remove(SETTINGS_STYLE_GROUP); + if (theStyle.isSystemTheme()) + return; } settings->beginGroup(SETTINGS_STYLE_GROUP); @@ -206,3 +219,18 @@ void CodeEditorStyle::saveSettings(QSettings *settings, } settings->endGroup(); } + +static QString rgbStyleString(QColor c) +{ + return QString("rgb(%1,%2,%3)").arg(c.red()).arg(c.green()).arg(c.blue()); +} + +QString CodeEditorStyle::generateStyleString() const +{ + if (isSystemTheme()) + return QString(); + return QString("background:%1; color:%2; selection-background-color:%3;") + .arg(rgbStyleString(widgetBGColor)) + .arg(rgbStyleString(widgetFGColor)) + .arg(rgbStyleString(highlightBGColor)); +} diff --git a/gui/codeeditorstyle.h b/gui/codeeditorstyle.h index d9e1d4761..2559d0aff 100644 --- a/gui/codeeditorstyle.h +++ b/gui/codeeditorstyle.h @@ -64,10 +64,18 @@ public: bool operator==(const CodeEditorStyle& rhs) const; bool operator!=(const CodeEditorStyle& rhs) const; + bool isSystemTheme() const { + return mSystemTheme; + } + + static CodeEditorStyle getSystemTheme(); static CodeEditorStyle loadSettings(QSettings *settings); static void saveSettings(QSettings *settings, const CodeEditorStyle& theStyle); + QString generateStyleString() const; + public: + bool mSystemTheme; QColor widgetFGColor; QColor widgetBGColor; QColor highlightBGColor; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 45cb34002..4c1abf91a 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -33,6 +33,7 @@ #include "applicationlist.h" #include "aboutdialog.h" +#include "codeeditorstyle.h" #include "common.h" #include "threadhandler.h" #include "fileviewdialog.h" @@ -154,6 +155,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : loadSettings(); + updateStyleSetting(); + mThread->initialize(mUI.mResults); if (mProjectFile) formatAndSetTitle(tr("Project:") + ' ' + mProjectFile->getFilename()); @@ -398,6 +401,16 @@ void MainWindow::saveSettings() const mUI.mResults->saveSettings(mSettings); } +void MainWindow::updateStyleSetting() +{ + mUI.mResults->updateStyleSetting(mSettings); + QString styleSheet = CodeEditorStyle::loadSettings(mSettings).generateStyleString(); + mUI.mToolBarMain->setStyleSheet(styleSheet); + mUI.mToolBarView->setStyleSheet(styleSheet); + mUI.mToolBarFilter->setStyleSheet(styleSheet); + this->setStyleSheet(styleSheet); +} + void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, const bool checkConfiguration) { clearResults(); @@ -1010,7 +1023,7 @@ void MainWindow::programSettings() dialog.showNoErrorsMessage(), dialog.showErrorId(), dialog.showInconclusive()); - mUI.mResults->updateStyleSetting(mSettings); + this->updateStyleSetting(); const QString newLang = mSettings->value(SETTINGS_LANGUAGE, "en").toString(); setLanguage(newLang); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 6812b17c8..041bb5412 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -227,6 +227,9 @@ protected slots: private: + /** Set widget themes */ + void updateStyleSetting(); + /** Get filename for last results */ QString getLastResults() const; diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 0bd9b8a57..e9e10a981 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -244,6 +244,9 @@ void ResultsView::updateStyleSetting(QSettings *settings) { CodeEditorStyle theStyle(CodeEditorStyle::loadSettings(settings)); mUI.mCode->setStyle(theStyle); + QString styleString(theStyle.generateStyleString()); + mUI.mTree->setStyleSheet(styleString); + mUI.mDetails->setStyleSheet(styleString); } void ResultsView::setCheckDirectory(const QString &dir) diff --git a/gui/settings.ui b/gui/settings.ui index e6e9abcfa..a480276ca 100644 --- a/gui/settings.ui +++ b/gui/settings.ui @@ -420,26 +420,33 @@ - + - Code Editor + Theme - Code Editor Style + Style - + + + System Style + + + + + Default Light Style - + Default Dark Style @@ -448,14 +455,14 @@ - + Custom - + Edit... diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 9c9f381e9..04c637816 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -84,10 +84,11 @@ SettingsDialog::SettingsDialog(ApplicationList *list, connect(mUI.mBtnBrowsePythonPath, &QPushButton::clicked, this, &SettingsDialog::browsePythonPath); connect(mUI.mBtnBrowseMisraFile, &QPushButton::clicked, this, &SettingsDialog::browseMisraFile); - connect(mUI.btnEditCustom, SIGNAL(clicked()), this, SLOT(editCodeEditorStyle())); - connect(mUI.choiceLight, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault())); - connect(mUI.choiceDark, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault())); - connect(mUI.choiceCustom, SIGNAL(toggled(bool)), mUI.btnEditCustom, SLOT(setEnabled(bool))); + connect(mUI.mBtnEditTheme, SIGNAL(clicked()), this, SLOT(editCodeEditorStyle())); + connect(mUI.mThemeSystem, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault())); + connect(mUI.mThemeDark, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault())); + connect(mUI.mThemeLight, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault())); + connect(mUI.mThemeCustom, SIGNAL(toggled(bool)), mUI.mBtnEditTheme, SLOT(setEnabled(bool))); mUI.mListWidget->setSortingEnabled(false); populateApplicationList(); @@ -185,7 +186,6 @@ void SettingsDialog::saveSettingValues() const settings.setValue(SETTINGS_LANGUAGE, langcode); } CodeEditorStyle::saveSettings(&settings, *mCurrentStyle); - } void SettingsDialog::saveCheckboxValue(QSettings *settings, QCheckBox *box, @@ -330,8 +330,12 @@ void SettingsDialog::browseMisraFile() // Slot to set default light style void SettingsDialog::setCodeEditorStyleDefault() { - if (mUI.choiceLight->isChecked()) *mCurrentStyle = defaultStyleLight; - if (mUI.choiceDark->isChecked()) *mCurrentStyle = defaultStyleDark; + if (mUI.mThemeSystem->isChecked()) + *mCurrentStyle = CodeEditorStyle::getSystemTheme(); + if (mUI.mThemeLight->isChecked()) + *mCurrentStyle = defaultStyleLight; + if (mUI.mThemeDark->isChecked()) + *mCurrentStyle = defaultStyleDark; manageStyleControls(); } @@ -359,11 +363,13 @@ void SettingsDialog::browseClangPath() void SettingsDialog::manageStyleControls() { - bool isDefaultLight = *mCurrentStyle == defaultStyleLight; - bool isDefaultDark = *mCurrentStyle == defaultStyleDark; - mUI.choiceLight->setChecked(isDefaultLight && !isDefaultDark); - mUI.choiceDark->setChecked(!isDefaultLight && isDefaultDark); - mUI.choiceCustom->setChecked(!isDefaultLight && !isDefaultDark); - mUI.btnEditCustom->setEnabled(!isDefaultLight && !isDefaultDark); + bool isSystemTheme = mCurrentStyle->isSystemTheme(); + bool isDefaultLight = !isSystemTheme && *mCurrentStyle == defaultStyleLight; + bool isDefaultDark = !isSystemTheme && *mCurrentStyle == defaultStyleDark; + mUI.mThemeSystem->setChecked(isSystemTheme); + mUI.mThemeLight->setChecked(isDefaultLight && !isDefaultDark); + mUI.mThemeDark->setChecked(!isDefaultLight && isDefaultDark); + mUI.mThemeCustom->setChecked(!isSystemTheme && !isDefaultLight && !isDefaultDark); + mUI.mBtnEditTheme->setEnabled(!isSystemTheme && !isDefaultLight && !isDefaultDark); }