forked from sqlitebrowser/sqlitebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsontextedit.cpp
More file actions
54 lines (45 loc) · 2.08 KB
/
jsontextedit.cpp
File metadata and controls
54 lines (45 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "jsontextedit.h"
#include "Settings.h"
QsciLexerJSON* JsonTextEdit::jsonLexer = nullptr;
JsonTextEdit::JsonTextEdit(QWidget* parent) :
ExtendedScintilla(parent)
{
// Create lexer object if not done yet
if(jsonLexer == nullptr)
jsonLexer = new QsciLexerJSON(this);
// Set the JSON lexer
setLexer(jsonLexer);
jsonLexer->setFoldCompact(false);
// Do rest of initialisation
reloadSettings();
}
JsonTextEdit::~JsonTextEdit()
{
}
void JsonTextEdit::reloadSettings()
{
ExtendedScintilla::reloadSettings();
setupSyntaxHighlightingFormat("comment", QsciLexerJSON::CommentLine);
setupSyntaxHighlightingFormat("comment", QsciLexerJSON::CommentBlock);
setupSyntaxHighlightingFormat("keyword", QsciLexerJSON::Keyword);
setupSyntaxHighlightingFormat("keyword", QsciLexerJSON::KeywordLD);
setupSyntaxHighlightingFormat("string", QsciLexerJSON::String);
setupSyntaxHighlightingFormat("table", QsciLexerJSON::Number);
setupSyntaxHighlightingFormat("identifier", QsciLexerJSON::Property);
jsonLexer->setHighlightComments(true);
// 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);
}