git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
#include "piqt_highlighter.h"
|
|
|
|
|
|
ConfigHighlighter::ConfigHighlighter(QTextDocument * parent): QSyntaxHighlighter(parent) {
|
|
HighlightingRule rule;
|
|
|
|
valueNameFormat.setForeground(QColor(0, 64, 154));
|
|
rule.pattern = QRegExp("[^=]"); //"\\b[A-Za-z0-9_]+(?=\\()");
|
|
rule.format = valueNameFormat;
|
|
highlightingRules.append(rule);
|
|
|
|
valueFormat.setForeground(QColor(192, 0, 0));
|
|
rule.pattern = QRegExp("=[^\n]*");
|
|
rule.format = valueFormat;
|
|
highlightingRules.append(rule);
|
|
|
|
equalFormat.setFontWeight(QFont::Bold);
|
|
equalFormat.setForeground(QColor(96, 126, 0));
|
|
rule.pattern = QRegExp("=");
|
|
rule.format = equalFormat;
|
|
highlightingRules.append(rule);
|
|
|
|
sectionFormat.setFontWeight(QFont::Bold);
|
|
sectionFormat.setForeground(QColor(0, 32, 64));
|
|
rule.pattern = QRegExp("\\[.*\\]");
|
|
rule.format = sectionFormat;
|
|
highlightingRules.append(rule);
|
|
|
|
singleLineCommentFormat.setFontItalic(true);
|
|
singleLineCommentFormat.setForeground(QColor(128, 128, 128));
|
|
rule.pattern = QRegExp("#[^\n]*");
|
|
rule.format = singleLineCommentFormat;
|
|
highlightingRules.append(rule);
|
|
|
|
spaceFormat.setForeground(QColor(210, 210, 210));
|
|
|
|
//commentStartExpression = QRegExp("/\\*");
|
|
//commentEndExpression = QRegExp("\\*/");
|
|
}
|
|
|
|
|
|
void ConfigHighlighter::highlightBlock(const QString & text) {
|
|
foreach (const HighlightingRule &rule, highlightingRules) {
|
|
QRegExp expression(rule.pattern);
|
|
int index = expression.indexIn(text);
|
|
while (index >= 0) {
|
|
int length = expression.matchedLength();
|
|
setFormat(index, length, rule.format);
|
|
index = expression.indexIn(text, index + length);
|
|
}
|
|
}
|
|
setCurrentBlockState(0);
|
|
|
|
QRegExp expression = QRegExp("[ |\t]");
|
|
int index = expression.indexIn(text);
|
|
while (index >= 0) {
|
|
int length = expression.matchedLength();
|
|
setFormat(index, length, spaceFormat);
|
|
index = expression.indexIn(text, index + length);
|
|
}
|
|
}
|