1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef SYNTAXHIGHLIGHTER_H |
5 | #define SYNTAXHIGHLIGHTER_H |
6 | |
7 | #include <QtQml/qqmlregistration.h> |
8 | |
9 | #include <QtGui/qsyntaxhighlighter.h> |
10 | #include <QtQuick/qquicktextdocument.h> |
11 | |
12 | #include <QtCore/qpointer.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | class SyntaxHighlighter : public QSyntaxHighlighter |
17 | { |
18 | Q_OBJECT |
19 | Q_PROPERTY(QQuickTextDocument * document READ document WRITE setDocument NOTIFY documentChanged) |
20 | QML_ELEMENT |
21 | public: |
22 | enum BlockState |
23 | { |
24 | None, |
25 | Comment |
26 | }; |
27 | |
28 | explicit SyntaxHighlighter(QObject *p = nullptr); |
29 | |
30 | // Shadows |
31 | QQuickTextDocument *document() const; |
32 | void setDocument(QQuickTextDocument *newDocument); |
33 | |
34 | signals: |
35 | void documentChanged(); |
36 | |
37 | protected: |
38 | void highlightBlock(const QString &text) final; |
39 | QPointer<QQuickTextDocument> m_quickTextDocument; |
40 | QSet<QByteArrayView> m_keywords; |
41 | QSet<QByteArrayView> m_argumentKeywords; |
42 | |
43 | private: |
44 | void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format); |
45 | }; |
46 | |
47 | QT_END_NAMESPACE |
48 | |
49 | #endif // SYNTAXHIGHLIGHTER_H |
50 |