<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1" >
< title > TQSyntaxHighlighter 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 Classes< / font > < / a >
| < a href = "mainclasses.html" >
< font color = "#004faf" > Main Classes< / font > < / a >
| < a href = "annotated.html" >
< font color = "#004faf" > Annotated< / font > < / a >
| < a href = "groups.html" >
< font color = "#004faf" > Grouped 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 > TQSyntaxHighlighter Class Reference< / h1 >
< p > The TQSyntaxHighlighter class is a base class for
implementing TQTextEdit syntax highlighters.
< a href = "#details" > More...< / a >
< p > < tt > #include < < a href = "tqsyntaxhighlighter-h.html" > tqsyntaxhighlighter.h< / a > > < / tt >
< p > Inherits < a href = "tqt.html" > TQt< / a > .
< p > < a href = "tqsyntaxhighlighter-members.html" > List of all member functions.< / a >
< h2 > Public Members< / h2 >
< ul >
< li class = fn > < a href = "#TQSyntaxHighlighter" > < b > TQSyntaxHighlighter< / b > < / a > ( TQTextEdit * textEdit )< / li >
< li class = fn > virtual < a href = "#~TQSyntaxHighlighter" > < b > ~TQSyntaxHighlighter< / b > < / a > ()< / li >
< li class = fn > virtual int < a href = "#highlightParagraph" > < b > highlightParagraph< / b > < / a > ( const TQString & text, int endStateOfLastPara ) = 0< / li >
< li class = fn > void < a href = "#setFormat" > < b > setFormat< / b > < / a > ( int start, int count, const TQFont & font, const TQColor & color )< / li >
< li class = fn > void < a href = "#setFormat-2" > < b > setFormat< / b > < / a > ( int start, int count, const TQColor & color )< / li >
< li class = fn > void < a href = "#setFormat-3" > < b > setFormat< / b > < / a > ( int start, int count, const TQFont & font )< / li >
< li class = fn > TQTextEdit * < 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 TQSyntaxHighlighter class is a base class for
implementing < a href = "tqtextedit.html" > TQTextEdit< / a > syntax highlighters.
< p >
< p > A syntax highligher automatically highlights parts of the text in
a TQTextEdit. 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 TQTextEdit, you must
subclass TQSyntaxHighlighter and reimplement < a href = "#highlightParagraph" > highlightParagraph< / a > ().
< p > When you create an instance of your TQSyntaxHighlighter subclass,
pass it the TQTextEdit 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 = "TQSyntaxHighlighter" > < / a > TQSyntaxHighlighter::TQSyntaxHighlighter ( < a href = "tqtextedit.html" > TQTextEdit< / a > * textEdit )
< / h3 >
Constructs the TQSyntaxHighlighter and installs it on < em > textEdit< / em > .
< p > It is the caller's responsibility to delete the
TQSyntaxHighlighter when it is no longer needed.
< h3 class = fn > < a name = "~TQSyntaxHighlighter" > < / a > TQSyntaxHighlighter::~TQSyntaxHighlighter ()< tt > [virtual]< / tt >
< / h3 >
Destructor. Uninstalls this syntax highlighter from the < a href = "#textEdit" > textEdit< / a > ()
< h3 class = fn > int < a name = "currentParagraph" > < / a > TQSyntaxHighlighter::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 > TQSyntaxHighlighter::highlightParagraph ( const < a href = "tqstring.html" > TQString< / a > & text, int 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 > TQSyntaxHighlighter::rehighlight ()
< / h3 > Redoes the highlighting of the whole document.
< h3 class = fn > void < a name = "setFormat" > < / a > TQSyntaxHighlighter::setFormat ( int start, int count, const < a href = "tqfont.html" > TQFont< / a > & font, const < a href = "tqcolor.html" > TQColor< / a > & 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 > TQSyntaxHighlighter::setFormat ( int start, int count, const < a href = "tqcolor.html" > TQColor< / a > & 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 > TQSyntaxHighlighter::setFormat ( int start, int count, const < a href = "tqfont.html" > TQFont< / a > & font )
< / h3 > This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
< h3 class = fn > < a href = "tqtextedit.html" > TQTextEdit< / a > * < a name = "textEdit" > < / a > TQSyntaxHighlighter::textEdit () const
< / h3 >
< p > Returns the < a href = "tqtextedit.html" > TQTextEdit< / a > on which this syntax highlighter is
installed
<!-- eof -->
< hr > < p >
This file is part of the < a href = "index.html" > TQt toolkit< / a > .
Copyright © 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 © 2007
< a href = "troll.html" > Trolltech< / a > < td align = center > < a href = "trademarks.html" > Trademarks< / a >
< td align = right > < div align = right > TQt 3.3.8< / div >
< / table > < / div > < / address > < / body >
< / html >