1 /***************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Qt Software Information (qt-info@nokia.com)
10 ** Non-Open Source Usage
12 ** Licensees may use this file in accordance with the Qt Beta Version
13 ** License Agreement, Agreement version 2.2 provided with the Software or,
14 ** alternatively, in accordance with the terms contained in a written
15 ** agreement between you and Nokia.
17 ** GNU General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU General
20 ** Public License versions 2.0 or 3.0 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.GPL included in the packaging
22 ** of this file. Please review the following information to ensure GNU
23 ** General Public Licensing requirements will be met:
25 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
26 ** http://www.gnu.org/copyleft/gpl.html.
28 ** In addition, as a special exception, Nokia gives you certain additional
29 ** rights. These rights are described in the Nokia Qt GPL Exception
30 ** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
32 ***************************************************************************/
34 #ifndef QSCRIPTSYNTAXHIGHLIGHTER_H
35 #define QSCRIPTSYNTAXHIGHLIGHTER_H
38 #include <QtGui/QSyntaxHighlighter>
40 namespace SharedTools
{
42 class QScriptHighlighter
: public QSyntaxHighlighter
46 QScriptHighlighter(QTextDocument
*parent
= 0);
47 virtual void highlightBlock(const QString
&text
);
49 enum { NumberFormat
, StringFormat
, TypeFormat
,
50 KeywordFormat
, PreProcessorFormat
, LabelFormat
, CommentFormat
,
53 // MS VC 6 compatible, still.
54 void setFormats(const QVector
<QTextCharFormat
> &s
);
55 static const QVector
<QTextCharFormat
> &defaultFormats();
58 // The functions are notified whenever parentheses are encountered.
59 // Custom behaviour can be added, for example storing info for indenting.
60 virtual int onBlockStart(); // returns the blocks initial state
61 virtual void onOpeningParenthesis(QChar parenthesis
, int pos
);
62 virtual void onClosingParenthesis(QChar parenthesis
, int pos
);
63 // sets the enriched user state, or simply calls setCurrentBlockState(state);
64 virtual void onBlockEnd(int state
, int firstNonSpace
);
66 void highlightKeyword(int currentPos
, const QString
&buffer
);
68 QTextCharFormat m_formats
[NumFormats
];
71 } // namespace SharedTools
73 #endif // QSCRIPTSYNTAXHIGHLIGHTER_H