mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
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.
85 lines
3.5 KiB
C++
85 lines
3.5 KiB
C++
#include "docktextedit.h"
|
|
#include "Settings.h"
|
|
|
|
QsciLexerJSON* DockTextEdit::jsonLexer = nullptr;
|
|
QsciLexerXML* DockTextEdit::xmlLexer = nullptr;
|
|
|
|
DockTextEdit::DockTextEdit(QWidget* parent) :
|
|
ExtendedScintilla(parent)
|
|
{
|
|
// Create lexer objects if not done yet
|
|
if(jsonLexer == nullptr)
|
|
jsonLexer = new QsciLexerJSON(this);
|
|
if(xmlLexer == nullptr)
|
|
xmlLexer = new QsciLexerXML(this);
|
|
|
|
// Set the JSON lexer as default
|
|
setLexer(jsonLexer);
|
|
|
|
jsonLexer->setFoldCompact(false);
|
|
jsonLexer->setHighlightComments(true);
|
|
|
|
// Do rest of initialisation
|
|
reloadSettings();
|
|
}
|
|
|
|
DockTextEdit::~DockTextEdit()
|
|
{
|
|
}
|
|
|
|
void DockTextEdit::reloadSettings()
|
|
{
|
|
// Set the parent settings for both lexers
|
|
reloadLexerSettings(jsonLexer);
|
|
reloadLexerSettings(xmlLexer);
|
|
|
|
setupSyntaxHighlightingFormat(jsonLexer, "comment", QsciLexerJSON::CommentLine);
|
|
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);
|
|
|
|
// The default style for invalid JSON or unclosed strings uses red
|
|
// background and white foreground, but the current line has
|
|
// precedence, so it is by default white over gray. We change the
|
|
// default to something more readable for the current line at
|
|
// invalid JSON.
|
|
QColor stringColor = QColor(Settings::getValue("syntaxhighlighter", "string_colour").toString());
|
|
jsonLexer->setColor(stringColor, QsciLexerJSON::Error);
|
|
jsonLexer->setColor(stringColor, QsciLexerJSON::UnclosedString);
|
|
QFont errorFont(Settings::getValue("editor", "font").toString());
|
|
errorFont.setPointSize(Settings::getValue("editor", "fontsize").toInt());
|
|
errorFont.setItalic(true);
|
|
jsonLexer->setFont(errorFont, QsciLexerJSON::Error);
|
|
jsonLexer->setFont(errorFont, QsciLexerJSON::UnclosedString);
|
|
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);
|
|
setupSyntaxHighlightingFormat(xmlLexer, "identifier", QsciLexerHTML::Attribute);
|
|
}
|
|
|
|
void DockTextEdit::setLanguage(Language lang)
|
|
{
|
|
m_language = lang;
|
|
switch (lang) {
|
|
case JSON:
|
|
setLexer(jsonLexer);
|
|
break;
|
|
case XML:
|
|
setLexer(xmlLexer);
|
|
break;
|
|
}
|
|
}
|