1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QSYNTAXHIGHLIGHTER_H |
5 | #define QSYNTAXHIGHLIGHTER_H |
6 | |
7 | #include <QtGui/qtguiglobal.h> |
8 | |
9 | #ifndef QT_NO_SYNTAXHIGHLIGHTER |
10 | |
11 | #include <QtCore/qobject.h> |
12 | #include <QtGui/qtextobject.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | |
17 | class QTextDocument; |
18 | class QSyntaxHighlighterPrivate; |
19 | class QTextCharFormat; |
20 | class QFont; |
21 | class QColor; |
22 | class QTextBlockUserData; |
23 | |
24 | class Q_GUI_EXPORT QSyntaxHighlighter : public QObject |
25 | { |
26 | Q_OBJECT |
27 | Q_DECLARE_PRIVATE(QSyntaxHighlighter) |
28 | public: |
29 | explicit QSyntaxHighlighter(QObject *parent); |
30 | explicit QSyntaxHighlighter(QTextDocument *parent); |
31 | ~QSyntaxHighlighter(); |
32 | |
33 | void setDocument(QTextDocument *doc); |
34 | QTextDocument *document() const; |
35 | |
36 | public Q_SLOTS: |
37 | void rehighlight(); |
38 | void rehighlightBlock(const QTextBlock &block); |
39 | |
40 | protected: |
41 | virtual void highlightBlock(const QString &text) = 0; |
42 | |
43 | void setFormat(int start, int count, const QTextCharFormat &format); |
44 | void setFormat(int start, int count, const QColor &color); |
45 | void setFormat(int start, int count, const QFont &font); |
46 | QTextCharFormat format(int pos) const; |
47 | |
48 | int previousBlockState() const; |
49 | int currentBlockState() const; |
50 | void setCurrentBlockState(int newState); |
51 | |
52 | void setCurrentBlockUserData(QTextBlockUserData *data); |
53 | QTextBlockUserData *currentBlockUserData() const; |
54 | |
55 | QTextBlock currentBlock() const; |
56 | |
57 | private: |
58 | Q_DISABLE_COPY(QSyntaxHighlighter) |
59 | Q_PRIVATE_SLOT(d_func(), void _q_reformatBlocks(int from, int charsRemoved, int charsAdded)) |
60 | Q_PRIVATE_SLOT(d_func(), void _q_delayedRehighlight()) |
61 | }; |
62 | |
63 | QT_END_NAMESPACE |
64 | |
65 | #endif // QT_NO_SYNTAXHIGHLIGHTER |
66 | |
67 | #endif // QSYNTAXHIGHLIGHTER_H |
68 | |