2 * This file is part of NixNote/NeighborNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.gui;
\r
22 import com.trolltech.qt.core.QRegExp;
\r
23 import com.trolltech.qt.core.Qt;
\r
24 import com.trolltech.qt.gui.QBrush;
\r
25 import com.trolltech.qt.gui.QColor;
\r
26 import com.trolltech.qt.gui.QFont;
\r
27 import com.trolltech.qt.gui.QSyntaxHighlighter;
\r
28 import com.trolltech.qt.gui.QTextCharFormat;
\r
29 import com.trolltech.qt.gui.QTextDocument;
\r
31 public class Highlighter extends QSyntaxHighlighter {
\r
33 public class HighlightingRule {
\r
34 public QRegExp pattern;
\r
35 public QTextCharFormat format;
\r
37 public HighlightingRule(QRegExp pattern, QTextCharFormat format) {
\r
38 this.pattern = pattern;
\r
39 this.format = format;
\r
43 public Highlighter(QTextDocument parent) {
\r
48 protected void highlightBlock(String text) {
\r
49 QTextCharFormat format = new QTextCharFormat();
\r
50 QBrush brush = new QBrush(QColor.blue, Qt.BrushStyle.SolidPattern);
\r
51 format.setForeground(brush);
\r
52 format.setFontWeight(QFont.Weight.Bold.value());
\r
54 int index = text.indexOf("<");
\r
55 while (index >= 0) {
\r
56 int length = text.indexOf(">", index)-index+1;
\r
57 setFormat(index, length, format);
\r
58 index = text.indexOf("<", index+1);
\r
60 setCurrentBlockState(0);
\r