OSDN Git Service

コピーライトの表示を修正。
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / Highlighter.java
1 /*\r
2  * This file is part of NixNote/NeighborNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\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
12  *\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
17  *\r
18  */\r
19 \r
20 package cx.fbn.nevernote.gui;\r
21 \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
30 \r
31 public class Highlighter extends QSyntaxHighlighter {\r
32         \r
33         public class HighlightingRule {\r
34                 public QRegExp pattern;\r
35                 public QTextCharFormat format;\r
36                 \r
37                 public HighlightingRule(QRegExp pattern, QTextCharFormat format) {\r
38                         this.pattern = pattern;\r
39                         this.format = format;\r
40                 }\r
41         }\r
42 \r
43         public Highlighter(QTextDocument parent)  {\r
44                 super(parent);\r
45         }\r
46 \r
47         @Override\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
53                 \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
59                 }\r
60                 setCurrentBlockState(0);\r
61         }\r
62 \r
63 \r
64 }\r