source: trunk/doc/html/qsyntaxhighlighter.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 8.8 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/widgets/qsyntaxhighlighter.cpp:46 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QSyntaxHighlighter Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<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>
33
34<p>The QSyntaxHighlighter class is a base class for
35implementing QTextEdit syntax highlighters.
36<a href="#details">More...</a>
37<p><tt>#include &lt;<a href="qsyntaxhighlighter-h.html">qsyntaxhighlighter.h</a>&gt;</tt>
38<p>Inherits <a href="qt.html">Qt</a>.
39<p><a href="qsyntaxhighlighter-members.html">List of all member functions.</a>
40<h2>Public Members</h2>
41<ul>
42<li class=fn><a href="#QSyntaxHighlighter"><b>QSyntaxHighlighter</b></a> ( QTextEdit&nbsp;*&nbsp;textEdit )</li>
43<li class=fn>virtual <a href="#~QSyntaxHighlighter"><b>~QSyntaxHighlighter</b></a> ()</li>
44<li class=fn>virtual int <a href="#highlightParagraph"><b>highlightParagraph</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;text, int&nbsp;endStateOfLastPara ) = 0</li>
45<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>
46<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>
47<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>
48<li class=fn>QTextEdit * <a href="#textEdit"><b>textEdit</b></a> () const</li>
49<li class=fn>void <a href="#rehighlight"><b>rehighlight</b></a> ()</li>
50<li class=fn>int <a href="#currentParagraph"><b>currentParagraph</b></a> () const</li>
51</ul>
52<hr><a name="details"></a><h2>Detailed Description</h2>
53
54
55The QSyntaxHighlighter class is a base class for
56implementing <a href="qtextedit.html">QTextEdit</a> syntax highlighters.
57<p>
58
59<p> A syntax highligher automatically highlights parts of the text in
60a QTextEdit. Syntax highlighters are often used when the user is
61entering text in a specific format (for example, source code) and
62help the user to read the text and identify syntax errors.
63<p> To provide your own syntax highlighting for QTextEdit, you must
64subclass QSyntaxHighlighter and reimplement <a href="#highlightParagraph">highlightParagraph</a>().
65<p> When you create an instance of your QSyntaxHighlighter subclass,
66pass it the QTextEdit that you want the syntax highlighting to be
67applied to. After this your highlightParagraph() function will be
68called automatically whenever necessary. Use your
69highlightParagraph() function to apply formatting (e.g. setting
70the font and color) to the text that is passed to it.
71<p>See also <a href="basic.html">Basic Widgets</a> and <a href="text.html">Text Related Classes</a>.
72
73<hr><h2>Member Function Documentation</h2>
74<h3 class=fn><a name="QSyntaxHighlighter"></a>QSyntaxHighlighter::QSyntaxHighlighter ( <a href="qtextedit.html">QTextEdit</a>&nbsp;*&nbsp;textEdit )
75</h3>
76Constructs the QSyntaxHighlighter and installs it on <em>textEdit</em>.
77<p> It is the caller's responsibility to delete the
78QSyntaxHighlighter when it is no longer needed.
79
80<h3 class=fn><a name="~QSyntaxHighlighter"></a>QSyntaxHighlighter::~QSyntaxHighlighter ()<tt> [virtual]</tt>
81</h3>
82Destructor. Uninstalls this syntax highlighter from the <a href="#textEdit">textEdit</a>()
83
84<h3 class=fn>int <a name="currentParagraph"></a>QSyntaxHighlighter::currentParagraph () const
85</h3>
86Returns the id of the paragraph which is highlighted, or -1 of no
87paragraph is currently highlighted.
88<p> Usually this function is called from within <a href="#highlightParagraph">highlightParagraph</a>().
89
90<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>
91</h3>
92
93<p> This function is called when necessary by the rich text engine,
94i.e. on paragraphs which have changed.
95<p> In your reimplementation you should parse the paragraph's <em>text</em>
96and call <a href="#setFormat">setFormat</a>() as often as necessary to apply any font and
97color changes that you require. Your function must return a value
98which indicates the paragraph's end state: see below.
99<p> Some syntaxes can have constructs that span paragraphs. For
100example, a C++ syntax highlighter should be able to cope with
101<tt>/</tt><tt>*...*</tt><tt>/</tt> comments that span paragraphs. To deal
102with these cases it is necessary to know the end state of the
103previous paragraph (e.g. "in comment").
104<p> If your syntax does not have paragraph spanning constructs, simply
105ignore the <em>endStateOfLastPara</em> parameter and always return 0.
106<p> Whenever <a href="#highlightParagraph">highlightParagraph</a>() is called it is passed a value for
107<em>endStateOfLastPara</em>. For the very first paragraph this value is
108always -2. For any other paragraph the value is the value returned
109by the most recent highlightParagraph() call that applied to the
110preceding paragraph.
111<p> The value you return is up to you. We recommend only returning 0
112(to signify that this paragraph's syntax highlighting does not
113affect the following paragraph), or a positive integer (to signify
114that this paragraph has ended in the middle of a paragraph
115spanning construct).
116<p> To find out which paragraph is highlighted, call
117<a href="#currentParagraph">currentParagraph</a>().
118<p> For example, if you're writing a simple C++ syntax highlighter,
119you might designate 1 to signify "in comment". For a paragraph
120that ended in the middle of a comment you'd return 1, and for
121other paragraphs you'd return 0. In your parsing code if <em>endStateOfLastPara</em> was 1, you would highlight the text as a C++
122comment until you reached the closing <tt>*</tt><tt>/</tt>.
123
124<h3 class=fn>void <a name="rehighlight"></a>QSyntaxHighlighter::rehighlight ()
125</h3> Redoes the highlighting of the whole document.
126
127<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 )
128</h3>
129This function is applied to the syntax highlighter's current
130paragraph (the text of which is passed to the <a href="#highlightParagraph">highlightParagraph</a>()
131function).
132<p> The specified <em>font</em> and <em>color</em> are applied to the text from
133position <em>start</em> for <em>count</em> characters. (If <em>count</em> is 0,
134nothing is done.)
135
136<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 )
137</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
138
139<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 )
140</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
141
142<h3 class=fn><a href="qtextedit.html">QTextEdit</a>&nbsp;* <a name="textEdit"></a>QSyntaxHighlighter::textEdit () const
143</h3>
144
145<p> Returns the <a href="qtextedit.html">QTextEdit</a> on which this syntax highlighter is
146installed
147
148<!-- eof -->
149<hr><p>
150This file is part of the <a href="index.html">Qt toolkit</a>.
151Copyright &copy; 1995-2007
152<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
153<table width=100% cellspacing=0 border=0><tr>
154<td>Copyright &copy; 2007
155<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
156<td align=right><div align=right>Qt 3.3.8</div>
157</table></div></address></body>
158</html>
Note: See TracBrowser for help on using the repository browser.