| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "stylescicpp.h" |
| 6 | #include "textedittabwidget/style/stylejsonfile.h" |
| 7 | #include "textedittabwidget/textedit.h" |
| 8 | #include "textedittabwidget/style/stylecolor.h" |
| 9 | |
| 10 | #include "SciLexer.h" |
| 11 | |
| 12 | |
| 13 | StyleSciCpp::StyleSciCpp(TextEdit *parent) |
| 14 | : StyleSci(parent) |
| 15 | { |
| 16 | |
| 17 | } |
| 18 | |
| 19 | QMap<int, QString> StyleSciCpp::keyWords() const |
| 20 | { |
| 21 | return { |
| 22 | { 1, "and and_eq asm auto bitand bitor bool break case " |
| 23 | "catch char class compl const const_cast continue " |
| 24 | "default delete do double dynamic_cast else enum " |
| 25 | "explicit export extern false float for friend goto if " |
| 26 | "inline int long mutable namespace new not not_eq " |
| 27 | "operator or or_eq private protected public register " |
| 28 | "reinterpret_cast return short signed sizeof static " |
| 29 | "static_cast struct switch template this throw true " |
| 30 | "try typedef typeid typename union unsigned using " |
| 31 | "virtual void volatile wchar_t while xor xor_eq" |
| 32 | } |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | void StyleSciCpp::setStyle() |
| 37 | { |
| 38 | StyleSci::setStyle(); |
| 39 | auto jsonFile = edit()->getStyleFile(); |
| 40 | if (jsonFile->setTheme(StyleJsonFile::Theme::get()->Dark)) { |
| 41 | QJsonObject tempObj; |
| 42 | int tempFore; |
| 43 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Comment).toObject(); |
| 44 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 45 | edit()->styleSetFore(SCE_C_COMMENT, tempFore); // #整行 |
| 46 | edit()->styleSetFore(SCE_C_COMMENTLINE, tempFore); // //注释 |
| 47 | edit()->styleSetFore(SCE_C_COMMENTDOC, tempFore); |
| 48 | edit()->styleSetFore(SCE_C_COMMENTLINEDOC, tempFore); // ///注释 |
| 49 | edit()->styleSetFore(SCE_C_COMMENTDOCKEYWORD, tempFore - 0x3333); |
| 50 | edit()->styleSetFore(SCE_C_COMMENTDOCKEYWORDERROR, tempFore - 0x3333); // /// @ |
| 51 | edit()->styleSetFore(SCE_C_PREPROCESSORCOMMENT, tempFore); |
| 52 | edit()->styleSetFore(SCE_C_PREPROCESSORCOMMENTDOC, tempFore); |
| 53 | |
| 54 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Number).toObject(); |
| 55 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 56 | edit()->styleSetFore(SCE_C_NUMBER, tempFore); |
| 57 | |
| 58 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Keyword).toObject(); |
| 59 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 60 | edit()->styleSetFore(SCE_C_WORD, tempFore); |
| 61 | edit()->styleSetFore(SCE_C_WORD2, tempFore); |
| 62 | |
| 63 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->String).toObject(); |
| 64 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 65 | edit()->styleSetFore(SCE_C_STRING, tempFore); // 字符串 |
| 66 | edit()->styleSetFore(SCE_C_CHARACTER, tempFore); // 字符串 |
| 67 | edit()->styleSetFore(SCE_C_UUID, tempFore); |
| 68 | edit()->styleSetFore(SCE_C_STRINGEOL, tempFore); |
| 69 | edit()->styleSetFore(SCE_C_REGEX, tempFore); |
| 70 | edit()->styleSetFore(SCE_C_STRINGRAW, tempFore); |
| 71 | edit()->styleSetFore(SCE_C_VERBATIM, tempFore); |
| 72 | edit()->styleSetFore(SCE_C_HASHQUOTEDSTRING, tempFore); |
| 73 | |
| 74 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Preprocessor).toObject(); |
| 75 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 76 | edit()->styleSetFore(SCE_C_PREPROCESSOR, tempFore); // # |
| 77 | |
| 78 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Operators).toObject(); |
| 79 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 80 | edit()->styleSetFore(SCE_C_OPERATOR, tempFore); // 符号 |
| 81 | |
| 82 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Text).toObject(); |
| 83 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 84 | edit()->styleSetFore(SCE_C_IDENTIFIER, tempFore); |
| 85 | edit()->styleSetFore(SCE_C_USERLITERAL, tempFore); |
| 86 | edit()->styleSetFore(SCE_C_TASKMARKER, tempFore); |
| 87 | edit()->styleSetFore(SCE_C_ESCAPESEQUENCE, tempFore); |
| 88 | |
| 89 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Global).toObject(); |
| 90 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 91 | edit()->styleSetFore(SCE_C_GLOBALCLASS, tempFore); |
| 92 | } else { |
| 93 | edit()->styleSetFore(SCE_C_COMMENT, StyleColor::color(StyleColor::Table::get()->DeepSkyBlue)); // #整行 |
| 94 | edit()->styleSetFore(SCE_C_COMMENTLINE, StyleColor::color(StyleColor::Table::get()->DarkTurquoise)); // //注释 |
| 95 | edit()->styleSetFore(SCE_C_COMMENTDOC, StyleColor::color(StyleColor::Table::get()->DarkTurquoise)); |
| 96 | edit()->styleSetFore(SCE_C_NUMBER, StyleColor::color(StyleColor::Table::get()->Magenta)); |
| 97 | edit()->styleSetFore(SCE_C_WORD, StyleColor::color(StyleColor::Table::get()->Gold)); |
| 98 | edit()->styleSetFore(SCE_C_STRING, StyleColor::color(StyleColor::Table::get()->Magenta)); // 字符串 |
| 99 | edit()->styleSetFore(SCE_C_CHARACTER, StyleColor::color(StyleColor::Table::get()->Magenta)); |
| 100 | edit()->styleSetFore(SCE_C_UUID, StyleColor::color(StyleColor::Table::get()->Magenta)); |
| 101 | edit()->styleSetFore(SCE_C_PREPROCESSOR, StyleColor::color(StyleColor::Table::get()->MediumBlue)); // # |
| 102 | edit()->styleSetFore(SCE_C_OPERATOR, edit()->styleFore(SCE_C_DEFAULT)); // 符号 |
| 103 | edit()->styleSetFore(SCE_C_IDENTIFIER, edit()->styleFore(SCE_C_DEFAULT)); |
| 104 | edit()->styleSetFore(SCE_C_STRINGEOL, StyleColor::color(StyleColor::Table::get()->Magenta)); |
| 105 | edit()->styleSetFore(SCE_C_VERBATIM, StyleColor::color(StyleColor::Table::get()->Magenta)); |
| 106 | edit()->styleSetFore(SCE_C_REGEX, StyleColor::color(StyleColor::Table::get()->Magenta)); |
| 107 | edit()->styleSetFore(SCE_C_COMMENTLINEDOC, StyleColor::color(StyleColor::Table::get()->DarkTurquoise)); // ///注释 |
| 108 | edit()->styleSetFore(SCE_C_WORD2, StyleColor::color(StyleColor::Table::get()->Gold)); // 1 一般关键字 |
| 109 | edit()->styleSetFore(SCE_C_COMMENTDOCKEYWORD, StyleColor::color(StyleColor::Table::get()->DeepSkyBlue)); |
| 110 | edit()->styleSetFore(SCE_C_COMMENTDOCKEYWORDERROR, StyleColor::color(StyleColor::Table::get()->DeepSkyBlue)); // /// @ |
| 111 | edit()->styleSetFore(SCE_C_GLOBALCLASS, StyleColor::color(StyleColor::Table::get()->Gold)); |
| 112 | edit()->styleSetFore(SCE_C_STRINGRAW, StyleColor::color(StyleColor::Table::get()->Gainsboro)); |
| 113 | edit()->styleSetFore(SCE_C_HASHQUOTEDSTRING, StyleColor::color(StyleColor::Table::get()->Gainsboro)); |
| 114 | edit()->styleSetFore(SCE_C_PREPROCESSORCOMMENT, StyleColor::color(StyleColor::Table::get()->Gainsboro)); |
| 115 | edit()->styleSetFore(SCE_C_PREPROCESSORCOMMENTDOC, StyleColor::color(StyleColor::Table::get()->Gainsboro)); |
| 116 | edit()->styleSetFore(SCE_C_USERLITERAL, StyleColor::color(StyleColor::Table::get()->Gainsboro)); |
| 117 | edit()->styleSetFore(SCE_C_TASKMARKER, StyleColor::color(StyleColor::Table::get()->Gainsboro)); |
| 118 | edit()->styleSetFore(SCE_C_ESCAPESEQUENCE, StyleColor::color(StyleColor::Table::get()->Gainsboro)); |
| 119 | } |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | int StyleSciCpp::sectionEnd() const |
| 124 | { |
| 125 | return SCE_C_ESCAPESEQUENCE; //default style key end; |
| 126 | } |
| 127 | |