1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef TEXTEDITOR_SYNTAXHIGHLIGHTER_H
43 #define TEXTEDITOR_SYNTAXHIGHLIGHTER_H
45 #include "texteditor_global.h"
46 #include <QtCore/qglobal.h>
47 #include <QtCore/qobject.h>
48 #include <QtGui/qtextobject.h>
49 #include <QtGui/QTextLayout>
53 class QSyntaxHighlighterPrivate;
54 class QTextCharFormat;
57 class QTextBlockUserData;
61 namespace TextEditor {
63 class SyntaxHighlighterPrivate;
65 class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject
68 Q_DECLARE_PRIVATE(SyntaxHighlighter)
70 SyntaxHighlighter(QObject *parent);
71 SyntaxHighlighter(QTextDocument *parent);
72 SyntaxHighlighter(QTextEdit *parent);
73 virtual ~SyntaxHighlighter();
75 void setDocument(QTextDocument *doc);
76 QTextDocument *document() const;
78 void setExtraAdditionalFormats(const QTextBlock& block, const QList<QTextLayout::FormatRange> &formats);
82 void rehighlightBlock(const QTextBlock &block);
85 virtual void highlightBlock(const QString &text) = 0;
87 void setFormat(int start, int count, const QTextCharFormat &format);
88 void setFormat(int start, int count, const QColor &color);
89 void setFormat(int start, int count, const QFont &font);
90 QTextCharFormat format(int pos) const;
92 void applyFormatToSpaces(const QString &text, const QTextCharFormat &format);
94 int previousBlockState() const;
95 int currentBlockState() const;
96 void setCurrentBlockState(int newState);
98 void setCurrentBlockUserData(QTextBlockUserData *data);
99 QTextBlockUserData *currentBlockUserData() const;
101 QTextBlock currentBlock() const;
104 Q_DISABLE_COPY(SyntaxHighlighter)
105 Q_PRIVATE_SLOT(d_ptr, void _q_reformatBlocks(int from, int charsRemoved, int charsAdded))
106 Q_PRIVATE_SLOT(d_ptr, void _q_delayedRehighlight())
108 QScopedPointer<SyntaxHighlighterPrivate> d_ptr;
111 } // end of namespace TextEditor
113 #endif // TEXTEDITOR_SYNTAXHIGHLIGHTER_H