GUI: Updated codeeditor formatting

This commit is contained in:
Daniel Marjamäki 2018-02-23 22:17:40 +01:00
parent 17388c33aa
commit 1b53e3ec1d
2 changed files with 41 additions and 18 deletions

View File

@ -11,18 +11,48 @@ Highlighter::Highlighter(QTextDocument *parent)
keywordFormat.setForeground(Qt::darkBlue); keywordFormat.setForeground(Qt::darkBlue);
keywordFormat.setFontWeight(QFont::Bold); keywordFormat.setFontWeight(QFont::Bold);
QStringList keywordPatterns; QStringList keywordPatterns;
keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b" keywordPatterns << "bool"
<< "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b" << "break"
<< "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b" << "case"
<< "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b" << "char"
<< "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b" << "class"
<< "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b" << "const"
<< "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b" << "continue"
<< "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b" << "default"
<< "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b" << "do"
<< "\\bvoid\\b" << "\\bvolatile\\b" << "\\bbool\\b"; << "double"
<< "else"
<< "enum"
<< "explicit"
<< "for"
<< "friend"
<< "if"
<< "inline"
<< "int"
<< "long"
<< "namespace"
<< "operator"
<< "private"
<< "protected"
<< "public"
<< "return"
<< "short"
<< "signed"
<< "static"
<< "struct"
<< "switch"
<< "template"
<< "throw"
<< "typedef"
<< "typename"
<< "union"
<< "unsigned"
<< "virtual"
<< "void"
<< "volatile"
<< "while";
foreach (const QString &pattern, keywordPatterns) { foreach (const QString &pattern, keywordPatterns) {
rule.pattern = QRegularExpression(pattern); rule.pattern = QRegularExpression("\\b" + pattern + "\\b");
rule.format = keywordFormat; rule.format = keywordFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
} }
@ -38,12 +68,6 @@ Highlighter::Highlighter(QTextDocument *parent)
rule.format = quotationFormat; rule.format = quotationFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
functionFormat.setFontItalic(true);
functionFormat.setForeground(Qt::blue);
rule.pattern = QRegularExpression("\\b[A-Za-z0-9_]+(?=\\()");
rule.format = functionFormat;
highlightingRules.append(rule);
singleLineCommentFormat.setForeground(Qt::gray); singleLineCommentFormat.setForeground(Qt::gray);
rule.pattern = QRegularExpression("//[^\n]*"); rule.pattern = QRegularExpression("//[^\n]*");
rule.format = singleLineCommentFormat; rule.format = singleLineCommentFormat;

View File

@ -41,7 +41,6 @@ private:
QTextCharFormat singleLineCommentFormat; QTextCharFormat singleLineCommentFormat;
QTextCharFormat multiLineCommentFormat; QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat; QTextCharFormat quotationFormat;
QTextCharFormat functionFormat;
QTextCharFormat symbolFormat; QTextCharFormat symbolFormat;
}; };