-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSyntaxHighlighter.cpp
54 lines (44 loc) · 1.21 KB
/
SyntaxHighlighter.cpp
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
51
52
53
54
#include "SyntaxHighlighter.h"
SyntaxHighlighter::SyntaxHighlighter( QObject* parent ) :
QSyntaxHighlighter(parent),
m_TextDocument(nullptr)
{
}
void SyntaxHighlighter::highlightBlock( const QString &text )
{
emit highlightBlock( QVariant(text) );
}
QQuickTextDocument* SyntaxHighlighter::textDocument() const
{
return m_TextDocument;
}
void SyntaxHighlighter::setTextDocument( QQuickTextDocument* textDocument )
{
if (textDocument == m_TextDocument)
{
return;
}
m_TextDocument = textDocument;
QTextDocument* doc = m_TextDocument->textDocument();
setDocument(doc);
emit textDocumentChanged();
}
void SyntaxHighlighter::setFormat( int start, int count, const QVariant& format )
{
TextCharFormat* charFormat = qvariant_cast<TextCharFormat*>( format );
if ( charFormat )
{
QSyntaxHighlighter::setFormat( start, count, *charFormat );
return;
}
if ( format.canConvert(QVariant::Color) )
{
QSyntaxHighlighter::setFormat( start, count, format.value<QColor>() );
return;
}
if ( format.canConvert(QVariant::Font) )
{
QSyntaxHighlighter::setFormat( start, count, format.value<QFont>() );
return;
}
}