1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "stylescipython.h" |
6 | #include "textedittabwidget/style/stylejsonfile.h" |
7 | #include "textedittabwidget/style/stylecolor.h" |
8 | #include "textedittabwidget/textedit.h" |
9 | #include "SciLexer.h" |
10 | |
11 | StyleSciPython::StyleSciPython(TextEdit *parent) |
12 | : StyleSci (parent) |
13 | { |
14 | |
15 | } |
16 | |
17 | QMap<int, QString> StyleSciPython::keyWords() const |
18 | { |
19 | return StyleSci::keyWords(); |
20 | } |
21 | |
22 | void StyleSciPython::setStyle() |
23 | { |
24 | StyleSci::setStyle(); |
25 | |
26 | auto jsonFile = edit()->getStyleFile(); |
27 | if (jsonFile->setTheme(StyleJsonFile::Theme::get()->Dark)) { |
28 | QJsonObject tempObj; |
29 | int tempFore; |
30 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Comment).toObject(); |
31 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
32 | edit()->styleSetFore(SCE_P_COMMENTLINE, tempFore); |
33 | edit()->styleSetFore(SCE_P_COMMENTBLOCK, tempFore); |
34 | |
35 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Class).toObject(); |
36 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
37 | edit()->styleSetFore(SCE_P_CLASSNAME, tempFore); |
38 | edit()->styleSetFore(SCE_P_DEFNAME, tempFore); |
39 | edit()->styleSetFore(SCE_P_TRIPLE, tempFore); |
40 | edit()->styleSetFore(SCE_P_TRIPLEDOUBLE, tempFore); |
41 | |
42 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Variable).toObject(); |
43 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
44 | edit()->styleSetFore(SCE_P_IDENTIFIER, tempFore); |
45 | |
46 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Number).toObject(); |
47 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
48 | edit()->styleSetFore(SCE_P_NUMBER, tempFore); |
49 | |
50 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Keyword).toObject(); |
51 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
52 | edit()->styleSetFore(SCE_P_WORD, tempFore); |
53 | edit()->styleSetFore(SCE_P_WORD2, tempFore); |
54 | |
55 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->String).toObject(); |
56 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
57 | edit()->styleSetFore(SCE_P_STRING, tempFore); |
58 | edit()->styleSetFore(SCE_P_CHARACTER, tempFore); |
59 | edit()->styleSetFore(SCE_P_STRINGEOL, tempFore); |
60 | edit()->styleSetFore(SCE_P_DECORATOR, tempFore); |
61 | edit()->styleSetFore(SCE_P_FSTRING, tempFore); |
62 | edit()->styleSetFore(SCE_P_FCHARACTER, tempFore); |
63 | edit()->styleSetFore(SCE_P_FTRIPLE, tempFore); |
64 | edit()->styleSetFore(SCE_P_FTRIPLEDOUBLE, tempFore); |
65 | |
66 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Operators).toObject(); |
67 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
68 | edit()->styleSetFore(SCE_P_OPERATOR, tempFore); // 符号 |
69 | } |
70 | } |
71 | |
72 | void StyleSciPython::setLexer() |
73 | { |
74 | StyleSci::setLexer(); |
75 | } |
76 | |
77 | int StyleSciPython::sectionEnd() const |
78 | { |
79 | return SCE_P_FTRIPLEDOUBLE; |
80 | } |
81 | |