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 | class SyntaxHighlighter : public QSyntaxHighlighter |
12 | { |
13 | Q_OBJECT |
14 | Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged) |
15 | QML_ELEMENT |
16 | public: |
17 | enum BlockState |
18 | { |
19 | None, |
20 | Comment |
21 | }; |
22 | |
23 | explicit SyntaxHighlighter(QObject *p = nullptr); |
24 | |
25 | // Shadows |
26 | QQuickTextDocument *document() const; |
27 | void setDocument(QQuickTextDocument *newDocument); |
28 | |
29 | signals: |
30 | void documentChanged(); |
31 | |
32 | protected: |
33 | void highlightBlock(const QString &text) final; |
34 | QPointer<QQuickTextDocument> m_quickTextDocument; |
35 | QSet<QByteArrayView> m_tagKeywords; |
36 | QSet<QByteArrayView> m_argumentKeywords; |
37 | |
38 | private: |
39 | void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format); |
40 | }; |
41 | |
42 | #endif // SYNTAXHIGHLIGHTER_H |
43 |