1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
9 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
14 ** Please review the following information to ensure the GNU Lesser General
15 ** Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
24 ** Alternatively, this file may be used in accordance with the terms and
25 ** conditions contained in a signed written agreement between you and Nokia.
27 ** If you have questions regarding the use of this file, please contact
28 ** Nokia at qt-info@nokia.com.
30 **************************************************************************/
32 #ifndef TEXTEDITOR_SYNTAXHIGHLIGHTER_H
33 #define TEXTEDITOR_SYNTAXHIGHLIGHTER_H
35 #include "texteditor_global.h"
37 #include <QtCore/QObject>
38 #include <QtGui/QTextLayout>
42 class QSyntaxHighlighterPrivate;
43 class QTextCharFormat;
46 class QTextBlockUserData;
50 namespace TextEditor {
52 class SyntaxHighlighterPrivate;
54 class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject
57 Q_DECLARE_PRIVATE(SyntaxHighlighter)
59 SyntaxHighlighter(QObject *parent);
60 SyntaxHighlighter(QTextDocument *parent);
61 SyntaxHighlighter(QTextEdit *parent);
62 virtual ~SyntaxHighlighter();
64 void setDocument(QTextDocument *doc);
65 QTextDocument *document() const;
67 void setExtraAdditionalFormats(const QTextBlock& block, const QList<QTextLayout::FormatRange> &formats);
71 void rehighlightBlock(const QTextBlock &block);
74 virtual void highlightBlock(const QString &text) = 0;
76 void setFormat(int start, int count, const QTextCharFormat &format);
77 void setFormat(int start, int count, const QColor &color);
78 void setFormat(int start, int count, const QFont &font);
79 QTextCharFormat format(int pos) const;
81 void applyFormatToSpaces(const QString &text, const QTextCharFormat &format);
83 int previousBlockState() const;
84 int currentBlockState() const;
85 void setCurrentBlockState(int newState);
87 void setCurrentBlockUserData(QTextBlockUserData *data);
88 QTextBlockUserData *currentBlockUserData() const;
90 QTextBlock currentBlock() const;
93 Q_DISABLE_COPY(SyntaxHighlighter)
94 Q_PRIVATE_SLOT(d_ptr, void _q_reformatBlocks(int from, int charsRemoved, int charsAdded))
95 Q_PRIVATE_SLOT(d_ptr, void _q_delayedRehighlight())
97 QScopedPointer<SyntaxHighlighterPrivate> d_ptr;
100 } // namespace TextEditor
102 #endif // TEXTEDITOR_SYNTAXHIGHLIGHTER_H