summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqsyntaxhighlighter.3qt
blob: 058be188eb3c2eb6edf3dabcaf3c128fae5a64e3 (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
'\" t
.TH QSyntaxHighlighter 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QSyntaxHighlighter \- Base class for implementing TQTextEdit syntax highlighters
.SH SYNOPSIS
\fC#include <ntqsyntaxhighlighter.h>\fR
.PP
Inherits Qt.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQSyntaxHighlighter\fR ( TQTextEdit * textEdit )"
.br
.ti -1c
.BI "virtual \fB~QSyntaxHighlighter\fR ()"
.br
.ti -1c
.BI "virtual int \fBhighlightParagraph\fR ( const TQString & text, int endStateOfLastPara ) = 0"
.br
.ti -1c
.BI "void \fBsetFormat\fR ( int start, int count, const TQFont & font, const TQColor & color )"
.br
.ti -1c
.BI "void \fBsetFormat\fR ( int start, int count, const TQColor & color )"
.br
.ti -1c
.BI "void \fBsetFormat\fR ( int start, int count, const TQFont & font )"
.br
.ti -1c
.BI "TQTextEdit * \fBtextEdit\fR () const"
.br
.ti -1c
.BI "void \fBrehighlight\fR ()"
.br
.ti -1c
.BI "int \fBcurrentParagraph\fR () const"
.br
.in -1c
.SH DESCRIPTION
The QSyntaxHighlighter class is a base class for implementing TQTextEdit syntax highlighters.
.PP
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.
.PP
To provide your own syntax highlighting for TQTextEdit, you must subclass QSyntaxHighlighter and reimplement highlightParagraph().
.PP
When you create an instance of your QSyntaxHighlighter 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.
.PP
See also Basic Widgets and Text Related Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QSyntaxHighlighter::QSyntaxHighlighter ( TQTextEdit * textEdit )"
Constructs the QSyntaxHighlighter and installs it on \fItextEdit\fR.
.PP
It is the caller's responsibility to delete the QSyntaxHighlighter when it is no longer needed.
.SH "QSyntaxHighlighter::~QSyntaxHighlighter ()\fC [virtual]\fR"
Destructor. Uninstalls this syntax highlighter from the textEdit()
.SH "int QSyntaxHighlighter::currentParagraph () const"
Returns the id of the paragraph which is highlighted, or -1 of no paragraph is currently highlighted.
.PP
Usually this function is called from within highlightParagraph().
.SH "int QSyntaxHighlighter::highlightParagraph ( const TQString & text, int endStateOfLastPara )\fC [pure virtual]\fR"
This function is called when necessary by the rich text engine, i.e. on paragraphs which have changed.
.PP
In your reimplementation you should parse the paragraph's \fItext\fR and call setFormat() 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.
.PP
Some syntaxes can have constructs that span paragraphs. For example, a C++ syntax highlighter should be able to cope with \fC/\fR\fC*...*\fR\fC/\fR 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").
.PP
If your syntax does not have paragraph spanning constructs, simply ignore the \fIendStateOfLastPara\fR parameter and always return 0.
.PP
Whenever highlightParagraph() is called it is passed a value for \fIendStateOfLastPara\fR. 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.
.PP
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).
.PP
To find out which paragraph is highlighted, call currentParagraph().
.PP
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 \fIendStateOfLastPara\fR was 1, you would highlight the text as a C++ comment until you reached the closing \fC*\fR\fC/\fR.
.SH "void QSyntaxHighlighter::rehighlight ()"
Redoes the highlighting of the whole document.
.SH "void QSyntaxHighlighter::setFormat ( int start, int count, const TQFont & font, const TQColor & color )"
This function is applied to the syntax highlighter's current paragraph (the text of which is passed to the highlightParagraph() function).
.PP
The specified \fIfont\fR and \fIcolor\fR are applied to the text from position \fIstart\fR for \fIcount\fR characters. (If \fIcount\fR is 0, nothing is done.)
.SH "void QSyntaxHighlighter::setFormat ( int start, int count, const TQColor & color )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QSyntaxHighlighter::setFormat ( int start, int count, const TQFont & font )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "TQTextEdit * QSyntaxHighlighter::textEdit () const"
Returns the TQTextEdit on which this syntax highlighter is
installed

.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqsyntaxhighlighter.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqsyntaxhighlighter.3qt) and the Qt
version (3.3.8).