1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Rostilav Checkan
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <QTextCharFormat>
24 #include "qsyntaxer.h"
26 QSyntaxer::QSyntaxer(QTextDocument
*parent
)
27 : QSyntaxHighlighter(parent
) {
28 HighlightingRule rule
;
30 hrules
[0].pattern
= QRegExp("%[^\\| \n<\\?%]{1,2}");
31 hrules
[0].format
.setFontWeight(QFont::Bold
);
32 hrules
[0].format
.setForeground(Qt::darkBlue
);
35 hrules
[1].pattern
= QRegExp("%[\\?]{1}[^<]{1,2}");
36 hrules
[1].format
.setForeground(Qt::darkMagenta
);
38 hrules
[2].pattern
= QRegExp("(<|>)");
39 hrules
[2].format
.setForeground(Qt::red
);
41 hrules
[3].pattern
= QRegExp("\\|");
42 hrules
[3].format
.setForeground(Qt::darkRed
);
44 hrules
[4].pattern
= QRegExp("#[^\n]*");
45 hrules
[4].format
.setForeground(Qt::darkGreen
);
46 hrules
[4].format
.setFontItalic(true);
49 void QSyntaxer::highlightBlock(const QString
&text
) {
50 QTextCharFormat wholeText
;
51 wholeText
.setFont(QFont("arial",11,QFont::Normal
));
52 setFormat(0,text
.length(),wholeText
);
54 foreach (HighlightingRule rule
, hrules
) {
55 QRegExp
expression(rule
.pattern
);
56 int index
= text
.indexOf(expression
);
58 int length
= expression
.matchedLength();
59 setFormat(index
, length
, rule
.format
);
60 index
= text
.indexOf(expression
, index
+ length
);