summaryrefslogtreecommitdiffstats
path: root/doc/html/qsyntaxhighlighter.html
blob: a366bc7eadfc3d2ba4730684ad81eb49495b923d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/widgets/qsyntaxhighlighter.cpp:46 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QSyntaxHighlighter Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QSyntaxHighlighter Class Reference</h1>

<p>The QSyntaxHighlighter class is a base class for
implementing QTextEdit syntax highlighters.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qsyntaxhighlighter-h.html">qsyntaxhighlighter.h</a>&gt;</tt>
<p>Inherits <a href="qt.html">Qt</a>.
<p><a href="qsyntaxhighlighter-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QSyntaxHighlighter"><b>QSyntaxHighlighter</b></a> ( QTextEdit&nbsp;*&nbsp;textEdit )</li>
<li class=fn>virtual <a href="#~QSyntaxHighlighter"><b>~QSyntaxHighlighter</b></a> ()</li>
<li class=fn>virtual int <a href="#highlightParagraph"><b>highlightParagraph</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;text, int&nbsp;endStateOfLastPara ) = 0</li>
<li class=fn>void <a href="#setFormat"><b>setFormat</b></a> ( int&nbsp;start, int&nbsp;count, const&nbsp;QFont&nbsp;&amp;&nbsp;font, const&nbsp;QColor&nbsp;&amp;&nbsp;color )</li>
<li class=fn>void <a href="#setFormat-2"><b>setFormat</b></a> ( int&nbsp;start, int&nbsp;count, const&nbsp;QColor&nbsp;&amp;&nbsp;color )</li>
<li class=fn>void <a href="#setFormat-3"><b>setFormat</b></a> ( int&nbsp;start, int&nbsp;count, const&nbsp;QFont&nbsp;&amp;&nbsp;font )</li>
<li class=fn>QTextEdit * <a href="#textEdit"><b>textEdit</b></a> () const</li>
<li class=fn>void <a href="#rehighlight"><b>rehighlight</b></a> ()</li>
<li class=fn>int <a href="#currentParagraph"><b>currentParagraph</b></a> () const</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QSyntaxHighlighter class is a base class for
implementing <a href="qtextedit.html">QTextEdit</a> syntax highlighters.
<p> 

<p> A syntax highligher automatically highlights parts of the text in
a QTextEdit. Syntax highlighters are often used when the user is
entering text in a specific format (for example, source code) and
help the user to read the text and identify syntax errors.
<p> To provide your own syntax highlighting for QTextEdit, you must
subclass QSyntaxHighlighter and reimplement <a href="#highlightParagraph">highlightParagraph</a>().
<p> When you create an instance of your QSyntaxHighlighter subclass,
pass it the QTextEdit that you want the syntax highlighting to be
applied to. After this your highlightParagraph() function will be
called automatically whenever necessary. Use your
highlightParagraph() function to apply formatting (e.g. setting
the font and color) to the text that is passed to it.
<p>See also <a href="basic.html">Basic Widgets</a> and <a href="text.html">Text Related Classes</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QSyntaxHighlighter"></a>QSyntaxHighlighter::QSyntaxHighlighter ( <a href="qtextedit.html">QTextEdit</a>&nbsp;*&nbsp;textEdit )
</h3>
Constructs the QSyntaxHighlighter and installs it on <em>textEdit</em>.
<p> It is the caller's responsibility to delete the
QSyntaxHighlighter when it is no longer needed.

<h3 class=fn><a name="~QSyntaxHighlighter"></a>QSyntaxHighlighter::~QSyntaxHighlighter ()<tt> [virtual]</tt>
</h3>
Destructor. Uninstalls this syntax highlighter from the <a href="#textEdit">textEdit</a>()

<h3 class=fn>int <a name="currentParagraph"></a>QSyntaxHighlighter::currentParagraph () const
</h3>
Returns the id of the paragraph which is highlighted, or -1 of no
paragraph is currently highlighted.
<p> Usually this function is called from within <a href="#highlightParagraph">highlightParagraph</a>().

<h3 class=fn>int <a name="highlightParagraph"></a>QSyntaxHighlighter::highlightParagraph ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text, int&nbsp;endStateOfLastPara )<tt> [pure virtual]</tt>
</h3>

<p> This function is called when necessary by the rich text engine,
i.e. on paragraphs which have changed.
<p> In your reimplementation you should parse the paragraph's <em>text</em>
and call <a href="#setFormat">setFormat</a>() as often as necessary to apply any font and
color changes that you require. Your function must return a value
which indicates the paragraph's end state: see below.
<p> Some syntaxes can have constructs that span paragraphs. For
example, a C++ syntax highlighter should be able to cope with
<tt>/</tt><tt>*...*</tt><tt>/</tt> comments that span paragraphs. To deal
with these cases it is necessary to know the end state of the
previous paragraph (e.g. "in comment").
<p> If your syntax does not have paragraph spanning constructs, simply
ignore the <em>endStateOfLastPara</em> parameter and always return 0.
<p> Whenever <a href="#highlightParagraph">highlightParagraph</a>() is called it is passed a value for
<em>endStateOfLastPara</em>. For the very first paragraph this value is
always -2. For any other paragraph the value is the value returned
by the most recent highlightParagraph() call that applied to the
preceding paragraph.
<p> The value you return is up to you. We recommend only returning 0
(to signify that this paragraph's syntax highlighting does not
affect the following paragraph), or a positive integer (to signify
that this paragraph has ended in the middle of a paragraph
spanning construct).
<p> To find out which paragraph is highlighted, call
<a href="#currentParagraph">currentParagraph</a>().
<p> For example, if you're writing a simple C++ syntax highlighter,
you might designate 1 to signify "in comment". For a paragraph
that ended in the middle of a comment you'd return 1, and for
other paragraphs you'd return 0. In your parsing code if <em>endStateOfLastPara</em> was 1, you would highlight the text as a C++
comment until you reached the closing <tt>*</tt><tt>/</tt>.

<h3 class=fn>void <a name="rehighlight"></a>QSyntaxHighlighter::rehighlight ()
</h3>  Redoes the highlighting of the whole document.

<h3 class=fn>void <a name="setFormat"></a>QSyntaxHighlighter::setFormat ( int&nbsp;start, int&nbsp;count, const&nbsp;<a href="qfont.html">QFont</a>&nbsp;&amp;&nbsp;font, const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;color )
</h3>
This function is applied to the syntax highlighter's current
paragraph (the text of which is passed to the <a href="#highlightParagraph">highlightParagraph</a>()
function).
<p> The specified <em>font</em> and <em>color</em> are applied to the text from
position <em>start</em> for <em>count</em> characters. (If <em>count</em> is 0,
nothing is done.)

<h3 class=fn>void <a name="setFormat-2"></a>QSyntaxHighlighter::setFormat ( int&nbsp;start, int&nbsp;count, const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;color )
</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

<h3 class=fn>void <a name="setFormat-3"></a>QSyntaxHighlighter::setFormat ( int&nbsp;start, int&nbsp;count, const&nbsp;<a href="qfont.html">QFont</a>&nbsp;&amp;&nbsp;font )
</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

<h3 class=fn><a href="qtextedit.html">QTextEdit</a>&nbsp;* <a name="textEdit"></a>QSyntaxHighlighter::textEdit () const
</h3>

<p> Returns the <a href="qtextedit.html">QTextEdit</a> on which this syntax highlighter is
installed

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>