[190] | 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"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { 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 Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main 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 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
|
---|
| 35 | implementing QTextEdit syntax highlighters.
|
---|
| 36 | <a href="#details">More...</a>
|
---|
| 37 | <p><tt>#include <<a href="qsyntaxhighlighter-h.html">qsyntaxhighlighter.h</a>></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 * 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 QString & text, int endStateOfLastPara ) = 0</li>
|
---|
| 45 | <li class=fn>void <a href="#setFormat"><b>setFormat</b></a> ( int start, int count, const QFont & font, const QColor & color )</li>
|
---|
| 46 | <li class=fn>void <a href="#setFormat-2"><b>setFormat</b></a> ( int start, int count, const QColor & color )</li>
|
---|
| 47 | <li class=fn>void <a href="#setFormat-3"><b>setFormat</b></a> ( int start, int count, const QFont & 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 |
|
---|
| 55 | The QSyntaxHighlighter class is a base class for
|
---|
| 56 | implementing <a href="qtextedit.html">QTextEdit</a> syntax highlighters.
|
---|
| 57 | <p>
|
---|
| 58 |
|
---|
| 59 | <p> A syntax highligher automatically highlights parts of the text in
|
---|
| 60 | a QTextEdit. Syntax highlighters are often used when the user is
|
---|
| 61 | entering text in a specific format (for example, source code) and
|
---|
| 62 | help the user to read the text and identify syntax errors.
|
---|
| 63 | <p> To provide your own syntax highlighting for QTextEdit, you must
|
---|
| 64 | subclass QSyntaxHighlighter and reimplement <a href="#highlightParagraph">highlightParagraph</a>().
|
---|
| 65 | <p> When you create an instance of your QSyntaxHighlighter subclass,
|
---|
| 66 | pass it the QTextEdit that you want the syntax highlighting to be
|
---|
| 67 | applied to. After this your highlightParagraph() function will be
|
---|
| 68 | called automatically whenever necessary. Use your
|
---|
| 69 | highlightParagraph() function to apply formatting (e.g. setting
|
---|
| 70 | the 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> * textEdit )
|
---|
| 75 | </h3>
|
---|
| 76 | Constructs the QSyntaxHighlighter and installs it on <em>textEdit</em>.
|
---|
| 77 | <p> It is the caller's responsibility to delete the
|
---|
| 78 | QSyntaxHighlighter when it is no longer needed.
|
---|
| 79 |
|
---|
| 80 | <h3 class=fn><a name="~QSyntaxHighlighter"></a>QSyntaxHighlighter::~QSyntaxHighlighter ()<tt> [virtual]</tt>
|
---|
| 81 | </h3>
|
---|
| 82 | Destructor. 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>
|
---|
| 86 | Returns the id of the paragraph which is highlighted, or -1 of no
|
---|
| 87 | paragraph 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 <a href="qstring.html">QString</a> & text, int endStateOfLastPara )<tt> [pure virtual]</tt>
|
---|
| 91 | </h3>
|
---|
| 92 |
|
---|
| 93 | <p> This function is called when necessary by the rich text engine,
|
---|
| 94 | i.e. on paragraphs which have changed.
|
---|
| 95 | <p> In your reimplementation you should parse the paragraph's <em>text</em>
|
---|
| 96 | and call <a href="#setFormat">setFormat</a>() as often as necessary to apply any font and
|
---|
| 97 | color changes that you require. Your function must return a value
|
---|
| 98 | which indicates the paragraph's end state: see below.
|
---|
| 99 | <p> Some syntaxes can have constructs that span paragraphs. For
|
---|
| 100 | example, a C++ syntax highlighter should be able to cope with
|
---|
| 101 | <tt>/</tt><tt>*...*</tt><tt>/</tt> comments that span paragraphs. To deal
|
---|
| 102 | with these cases it is necessary to know the end state of the
|
---|
| 103 | previous paragraph (e.g. "in comment").
|
---|
| 104 | <p> If your syntax does not have paragraph spanning constructs, simply
|
---|
| 105 | ignore 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
|
---|
| 108 | always -2. For any other paragraph the value is the value returned
|
---|
| 109 | by the most recent highlightParagraph() call that applied to the
|
---|
| 110 | preceding 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
|
---|
| 113 | affect the following paragraph), or a positive integer (to signify
|
---|
| 114 | that this paragraph has ended in the middle of a paragraph
|
---|
| 115 | spanning 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,
|
---|
| 119 | you might designate 1 to signify "in comment". For a paragraph
|
---|
| 120 | that ended in the middle of a comment you'd return 1, and for
|
---|
| 121 | other paragraphs you'd return 0. In your parsing code if <em>endStateOfLastPara</em> was 1, you would highlight the text as a C++
|
---|
| 122 | comment 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 start, int count, const <a href="qfont.html">QFont</a> & font, const <a href="qcolor.html">QColor</a> & color )
|
---|
| 128 | </h3>
|
---|
| 129 | This function is applied to the syntax highlighter's current
|
---|
| 130 | paragraph (the text of which is passed to the <a href="#highlightParagraph">highlightParagraph</a>()
|
---|
| 131 | function).
|
---|
| 132 | <p> The specified <em>font</em> and <em>color</em> are applied to the text from
|
---|
| 133 | position <em>start</em> for <em>count</em> characters. (If <em>count</em> is 0,
|
---|
| 134 | nothing is done.)
|
---|
| 135 |
|
---|
| 136 | <h3 class=fn>void <a name="setFormat-2"></a>QSyntaxHighlighter::setFormat ( int start, int count, const <a href="qcolor.html">QColor</a> & 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 start, int count, const <a href="qfont.html">QFont</a> & 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> * <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
|
---|
| 146 | installed
|
---|
| 147 |
|
---|
| 148 | <!-- eof -->
|
---|
| 149 | <hr><p>
|
---|
| 150 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
| 151 | Copyright © 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 © 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>
|
---|