00001 00008 #include <QtGui> 00009 #include "highlighter.h" 00010 00011 00017 Highlighter::Highlighter(QTextDocument *parent) 00018 : QSyntaxHighlighter(parent) 00019 { 00020 HighlightingRule rule; 00021 00022 // PBS options 00023 PBSFormat.setForeground(Qt::darkBlue); 00024 PBSFormat.setFontWeight(QFont::Bold); 00025 rule.pattern = QRegExp("^(?: |\t)*#PBS [^\\n]*"); 00026 rule.format = PBSFormat; 00027 highlightingRules.append(rule); 00028 00029 // PBS vars 00030 PBSVarFormat.setForeground(Qt::darkRed); 00031 PBSVarFormat.setFontWeight(QFont::Bold); 00032 rule.pattern = QRegExp("[$]PBS_\\S*"); 00033 rule.format = PBSVarFormat; 00034 highlightingRules.append(rule); 00035 } 00036 00037 00043 void Highlighter::highlightBlock(const QString &text) 00044 { 00045 foreach (HighlightingRule rule, highlightingRules) { 00046 QRegExp expression(rule.pattern); 00047 int index = text.indexOf(expression); 00048 while (index >= 0) { 00049 int length = expression.matchedLength(); 00050 setFormat(index, length, rule.format); 00051 index = text.indexOf(expression, index + length); 00052 } 00053 } 00054 }