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

source code of qtquick3d/tools/materialeditor/syntaxhighlighter.h