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