| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "stylescijs.h" |
| 6 | #include "textedittabwidget/style/stylejsonfile.h" |
| 7 | #include "textedittabwidget/style/stylecolor.h" |
| 8 | #include "textedittabwidget/textedit.h" |
| 9 | #include "SciLexer.h" |
| 10 | |
| 11 | StyleSciJS::StyleSciJS(TextEdit *parent) |
| 12 | : StyleSci(parent) |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | QMap<int, QString> StyleSciJS::keyWords() const |
| 17 | { |
| 18 | return StyleSci::keyWords(); |
| 19 | } |
| 20 | |
| 21 | void StyleSciJS::setStyle() |
| 22 | { |
| 23 | StyleSci::setStyle(); |
| 24 | |
| 25 | auto jsonFile = edit()->getStyleFile(); |
| 26 | if (jsonFile->setTheme(StyleJsonFile::Theme::get()->Dark)) { |
| 27 | auto highLightColor = [&](const QString &key) -> int { |
| 28 | QJsonObject tempObj = jsonFile->value(key).toObject(); |
| 29 | return StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toUInt(nullptr, 16)); |
| 30 | }; |
| 31 | // comment. |
| 32 | int color = highLightColor(StyleJsonFile::Key_1::get()->Comment); |
| 33 | edit()->styleSetFore(SCE_HJ_COMMENTLINE, color); |
| 34 | edit()->styleSetFore(SCE_HJ_COMMENT, color); |
| 35 | edit()->styleSetFore(SCE_HJ_COMMENTDOC, color); |
| 36 | |
| 37 | // number. |
| 38 | color = highLightColor(StyleJsonFile::Key_1::get()->Number); |
| 39 | edit()->styleSetFore(SCE_HJ_NUMBER, color); |
| 40 | |
| 41 | // keyword. |
| 42 | color = highLightColor(StyleJsonFile::Key_1::get()->Keyword); |
| 43 | edit()->styleSetFore(SCE_HJ_KEYWORD, color); |
| 44 | |
| 45 | // string. |
| 46 | color = highLightColor(StyleJsonFile::Key_1::get()->String); |
| 47 | edit()->styleSetFore(SCE_HJ_DOUBLESTRING, color); |
| 48 | edit()->styleSetFore(SCE_HJ_DOUBLESTRING, color); |
| 49 | |
| 50 | // word. |
| 51 | color = highLightColor(StyleJsonFile::Key_1::get()->Text); |
| 52 | edit()->styleSetFore(SCE_HJ_WORD, color); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void StyleSciJS::setLexer() |
| 57 | { |
| 58 | StyleSci::setLexer(); |
| 59 | } |
| 60 | |
| 61 | int StyleSciJS::sectionEnd() const |
| 62 | { |
| 63 | return SCE_HJ_REGEX; |
| 64 | } |
| 65 | |
| 66 | int StyleSciJS::sectionStart() const |
| 67 | { |
| 68 | return SCE_HJ_START; |
| 69 | } |
| 70 | |