blob: e5b0e0409daa6da857be35fd8c8bb4f7b2976f83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "qmljseditor_global.h"
#include <qmljs/qmljsscanner.h>
#include <texteditor/textdocumentlayout.h>
#include <texteditor/syntaxhighlighter.h>
namespace QmlJSEditor {
class QMLJSEDITOR_EXPORT QmlJSHighlighter : public TextEditor::SyntaxHighlighter
{
Q_OBJECT
public:
QmlJSHighlighter(QTextDocument *parent = nullptr);
~QmlJSHighlighter() override;
bool isQmlEnabled() const;
void setQmlEnabled(bool duiEnabled);
protected:
void highlightBlock(const QString &text) override;
int onBlockStart();
void onBlockEnd(int state);
// The functions are notified whenever parentheses are encountered.
// Custom behaviour can be added, for example storing info for indenting.
void onOpeningParenthesis(QChar parenthesis, int pos, bool atStart);
void onClosingParenthesis(QChar parenthesis, int pos, bool atEnd);
bool maybeQmlKeyword(QStringView text) const;
bool maybeQmlBuiltinType(QStringView text) const;
private:
bool m_qmlEnabled;
int m_braceDepth;
int m_foldingIndent;
bool m_inMultilineComment;
QmlJS::Scanner m_scanner;
TextEditor::Parentheses m_currentBlockParentheses;
};
} // namespace QmlJSEditor
|