mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Support for dark themes in default settings and restore defaults button
All the colour configurations have been reviewed under an operating-system theme dark theme. Some hard-coded colours in QScintilla editors and Data Browser have been replaced by queries of the system palette or reuse of our settings. New settings for foreground and background colours for QScintilla editors defaulting to system colours. This is mainly needed because if the user saves colour settings for a dark theme and then he changes the system theme back to a light theme, then the foreground colours are preserved while the background would fall back to the system theme leading to an incompatible combination. This also gives more freedom to the user in defining his own colour combinations. Since only the default colour settings adapt to the system theme, and once settings are saved this can no longer happen, a 'Restore Defaults' button is added so the default adapted colour settings can be restored. This is also useful for restoring default behaviour when wanted. Other fixes and improvements: waiting cursor while saving; check boxes in SQL tab for bold, italic and underline when applicable; avoid translation of hidden colour setting names used in code. See related issue #1324.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <QShortcut>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QPalette>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
@@ -99,6 +100,17 @@ void ExtendedScintilla::setupSyntaxHighlightingFormat(QsciLexer *lexer, const QS
|
||||
lexer->setFont(font, style);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void ExtendedScintilla::reloadKeywords()
|
||||
{
|
||||
// Set lexer again to reload the updated keywords list
|
||||
@@ -115,9 +127,11 @@ void ExtendedScintilla::reloadLexerSettings(QsciLexer *lexer)
|
||||
QFont defaultfont(Settings::getValue("editor", "font").toString());
|
||||
defaultfont.setStyleHint(QFont::TypeWriter);
|
||||
defaultfont.setPointSize(Settings::getValue("editor", "fontsize").toInt());
|
||||
lexer->setDefaultColor(Qt::black);
|
||||
lexer->setFont(defaultfont);
|
||||
|
||||
lexer->setDefaultColor(QColor(Settings::getValue("syntaxhighlighter", "foreground_colour").toString()));
|
||||
lexer->setPaper(QColor(Settings::getValue("syntaxhighlighter", "background_colour").toString()));
|
||||
|
||||
// Set font
|
||||
QFont font(Settings::getValue("editor", "font").toString());
|
||||
font.setStyleHint(QFont::TypeWriter);
|
||||
@@ -129,12 +143,13 @@ void ExtendedScintilla::reloadLexerSettings(QsciLexer *lexer)
|
||||
marginsfont.setPointSize(font.pointSize());
|
||||
setMarginsFont(marginsfont);
|
||||
setMarginLineNumbers(0, true);
|
||||
setMarginsBackgroundColor(Qt::lightGray);
|
||||
|
||||
updateLineNumberAreaWidth();
|
||||
|
||||
// Highlight current line
|
||||
setCaretLineVisible(true);
|
||||
setCaretLineBackgroundColor(QColor(Settings::getValue("syntaxhighlighter", "currentline_colour").toString()));
|
||||
setCaretForegroundColor(QColor(Settings::getValue("syntaxhighlighter", "foreground_colour").toString()));
|
||||
|
||||
// Set tab width
|
||||
setTabWidth(Settings::getValue("editor", "tabsize").toInt());
|
||||
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
|
||||
bool findText(QString text, bool regexp, bool caseSensitive, bool words, bool wrap, bool forward);
|
||||
void clearSelection();
|
||||
// Override parent setLexer
|
||||
void setLexer(QsciLexer *lexer);
|
||||
|
||||
public slots:
|
||||
void reloadKeywords();
|
||||
|
||||
@@ -110,7 +110,7 @@ void PreferencesDialog::loadSettings()
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setTextColor(2, color);
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setBackgroundColor(2, color);
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setText(2, colorname);
|
||||
if (name != "null") {
|
||||
if (name != "null" && name != "currentline" && name != "background" && name != "foreground") {
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(3, Settings::getValue("syntaxhighlighter", name + "_bold").toBool() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(4, Settings::getValue("syntaxhighlighter", name + "_italic").toBool() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(5, Settings::getValue("syntaxhighlighter", name + "_underline").toBool() ? Qt::Checked : Qt::Unchecked);
|
||||
@@ -181,6 +181,8 @@ void PreferencesDialog::loadSettings()
|
||||
|
||||
void PreferencesDialog::saveSettings()
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
Settings::setValue("db", "defaultencoding", ui->encodingComboBox->currentText());
|
||||
Settings::setValue("db", "defaultlocation", ui->locationEdit->text());
|
||||
Settings::setValue("db", "savedefaultlocation", ui->comboDefaultLocation->currentIndex());
|
||||
@@ -281,10 +283,11 @@ void PreferencesDialog::saveSettings()
|
||||
|
||||
Settings::setValue("General", "language", newLanguage);
|
||||
Settings::setValue("General", "toolbarStyle", ui->toolbarStyleComboBox->currentIndex());
|
||||
|
||||
Settings::setValue("General", "DBFileExtensions", m_dbFileExtensions.join(";;") );
|
||||
|
||||
accept();
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void PreferencesDialog::showColourDialog(QTreeWidgetItem* item, int column)
|
||||
@@ -578,3 +581,19 @@ void PreferencesDialog::on_buttonManageFileExtension_clicked()
|
||||
m_dbFileExtensions = manager->getDBFileExtensions();
|
||||
}
|
||||
}
|
||||
|
||||
void PreferencesDialog::on_buttonBox_clicked(QAbstractButton* button)
|
||||
{
|
||||
if (button == ui->buttonBox->button(QDialogButtonBox::Cancel))
|
||||
reject();
|
||||
else if (button == ui->buttonBox->button(QDialogButtonBox::Save))
|
||||
saveSettings();
|
||||
else if (button == ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)) {
|
||||
if (QMessageBox::warning(this, QApplication::applicationName(), tr("Are you sure you want to clear all the saved settings?\nAll your preferences will be lost and default values will be used."),
|
||||
QMessageBox::RestoreDefaults | QMessageBox::Cancel, QMessageBox::Cancel) == QMessageBox::RestoreDefaults)
|
||||
{
|
||||
Settings::restoreDefaults();
|
||||
accept();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class QTreeWidgetItem;
|
||||
class QFrame;
|
||||
class QTableWidget;
|
||||
class QSslCertificate;
|
||||
class QAbstractButton;
|
||||
|
||||
namespace Ui {
|
||||
class PreferencesDialog;
|
||||
@@ -37,6 +38,7 @@ private slots:
|
||||
void updatePreviewFont();
|
||||
|
||||
void on_buttonManageFileExtension_clicked();
|
||||
void on_buttonBox_clicked(QAbstractButton* button);
|
||||
|
||||
private:
|
||||
Ui::PreferencesDialog *ui;
|
||||
|
||||
@@ -806,7 +806,7 @@
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>function</string>
|
||||
<string notr="true">function</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Function</string>
|
||||
@@ -894,12 +894,28 @@
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>currentline</string>
|
||||
<string notr="true">currentline</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Current line</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">background</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Background</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">foreground</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Foreground</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -1349,7 +1365,7 @@
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -1415,38 +1431,6 @@
|
||||
<include location="icons/icons.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>saveSettings()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>287</x>
|
||||
<y>607</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>155</x>
|
||||
<y>143</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>355</x>
|
||||
<y>607</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>144</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonAddExtension</sender>
|
||||
<signal>clicked()</signal>
|
||||
@@ -1623,6 +1607,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>clicked(QAbstractButton*)</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>on_buttonBox_clicked(QAbstractButton*)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>385</x>
|
||||
<y>591</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>385</x>
|
||||
<y>306</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>saveSettings()</slot>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QFontInfo>
|
||||
#include <QLocale>
|
||||
#include <QStandardPaths>
|
||||
#include <QPalette>
|
||||
|
||||
QHash<QString, QVariant> Settings::m_hCache;
|
||||
|
||||
@@ -188,15 +189,15 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
|
||||
if(name == "null_fg_colour")
|
||||
return QColor(Qt::lightGray).name();
|
||||
if(name == "null_bg_colour")
|
||||
return QColor(Qt::white).name();
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
if(name == "reg_fg_colour")
|
||||
return QColor(Qt::black).name();
|
||||
return QPalette().color(QPalette::Active, QPalette::Text).name();
|
||||
if(name == "reg_bg_colour")
|
||||
return QColor(Qt::white).name();
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
if(name == "bin_fg_colour")
|
||||
return QColor(Qt::lightGray).name();
|
||||
if(name == "bin_bg_colour")
|
||||
return QColor(Qt::white).name();
|
||||
return QPalette().color(QPalette::Active, QPalette::Base).name();
|
||||
}
|
||||
|
||||
// syntaxhighlighter?
|
||||
@@ -217,20 +218,50 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
|
||||
// Colour?
|
||||
if(name.right(6) == "colour")
|
||||
{
|
||||
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();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,3 +341,10 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
|
||||
// Unknown combination of group and name? Return an invalid QVariant!
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void Settings::restoreDefaults ()
|
||||
{
|
||||
QSettings settings(QApplication::organizationName(), QApplication::organizationName());
|
||||
settings.clear();
|
||||
m_hCache.clear();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class Settings
|
||||
public:
|
||||
static QVariant getValue(const QString& group, const QString& name);
|
||||
static void setValue(const QString& group, const QString& name, const QVariant& value, bool dont_save_to_disk = false);
|
||||
static void restoreDefaults();
|
||||
|
||||
private:
|
||||
Settings() { } // class is fully static
|
||||
|
||||
@@ -37,6 +37,7 @@ void DockTextEdit::reloadSettings()
|
||||
setupSyntaxHighlightingFormat(jsonLexer, "comment", QsciLexerJSON::CommentBlock);
|
||||
setupSyntaxHighlightingFormat(jsonLexer, "keyword", QsciLexerJSON::Keyword);
|
||||
setupSyntaxHighlightingFormat(jsonLexer, "keyword", QsciLexerJSON::KeywordLD);
|
||||
setupSyntaxHighlightingFormat(jsonLexer, "function", QsciLexerJSON::Operator);
|
||||
setupSyntaxHighlightingFormat(jsonLexer, "string", QsciLexerJSON::String);
|
||||
setupSyntaxHighlightingFormat(jsonLexer, "table", QsciLexerJSON::Number);
|
||||
setupSyntaxHighlightingFormat(jsonLexer, "identifier", QsciLexerJSON::Property);
|
||||
@@ -57,8 +58,12 @@ void DockTextEdit::reloadSettings()
|
||||
jsonLexer->setPaper(jsonLexer->defaultPaper(QsciLexerJSON::String), QsciLexerJSON::Error);
|
||||
jsonLexer->setPaper(jsonLexer->defaultPaper(QsciLexerJSON::String), QsciLexerJSON::UnclosedString);
|
||||
|
||||
xmlLexer->setColor(QColor(Settings::getValue("syntaxhighlighter", "foreground_colour").toString()));
|
||||
setupSyntaxHighlightingFormat(xmlLexer, "comment", QsciLexerHTML::HTMLComment);
|
||||
setupSyntaxHighlightingFormat(xmlLexer, "keyword", QsciLexerHTML::Tag);
|
||||
setupSyntaxHighlightingFormat(xmlLexer, "keyword", QsciLexerHTML::XMLTagEnd);
|
||||
setupSyntaxHighlightingFormat(xmlLexer, "keyword", QsciLexerHTML::XMLStart);
|
||||
setupSyntaxHighlightingFormat(xmlLexer, "keyword", QsciLexerHTML::XMLEnd);
|
||||
setupSyntaxHighlightingFormat(xmlLexer, "string", QsciLexerHTML::HTMLDoubleQuotedString);
|
||||
setupSyntaxHighlightingFormat(xmlLexer, "string", QsciLexerHTML::HTMLSingleQuotedString);
|
||||
setupSyntaxHighlightingFormat(xmlLexer, "table", QsciLexerHTML::HTMLNumber);
|
||||
|
||||
Reference in New Issue
Block a user