mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Update preference colours when the application style is changed
In order to have matching colours in all the preferences, the individual
colour settings in Data Browser and SQL tabs are reset to default values
matching the corresponding style setting (dark stylesheet or follow desktop,
which could be dark or light as always).
Additionally, several problems with colour settings in QScintilla have
been fixed:
- We don't use indentation guides
- both sets of lexer colour settings must be used, otherwise the result is
inconsistant and unpredictable:
* lexer->setDefaultColor|Paper and lexer->setColor|Paper
This commit is contained in:
@@ -125,11 +125,18 @@ void ExtendedScintilla::setLexer(QsciLexer *lexer)
|
||||
{
|
||||
QsciScintilla::setLexer(lexer);
|
||||
|
||||
// Set margins to system window theme. setLexer seems to reset these colours.
|
||||
setMarginsBackgroundColor(QPalette().color(QPalette::Active, QPalette::Window));
|
||||
setMarginsForegroundColor(QPalette().color(QPalette::Active, QPalette::WindowText));
|
||||
setIndentationGuidesBackgroundColor(QPalette().color(QPalette::Active, QPalette::Window));
|
||||
setIndentationGuidesForegroundColor(QPalette().color(QPalette::Active, QPalette::WindowText));
|
||||
// Set margins according to settings. setLexer seems to reset these colours.
|
||||
// Use desktop default colors for margins when following desktop style, or the custom colors otherwise.
|
||||
switch (Settings::getValue("General", "appStyle").toInt()) {
|
||||
case Settings::FollowDesktopStyle :
|
||||
setMarginsBackgroundColor(QPalette().color(QPalette::Active, QPalette::Window));
|
||||
setMarginsForegroundColor(QPalette().color(QPalette::Active, QPalette::WindowText));
|
||||
break;
|
||||
case Settings::DarkStyle :
|
||||
setMarginsBackgroundColor(QColor(Settings::getValue("syntaxhighlighter","background_colour").toString()));
|
||||
setMarginsForegroundColor(QColor(Settings::getValue("syntaxhighlighter","foreground_colour").toString()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ExtendedScintilla::reloadKeywords()
|
||||
@@ -145,33 +152,38 @@ void ExtendedScintilla::reloadSettings()
|
||||
}
|
||||
void ExtendedScintilla::reloadLexerSettings(QsciLexer *lexer)
|
||||
{
|
||||
QColor foreground (Settings::getValue("syntaxhighlighter", "foreground_colour").toString());
|
||||
QColor background (Settings::getValue("syntaxhighlighter", "background_colour").toString());
|
||||
|
||||
QFont defaultfont(Settings::getValue("editor", "font").toString());
|
||||
defaultfont.setStyleHint(QFont::TypeWriter);
|
||||
defaultfont.setPointSize(Settings::getValue("editor", "fontsize").toInt());
|
||||
|
||||
// Set syntax highlighting settings
|
||||
if(lexer)
|
||||
{
|
||||
QFont defaultfont(Settings::getValue("editor", "font").toString());
|
||||
defaultfont.setStyleHint(QFont::TypeWriter);
|
||||
defaultfont.setPointSize(Settings::getValue("editor", "fontsize").toInt());
|
||||
lexer->setFont(defaultfont);
|
||||
|
||||
lexer->setDefaultColor(QColor(Settings::getValue("syntaxhighlighter", "foreground_colour").toString()));
|
||||
lexer->setPaper(QColor(Settings::getValue("syntaxhighlighter", "background_colour").toString()));
|
||||
lexer->setDefaultPaper(background);
|
||||
lexer->setDefaultColor(foreground);
|
||||
|
||||
// This sets the base colors for all the styles
|
||||
lexer->setPaper(background);
|
||||
lexer->setColor(foreground);
|
||||
}
|
||||
|
||||
// Set font
|
||||
QFont font(Settings::getValue("editor", "font").toString());
|
||||
font.setStyleHint(QFont::TypeWriter);
|
||||
font.setPointSize(Settings::getValue("editor", "fontsize").toInt());
|
||||
setFont(font);
|
||||
setFont(defaultfont);
|
||||
|
||||
// Show line numbers
|
||||
setMarginsFont(font);
|
||||
setMarginsFont(defaultfont);
|
||||
setMarginLineNumbers(0, true);
|
||||
updateLineNumberAreaWidth();
|
||||
|
||||
// Highlight current line
|
||||
setCaretLineVisible(true);
|
||||
setCaretLineBackgroundColor(QColor(Settings::getValue("syntaxhighlighter", "currentline_colour").toString()));
|
||||
setCaretForegroundColor(QColor(Settings::getValue("syntaxhighlighter", "foreground_colour").toString()));
|
||||
setCaretForegroundColor(foreground);
|
||||
|
||||
// Set tab width
|
||||
setTabWidth(Settings::getValue("editor", "tabsize").toInt());
|
||||
|
||||
@@ -41,6 +41,8 @@ PreferencesDialog::PreferencesDialog(QWidget* parent, Tabs tab)
|
||||
|
||||
loadSettings();
|
||||
|
||||
connect(ui->appStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(adjustColorsToStyle(int)));
|
||||
|
||||
// Avoid different heights due to having check boxes or not
|
||||
ui->treeSyntaxHighlighting->setUniformRowHeights(true);
|
||||
|
||||
@@ -523,6 +525,26 @@ void PreferencesDialog::saveColorSetting(QFrame *frame, const QString & settingN
|
||||
frame->palette().color(frame->backgroundRole()));
|
||||
}
|
||||
|
||||
void PreferencesDialog::adjustColorsToStyle(int style)
|
||||
{
|
||||
Settings::AppStyle appStyle = static_cast<Settings::AppStyle>(style);
|
||||
setColorSetting(ui->fr_null_fg, Settings::getDefaultColorValue("databrowser", "null_fg_colour", appStyle));
|
||||
setColorSetting(ui->fr_null_bg, Settings::getDefaultColorValue("databrowser", "null_bg_colour", appStyle));
|
||||
setColorSetting(ui->fr_bin_fg, Settings::getDefaultColorValue("databrowser", "bin_fg_colour", appStyle));
|
||||
setColorSetting(ui->fr_bin_bg, Settings::getDefaultColorValue("databrowser", "bin_bg_colour", appStyle));
|
||||
setColorSetting(ui->fr_reg_fg, Settings::getDefaultColorValue("databrowser", "reg_fg_colour", appStyle));
|
||||
setColorSetting(ui->fr_reg_bg, Settings::getDefaultColorValue("databrowser", "reg_bg_colour", appStyle));
|
||||
|
||||
for(int i=0; i < ui->treeSyntaxHighlighting->topLevelItemCount(); ++i)
|
||||
{
|
||||
QString name = ui->treeSyntaxHighlighting->topLevelItem(i)->text(0);
|
||||
QColor color = Settings::getDefaultColorValue("syntaxhighlighter", name + "_colour", appStyle);
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setTextColor(2, color);
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setBackgroundColor(2, color);
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setText(2, color.name());
|
||||
}
|
||||
}
|
||||
|
||||
void PreferencesDialog::activateRemoteTab(bool active)
|
||||
{
|
||||
ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->tabRemote), active);
|
||||
|
||||
@@ -45,6 +45,7 @@ private slots:
|
||||
void removeClientCertificate();
|
||||
void chooseRemoteCloneDirectory();
|
||||
void updatePreviewFont();
|
||||
void adjustColorsToStyle(int style);
|
||||
|
||||
void on_buttonManageFileExtension_clicked();
|
||||
void on_buttonBox_clicked(QAbstractButton* button);
|
||||
|
||||
@@ -509,6 +509,9 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>When this value is changed, all the other color preferences are also set to matching colors.</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@@ -873,6 +876,9 @@ Can be set to 0 for disabling completion.</string>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to set this color</string>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -899,6 +905,9 @@ Can be set to 0 for disabling completion.</string>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to set this color</string>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -925,6 +934,9 @@ Can be set to 0 for disabling completion.</string>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to set this color</string>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -941,6 +953,9 @@ Can be set to 0 for disabling completion.</string>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to set this color</string>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -957,6 +972,9 @@ Can be set to 0 for disabling completion.</string>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to set this color</string>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -973,6 +991,9 @@ Can be set to 0 for disabling completion.</string>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to set this color</string>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
||||
158
src/Settings.cpp
158
src/Settings.cpp
@@ -215,18 +215,8 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
|
||||
return "\\";
|
||||
if(name == "filter_delay")
|
||||
return 200;
|
||||
if(name == "null_fg_colour")
|
||||
return QColor(Qt::lightGray).name();
|
||||
if(name == "null_bg_colour")
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
if(name == "reg_fg_colour")
|
||||
return QPalette().color(QPalette::Active, QPalette::Text).name();
|
||||
if(name == "reg_bg_colour")
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
if(name == "bin_fg_colour")
|
||||
return QColor(Qt::lightGray).name();
|
||||
if(name == "bin_bg_colour")
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
if(name.right(6) == "colour")
|
||||
return getDefaultColorValue(group, name, FollowDesktopStyle);
|
||||
}
|
||||
|
||||
// syntaxhighlighter?
|
||||
@@ -246,52 +236,7 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
|
||||
|
||||
// Colour?
|
||||
if(name.right(6) == "colour")
|
||||
{
|
||||
QColor backgroundColour = QPalette().color(QPalette::Active, QPalette::Base);
|
||||
QColor foregroundColour = QPalette().color(QPalette::Active, QPalette::Text);
|
||||
|
||||
if(name == "foreground_colour")
|
||||
return foregroundColour.name();
|
||||
else if(name == "background_colour")
|
||||
return backgroundColour.name();
|
||||
|
||||
// Detect and provide sensible defaults for dark themes
|
||||
if (backgroundColour.value() < foregroundColour.value()) {
|
||||
if(name == "keyword_colour")
|
||||
return QColor(82, 148, 226).name();
|
||||
else if(name == "function_colour")
|
||||
return QColor(Qt::yellow).name();
|
||||
else if(name == "table_colour")
|
||||
return QColor(Qt::cyan).name();
|
||||
else if(name == "comment_colour")
|
||||
return QColor(Qt::green).name();
|
||||
else if(name == "identifier_colour")
|
||||
return QColor(Qt::magenta).name();
|
||||
else if(name == "string_colour")
|
||||
return QColor(Qt::lightGray).name();
|
||||
else if(name == "currentline_colour")
|
||||
return backgroundColour.lighter(150).name();
|
||||
else if(name == "background_colour")
|
||||
return backgroundColour.name();
|
||||
} else {
|
||||
if(name == "keyword_colour")
|
||||
return QColor(Qt::darkBlue).name();
|
||||
else if(name == "function_colour")
|
||||
return QColor(Qt::blue).name();
|
||||
else if(name == "table_colour")
|
||||
return QColor(Qt::darkCyan).name();
|
||||
else if(name == "comment_colour")
|
||||
return QColor(Qt::darkGreen).name();
|
||||
else if(name == "identifier_colour")
|
||||
return QColor(Qt::darkMagenta).name();
|
||||
else if(name == "string_colour")
|
||||
return QColor(Qt::red).name();
|
||||
else if(name == "currentline_colour")
|
||||
return QColor(236, 236, 245).name();
|
||||
else if(name == "background_colour")
|
||||
return backgroundColour.name();
|
||||
}
|
||||
}
|
||||
return getDefaultColorValue(group, name, FollowDesktopStyle);
|
||||
}
|
||||
|
||||
// editor/font?
|
||||
@@ -398,6 +343,103 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QColor Settings::getDefaultColorValue(const QString& group, const QString& name, AppStyle style)
|
||||
{
|
||||
// Data Browser/NULL & Binary Fields
|
||||
if(group == "databrowser")
|
||||
{
|
||||
switch (style) {
|
||||
case FollowDesktopStyle :
|
||||
if(name == "null_fg_colour")
|
||||
return QColor(Qt::lightGray).name();
|
||||
if(name == "null_bg_colour")
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
if(name == "reg_fg_colour")
|
||||
return QPalette().color(QPalette::Active, QPalette::Text).name();
|
||||
if(name == "reg_bg_colour")
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
if(name == "bin_fg_colour")
|
||||
return QColor(Qt::lightGray).name();
|
||||
if(name == "bin_bg_colour")
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
case DarkStyle :
|
||||
if(name == "null_fg_colour")
|
||||
return QColor("#787878");
|
||||
if(name == "null_bg_colour")
|
||||
return QColor("#19232D");
|
||||
if(name == "reg_fg_colour")
|
||||
return QColor("#F0F0F0");
|
||||
if(name == "reg_bg_colour")
|
||||
return QColor("#19232D");
|
||||
if(name == "bin_fg_colour")
|
||||
return QColor("#787878");
|
||||
if(name == "bin_bg_colour")
|
||||
return QColor("#19232D");
|
||||
}
|
||||
}
|
||||
|
||||
// syntaxhighlighter?
|
||||
if(group == "syntaxhighlighter")
|
||||
{
|
||||
// Colour?
|
||||
if(name.right(6) == "colour")
|
||||
{
|
||||
QColor backgroundColour;
|
||||
QColor foregroundColour;
|
||||
switch (style) {
|
||||
case FollowDesktopStyle :
|
||||
backgroundColour = QPalette().color(QPalette::Active, QPalette::Base);
|
||||
foregroundColour = QPalette().color(QPalette::Active, QPalette::Text);
|
||||
break;
|
||||
case DarkStyle :
|
||||
foregroundColour = QColor("#F0F0F0");
|
||||
backgroundColour = QColor("#19232D");
|
||||
break;
|
||||
}
|
||||
if(name == "foreground_colour")
|
||||
return foregroundColour;
|
||||
else if(name == "background_colour")
|
||||
return backgroundColour;
|
||||
|
||||
// Detect and provide sensible defaults for dark themes
|
||||
if (backgroundColour.value() < foregroundColour.value()) {
|
||||
if(name == "keyword_colour")
|
||||
return QColor(82, 148, 226);
|
||||
else if(name == "function_colour")
|
||||
return QColor(Qt::yellow);
|
||||
else if(name == "table_colour")
|
||||
return QColor(Qt::cyan);
|
||||
else if(name == "comment_colour")
|
||||
return QColor(Qt::green);
|
||||
else if(name == "identifier_colour")
|
||||
return QColor(Qt::magenta);
|
||||
else if(name == "string_colour")
|
||||
return QColor(Qt::lightGray);
|
||||
else if(name == "currentline_colour")
|
||||
return backgroundColour.lighter(150);
|
||||
} else {
|
||||
if(name == "keyword_colour")
|
||||
return QColor(Qt::darkBlue);
|
||||
else if(name == "function_colour")
|
||||
return QColor(Qt::blue);
|
||||
else if(name == "table_colour")
|
||||
return QColor(Qt::darkCyan);
|
||||
else if(name == "comment_colour")
|
||||
return QColor(Qt::darkGreen);
|
||||
else if(name == "identifier_colour")
|
||||
return QColor(Qt::darkMagenta);
|
||||
else if(name == "string_colour")
|
||||
return QColor(Qt::red);
|
||||
else if(name == "currentline_colour")
|
||||
return QColor(236, 236, 245);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown combination of group and name? Return an invalid QColor!
|
||||
return QColor();
|
||||
}
|
||||
|
||||
void Settings::restoreDefaults ()
|
||||
{
|
||||
QSettings settings(QApplication::organizationName(), QApplication::organizationName());
|
||||
|
||||
@@ -21,9 +21,13 @@ public:
|
||||
private:
|
||||
Settings() { } // class is fully static
|
||||
|
||||
// This works similar to getSettingsValue but returns the default value instead of the value set by the user
|
||||
// This works similar to getValue but returns the default value instead of the value set by the user
|
||||
static QVariant getDefaultValue(const QString& group, const QString& name);
|
||||
|
||||
// This works similar to getDefaultValue but returns the default color value based on the passed application style
|
||||
// instead of the current palette.
|
||||
static QColor getDefaultColorValue(const QString& group, const QString& name, AppStyle style);
|
||||
|
||||
// Cache for storing the settings to avoid repeatedly reading the settings file all the time
|
||||
static QHash<QString, QVariant> m_hCache;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user