39 HighlightingRule rule;
41 m_keywordFormat.setForeground(Qt::darkBlue);
42 m_keywordFormat.setFontWeight(QFont::Bold);
44 QStringList keywordPatterns = keywords();
45 foreach (
const QString &pattern, keywordPatterns) {
46 rule.pattern = QRegExp(pattern);
47 rule.format = m_keywordFormat;
48 m_highlightingRules.append(rule);
51 m_classFormat.setFontWeight(QFont::Bold);
52 m_classFormat.setForeground(Qt::darkMagenta);
53 rule.pattern = QRegExp(
"\\bQ[A-Za-z]+\\b");
54 rule.format = m_classFormat;
55 m_highlightingRules.append(rule);
57 m_singleLineCommentFormat.setForeground(Qt::red);
58 rule.pattern = QRegExp(
"//[^\n]*");
59 rule.format = m_singleLineCommentFormat;
60 m_highlightingRules.append(rule);
62 m_multiLineCommentFormat.setForeground(Qt::red);
64 m_quotationFormat.setForeground(Qt::darkGreen);
65 rule.pattern = QRegExp(
"\".*\"");
66 rule.format = m_quotationFormat;
67 m_highlightingRules.append(rule);
69 m_functionFormat.setFontItalic(
true);
70 m_functionFormat.setForeground(Qt::blue);
71 rule.pattern = QRegExp(
"\\b[A-Za-z0-9_]+(?=\\()");
72 rule.format = m_functionFormat;
73 m_highlightingRules.append(rule);
75 m_commentStartExpression = QRegExp(
"/\\*");
76 m_commentEndExpression = QRegExp(
"\\*/");
85 foreach (
const HighlightingRule &rule, m_highlightingRules) {
86 QRegExp expression(rule.pattern);
87 int index = expression.indexIn(text);
89 int length = expression.matchedLength();
90 setFormat(index, length, rule.format);
91 index = expression.indexIn(text, index + length);
94 setCurrentBlockState(0);
97 if (previousBlockState() != 1)
98 startIndex = m_commentStartExpression.indexIn(text);
100 while (startIndex >= 0) {
101 int endIndex = m_commentEndExpression.indexIn(text, startIndex);
103 if (endIndex == -1) {
104 setCurrentBlockState(1);
105 commentLength = text.length() - startIndex;
107 commentLength = endIndex - startIndex
108 + m_commentEndExpression.matchedLength();
110 setFormat(startIndex, commentLength, m_multiLineCommentFormat);
111 startIndex = m_commentStartExpression.indexIn(text, startIndex + commentLength);
119 QStringList CodeTextHighlighter::keywords()
static UMLApp * app()
Get the last created instance of this class.
CodeTextHighlighter(QTextDocument *parent=0)
Constructor.
virtual QStringList reservedKeywords() const
Get list of reserved keywords.
CodeGenerator * createObject(Uml::ProgrammingLanguage::Enum pl)
void highlightBlock(const QString &text)
Does highlighting the code block.
This class collects together all of the code documents which form this project, and generates code fo...
Uml::ProgrammingLanguage::Enum activeLanguage() const
Get the language for import and code generation.