-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathPygmentsHighlighter.cpp
More file actions
42 lines (34 loc) · 1.19 KB
/
PygmentsHighlighter.cpp
File metadata and controls
42 lines (34 loc) · 1.19 KB
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
/*! \file PygmentsHighlighter.cpp
* \brief implements PygmentsHighlighter
* \author "Melven Zoellner" <melven@topen.org>
*
*/
#include "PygmentsHighlighter.h"
PygmentsHighlighter::PygmentsHighlighter(QTextDocument *parentDoc) :
QSyntaxHighlighter(parentDoc)
{
// create an own pythonqt context for the highlighter
_context = PythonQt::self()->createUniqueModule();
// name this object
setObjectName("pygmentsHighlighter");
// make it accessable in pythonqt,
// this allows to delegate the work in highlightBlock
// to a python function
_context.addObject(objectName(),this);
// initialize python
_context.evalFile(":/lib/PygmentsHighlighter.py");
}
// just delegate the protected method setFormat from base class
void PygmentsHighlighter::_setFormat(int start, int count, const QTextCharFormat &format)
{
//qDebug() << "setFormat " << start << " " << count << " format " << format;
setFormat(start, count, format);
}
void PygmentsHighlighter::highlightBlock(const QString &text)
{
//qDebug() << "highlightBlock" << text;
// call python function to do everything
QVariantList args;
args.append(text);
_context.call("highlightCode", args);
}