Mantid
Loading...
Searching...
No Matches
AlternateCSPythonLexer.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
14AlternateCSPythonLexer::AlternateCSPythonLexer(const QFont &font) : QsciLexerPython(), m_font(font) {
15 auto &config = Mantid::Kernel::ConfigService::Instance();
16 std::string apply_dark_theme = "False";
17 if (config.hasProperty("editors.apply_dark_theme")) {
18 apply_dark_theme = config.getString("editors.apply_dark_theme");
19 }
20 m_isDarkMode = (apply_dark_theme == "True");
21}
22
28QColor AlternateCSPythonLexer::defaultColor(int style) const {
29 return m_isDarkMode ? defaultColorDark(style) : defaultColorLight(style);
30}
31
38 switch (style) {
39 case Default:
40 return QColor(0x00, 0x00, 0x00);
41
42 case Comment:
43 return QColor(0xad, 0xad, 0xad);
44
45 case Number:
46 return QColor(0x80, 0x00, 0x00);
47
48 case DoubleQuotedString:
49 case SingleQuotedString:
50 return QColor(0x00, 0xaa, 0x00);
51
52 case DoubleQuotedFString:
53 case SingleQuotedFString:
54 return QColor(0x00, 0xaa, 0x00);
55
56 case Keyword:
57 return QColor(0x00, 0x00, 0xff);
58
59 case TripleSingleQuotedString:
60 case TripleDoubleQuotedString:
61 return QColor(0x00, 0xaa, 0x00);
62
63 case TripleSingleQuotedFString:
64 case TripleDoubleQuotedFString:
65 return QColor(0x00, 0xaa, 0x00);
66
67 case ClassName:
68 return QColor(0x00, 0x00, 0x00);
69
70 case FunctionMethodName:
71 return QColor(0x00, 0x7f, 0x7f);
72
73 case Operator:
74 case Identifier:
75 return QColor(0x00, 0x00, 0x00);
76
77 case CommentBlock:
78 return QColor(0xad, 0xad, 0xad);
79
80 case UnclosedString:
81 return QColor(0x00, 0x00, 0x00);
82
83 case HighlightedIdentifier:
84 return QColor(0x40, 0x70, 0x90);
85
86 case Decorator:
87 return QColor(0x80, 0x50, 0x00);
88 }
89
90 return QsciLexer::defaultColor(style);
91}
92
99 switch (style) {
100 case Default:
101 return QColor(0xFF, 0xFF, 0xFF);
102
103 case Comment:
104 return QColor(0x72, 0x86, 0xB7);
105
106 case Number:
107 return QColor(0xFF, 0xC6, 0x8F);
108
109 case DoubleQuotedString:
110 case SingleQuotedString:
111 return QColor(0x98, 0xC3, 0x78);
112
113 case DoubleQuotedFString:
114 case SingleQuotedFString:
115 return QColor(0xE0, 0x6D, 0x76);
116
117 case Keyword:
118 return QColor(0xC6, 0x78, 0xDD);
119
120 case TripleSingleQuotedString:
121 case TripleDoubleQuotedString:
122 return QColor(0xCE, 0x91, 0x78);
123
124 case TripleSingleQuotedFString:
125 case TripleDoubleQuotedFString:
126 return QColor(0xE0, 0x6D, 0x76);
127
128 case ClassName:
129 return QColor(0xFF, 0xEE, 0xAE);
130
131 case FunctionMethodName:
132 return QColor(0xBB, 0xDA, 0xFF);
133
134 case Operator:
135 return QColor(0x99, 0xFF, 0xFF);
136
137 case Identifier:
138 return QColor(0xFF, 0xFF, 0xFF);
139
140 case CommentBlock:
141 return QColor(0xad, 0xad, 0xad);
142
143 case UnclosedString:
144 return QColor(0xFF, 0xFF, 0xFF);
145
146 case HighlightedIdentifier:
147 return QColor(0x00, 0x3F, 0x8E);
148
149 case Decorator:
150 return QColor(0xDC, 0xDC, 0xAA);
151 }
152
153 return QsciLexer::defaultColor(style);
154}
155
162 Q_UNUSED(style);
163 return m_font;
164}
165
167// * Returns the keywords used by the lexer for a given set.
168// * @param set The keyword set to retrieve (1 is for keywords)
169// * @return A string containing the keywords
170// */
171const char *AlternateCSPythonLexer::keywords(int set) const {
172 if (set == 1) {
173 // Retrieve default Python keywords from qscintilla
174 const char *defaultKeywords = QsciLexerPython::keywords(1);
175 static std::string combinedKeywords;
176 std::ostringstream stream;
177 stream << defaultKeywords << " " << customKeywords;
178
179 combinedKeywords = stream.str();
180 return combinedKeywords.c_str();
181 }
182
183 return QsciLexerPython::keywords(set);
184}
185
187 Q_UNUSED(style);
188 return m_isDarkMode ? QColor(30, 30, 30) : QColor(255, 255, 255);
189}
QColor defaultColor(int style) const override
Returns the foreground colour of the text for a style.
AlternateCSPythonLexer(const QFont &font)
Construct a lexer with a font to be used for all text styles.
QColor defaultColorDark(int style) const
Returns the foreground colour of the text for a dark theme style.
QColor defaultPaper(int style) const override
QFont defaultFont(int style) const override
Returns the font of the text.
QColor defaultColorLight(int style) const
Returns the foreground colour of the text for a light theme style.
const char * keywords(int set) const override
‍**
static constexpr const char * customKeywords