GUI: Use theme in whole program
This commit is contained in:
parent
4986b02566
commit
70e0c66c35
|
@ -29,6 +29,7 @@ CodeEditorStyle::CodeEditorStyle(
|
||||||
const QColor& CmtFGColor, const QFont::Weight& CmtWeight,
|
const QColor& CmtFGColor, const QFont::Weight& CmtWeight,
|
||||||
const QColor& SymbFGColor, const QColor& SymbBGColor,
|
const QColor& SymbFGColor, const QColor& SymbBGColor,
|
||||||
const QFont::Weight& SymbWeight) :
|
const QFont::Weight& SymbWeight) :
|
||||||
|
mSystemTheme(false),
|
||||||
widgetFGColor(CtrlFGColor),
|
widgetFGColor(CtrlFGColor),
|
||||||
widgetBGColor(CtrlBGColor),
|
widgetBGColor(CtrlBGColor),
|
||||||
highlightBGColor(HiLiBGColor),
|
highlightBGColor(HiLiBGColor),
|
||||||
|
@ -49,6 +50,7 @@ CodeEditorStyle::CodeEditorStyle(
|
||||||
|
|
||||||
bool CodeEditorStyle::operator==(const CodeEditorStyle& rhs) const
|
bool CodeEditorStyle::operator==(const CodeEditorStyle& rhs) const
|
||||||
{
|
{
|
||||||
|
if (mSystemTheme != rhs.mSystemTheme) return false;
|
||||||
if (widgetFGColor != rhs.widgetFGColor) return false;
|
if (widgetFGColor != rhs.widgetFGColor) return false;
|
||||||
if (widgetBGColor != rhs.widgetBGColor) return false;
|
if (widgetBGColor != rhs.widgetBGColor) return false;
|
||||||
if (highlightBGColor != rhs.highlightBGColor) return false;
|
if (highlightBGColor != rhs.highlightBGColor) return false;
|
||||||
|
@ -73,10 +75,18 @@ bool CodeEditorStyle::operator!=(const CodeEditorStyle& rhs) const
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeEditorStyle CodeEditorStyle::loadSettings(QSettings *settings)
|
CodeEditorStyle CodeEditorStyle::getSystemTheme()
|
||||||
{
|
{
|
||||||
CodeEditorStyle theStyle(defaultStyleLight);
|
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))
|
if (!settings->childGroups().contains(SETTINGS_STYLE_GROUP))
|
||||||
return theStyle;
|
return theStyle;
|
||||||
|
@ -153,10 +163,13 @@ CodeEditorStyle CodeEditorStyle::loadSettings(QSettings *settings)
|
||||||
void CodeEditorStyle::saveSettings(QSettings *settings,
|
void CodeEditorStyle::saveSettings(QSettings *settings,
|
||||||
const CodeEditorStyle& theStyle)
|
const CodeEditorStyle& theStyle)
|
||||||
{
|
{
|
||||||
if (!settings) return;
|
if (!settings)
|
||||||
|
return;
|
||||||
|
|
||||||
if (settings->childGroups().contains(SETTINGS_STYLE_GROUP)) {
|
if (settings->childGroups().contains(SETTINGS_STYLE_GROUP)) {
|
||||||
settings->remove(SETTINGS_STYLE_GROUP);
|
settings->remove(SETTINGS_STYLE_GROUP);
|
||||||
|
if (theStyle.isSystemTheme())
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
settings->beginGroup(SETTINGS_STYLE_GROUP);
|
settings->beginGroup(SETTINGS_STYLE_GROUP);
|
||||||
|
@ -206,3 +219,18 @@ void CodeEditorStyle::saveSettings(QSettings *settings,
|
||||||
}
|
}
|
||||||
settings->endGroup();
|
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));
|
||||||
|
}
|
||||||
|
|
|
@ -64,10 +64,18 @@ public:
|
||||||
bool operator==(const CodeEditorStyle& rhs) const;
|
bool operator==(const CodeEditorStyle& rhs) const;
|
||||||
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 CodeEditorStyle loadSettings(QSettings *settings);
|
||||||
static void saveSettings(QSettings *settings, const CodeEditorStyle& theStyle);
|
static void saveSettings(QSettings *settings, const CodeEditorStyle& theStyle);
|
||||||
|
|
||||||
|
QString generateStyleString() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
bool mSystemTheme;
|
||||||
QColor widgetFGColor;
|
QColor widgetFGColor;
|
||||||
QColor widgetBGColor;
|
QColor widgetBGColor;
|
||||||
QColor highlightBGColor;
|
QColor highlightBGColor;
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "applicationlist.h"
|
#include "applicationlist.h"
|
||||||
#include "aboutdialog.h"
|
#include "aboutdialog.h"
|
||||||
|
#include "codeeditorstyle.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "threadhandler.h"
|
#include "threadhandler.h"
|
||||||
#include "fileviewdialog.h"
|
#include "fileviewdialog.h"
|
||||||
|
@ -154,6 +155,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
|
updateStyleSetting();
|
||||||
|
|
||||||
mThread->initialize(mUI.mResults);
|
mThread->initialize(mUI.mResults);
|
||||||
if (mProjectFile)
|
if (mProjectFile)
|
||||||
formatAndSetTitle(tr("Project:") + ' ' + mProjectFile->getFilename());
|
formatAndSetTitle(tr("Project:") + ' ' + mProjectFile->getFilename());
|
||||||
|
@ -398,6 +401,16 @@ void MainWindow::saveSettings() const
|
||||||
mUI.mResults->saveSettings(mSettings);
|
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)
|
void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, const bool checkConfiguration)
|
||||||
{
|
{
|
||||||
clearResults();
|
clearResults();
|
||||||
|
@ -1010,7 +1023,7 @@ void MainWindow::programSettings()
|
||||||
dialog.showNoErrorsMessage(),
|
dialog.showNoErrorsMessage(),
|
||||||
dialog.showErrorId(),
|
dialog.showErrorId(),
|
||||||
dialog.showInconclusive());
|
dialog.showInconclusive());
|
||||||
mUI.mResults->updateStyleSetting(mSettings);
|
this->updateStyleSetting();
|
||||||
const QString newLang = mSettings->value(SETTINGS_LANGUAGE, "en").toString();
|
const QString newLang = mSettings->value(SETTINGS_LANGUAGE, "en").toString();
|
||||||
setLanguage(newLang);
|
setLanguage(newLang);
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,6 +227,9 @@ protected slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/** Set widget themes */
|
||||||
|
void updateStyleSetting();
|
||||||
|
|
||||||
/** Get filename for last results */
|
/** Get filename for last results */
|
||||||
QString getLastResults() const;
|
QString getLastResults() const;
|
||||||
|
|
||||||
|
|
|
@ -244,6 +244,9 @@ void ResultsView::updateStyleSetting(QSettings *settings)
|
||||||
{
|
{
|
||||||
CodeEditorStyle theStyle(CodeEditorStyle::loadSettings(settings));
|
CodeEditorStyle theStyle(CodeEditorStyle::loadSettings(settings));
|
||||||
mUI.mCode->setStyle(theStyle);
|
mUI.mCode->setStyle(theStyle);
|
||||||
|
QString styleString(theStyle.generateStyleString());
|
||||||
|
mUI.mTree->setStyleSheet(styleString);
|
||||||
|
mUI.mDetails->setStyleSheet(styleString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResultsView::setCheckDirectory(const QString &dir)
|
void ResultsView::setCheckDirectory(const QString &dir)
|
||||||
|
|
|
@ -420,26 +420,33 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="mTabEditorStyle">
|
<widget class="QWidget" name="mTabTheme">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Code Editor</string>
|
<string>Theme</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_11">
|
<layout class="QVBoxLayout" name="verticalLayout_11">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="gboxEditorStyle">
|
<widget class="QGroupBox" name="gboxEditorStyle">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Code Editor Style</string>
|
<string>Style</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_12">
|
<layout class="QVBoxLayout" name="verticalLayout_12">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QRadioButton" name="choiceLight">
|
<widget class="QRadioButton" name="mThemeSystem">
|
||||||
|
<property name="text">
|
||||||
|
<string>System Style</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="mThemeLight">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Default Light Style</string>
|
<string>Default Light Style</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QRadioButton" name="choiceDark">
|
<widget class="QRadioButton" name="mThemeDark">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Default Dark Style</string>
|
<string>Default Dark Style</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -448,14 +455,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="hlEditCustom">
|
<layout class="QHBoxLayout" name="hlEditCustom">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QRadioButton" name="choiceCustom">
|
<widget class="QRadioButton" name="mThemeCustom">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Custom</string>
|
<string>Custom</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnEditCustom">
|
<widget class="QPushButton" name="mBtnEditTheme">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Edit...</string>
|
<string>Edit...</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -84,10 +84,11 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
|
||||||
|
|
||||||
connect(mUI.mBtnBrowsePythonPath, &QPushButton::clicked, this, &SettingsDialog::browsePythonPath);
|
connect(mUI.mBtnBrowsePythonPath, &QPushButton::clicked, this, &SettingsDialog::browsePythonPath);
|
||||||
connect(mUI.mBtnBrowseMisraFile, &QPushButton::clicked, this, &SettingsDialog::browseMisraFile);
|
connect(mUI.mBtnBrowseMisraFile, &QPushButton::clicked, this, &SettingsDialog::browseMisraFile);
|
||||||
connect(mUI.btnEditCustom, SIGNAL(clicked()), this, SLOT(editCodeEditorStyle()));
|
connect(mUI.mBtnEditTheme, SIGNAL(clicked()), this, SLOT(editCodeEditorStyle()));
|
||||||
connect(mUI.choiceLight, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
|
connect(mUI.mThemeSystem, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
|
||||||
connect(mUI.choiceDark, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
|
connect(mUI.mThemeDark, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
|
||||||
connect(mUI.choiceCustom, SIGNAL(toggled(bool)), mUI.btnEditCustom, SLOT(setEnabled(bool)));
|
connect(mUI.mThemeLight, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
|
||||||
|
connect(mUI.mThemeCustom, SIGNAL(toggled(bool)), mUI.mBtnEditTheme, SLOT(setEnabled(bool)));
|
||||||
|
|
||||||
mUI.mListWidget->setSortingEnabled(false);
|
mUI.mListWidget->setSortingEnabled(false);
|
||||||
populateApplicationList();
|
populateApplicationList();
|
||||||
|
@ -185,7 +186,6 @@ void SettingsDialog::saveSettingValues() const
|
||||||
settings.setValue(SETTINGS_LANGUAGE, langcode);
|
settings.setValue(SETTINGS_LANGUAGE, langcode);
|
||||||
}
|
}
|
||||||
CodeEditorStyle::saveSettings(&settings, *mCurrentStyle);
|
CodeEditorStyle::saveSettings(&settings, *mCurrentStyle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::saveCheckboxValue(QSettings *settings, QCheckBox *box,
|
void SettingsDialog::saveCheckboxValue(QSettings *settings, QCheckBox *box,
|
||||||
|
@ -330,8 +330,12 @@ void SettingsDialog::browseMisraFile()
|
||||||
// Slot to set default light style
|
// Slot to set default light style
|
||||||
void SettingsDialog::setCodeEditorStyleDefault()
|
void SettingsDialog::setCodeEditorStyleDefault()
|
||||||
{
|
{
|
||||||
if (mUI.choiceLight->isChecked()) *mCurrentStyle = defaultStyleLight;
|
if (mUI.mThemeSystem->isChecked())
|
||||||
if (mUI.choiceDark->isChecked()) *mCurrentStyle = defaultStyleDark;
|
*mCurrentStyle = CodeEditorStyle::getSystemTheme();
|
||||||
|
if (mUI.mThemeLight->isChecked())
|
||||||
|
*mCurrentStyle = defaultStyleLight;
|
||||||
|
if (mUI.mThemeDark->isChecked())
|
||||||
|
*mCurrentStyle = defaultStyleDark;
|
||||||
manageStyleControls();
|
manageStyleControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,11 +363,13 @@ void SettingsDialog::browseClangPath()
|
||||||
|
|
||||||
void SettingsDialog::manageStyleControls()
|
void SettingsDialog::manageStyleControls()
|
||||||
{
|
{
|
||||||
bool isDefaultLight = *mCurrentStyle == defaultStyleLight;
|
bool isSystemTheme = mCurrentStyle->isSystemTheme();
|
||||||
bool isDefaultDark = *mCurrentStyle == defaultStyleDark;
|
bool isDefaultLight = !isSystemTheme && *mCurrentStyle == defaultStyleLight;
|
||||||
mUI.choiceLight->setChecked(isDefaultLight && !isDefaultDark);
|
bool isDefaultDark = !isSystemTheme && *mCurrentStyle == defaultStyleDark;
|
||||||
mUI.choiceDark->setChecked(!isDefaultLight && isDefaultDark);
|
mUI.mThemeSystem->setChecked(isSystemTheme);
|
||||||
mUI.choiceCustom->setChecked(!isDefaultLight && !isDefaultDark);
|
mUI.mThemeLight->setChecked(isDefaultLight && !isDefaultDark);
|
||||||
mUI.btnEditCustom->setEnabled(!isDefaultLight && !isDefaultDark);
|
mUI.mThemeDark->setChecked(!isDefaultLight && isDefaultDark);
|
||||||
|
mUI.mThemeCustom->setChecked(!isSystemTheme && !isDefaultLight && !isDefaultDark);
|
||||||
|
mUI.mBtnEditTheme->setEnabled(!isSystemTheme && !isDefaultLight && !isDefaultDark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue