51 #if QT_VERSION >= 0x050000 58 #include "renderObjectHighLighter.hh" 60 RenderObjectHighlighter::RenderObjectHighlighter(QTextDocument *parent)
61 : QSyntaxHighlighter(parent)
66 RenderObjectHighlighter::RenderObjectHighlighter(QTextEdit *parent)
67 : QSyntaxHighlighter(parent)
74 vertexShaderFormat_.setBackground(Qt::green);
75 vertexShaderFormat_.setFontWeight(QFont::Bold);
77 vertexShaderStartExpression_ = QRegExp(
"---------------------vertex-shader--------------------");
78 vertexShaderEndExpression_ = QRegExp(
"---------------------end-vertex-shader--------------------");
80 geometryShaderFormat_.setBackground(Qt::blue);
81 geometryShaderFormat_.setFontWeight(QFont::Bold);
83 geometryShaderStartExpression_ = QRegExp(
"---------------------geometry-shader--------------------");;
84 geometryShaderEndExpression_ = QRegExp(
"---------------------end-geometry-shader--------------------");;
87 fragmentShaderFormat_.setBackground(Qt::red);
88 fragmentShaderFormat_.setFontWeight(QFont::Bold);
90 fragmentShaderStartExpression_ = QRegExp(
"---------------------fragment-shader--------------------");
91 fragmentShaderEndExpression_ = QRegExp(
"---------------------end-fragment-shader--------------------");
94 defineFormat_.setForeground(Qt::green);
95 defineFormat_.setFontWeight(QFont::Bold);
98 singleLineCommentFormat_.setForeground(Qt::red);
101 keywordFormat_.setForeground(Qt::darkGreen);
102 keywordFormat_.setFontWeight(QFont::Bold);
105 keywordPatterns_ <<
"main" <<
"while" <<
"for" <<
"if" <<
"dot" <<
"sqrt" <<
"max" <<
"pow" <<
"return" <<
"normalize";
106 keywordPatterns_ <<
"min" <<
"clamp" <<
"step";
108 typeFormat_.setForeground(Qt::darkMagenta);
109 typeFormat_.setFontWeight(QFont::Bold);
112 typePatterns_ <<
"in" <<
"out" <<
"mat3" <<
"mat4" <<
"vec2" <<
"vec3" <<
"vec4" <<
"float" <<
"double" <<
"uniform" <<
"layout" ;
119 highlightingRules_.clear();
124 rule.pattern = QRegExp(
"#define.*");
125 rule.format = defineFormat_;
126 highlightingRules_.append(rule);
129 rule.pattern = QRegExp(
"#version.*");
130 rule.format = defineFormat_;
131 highlightingRules_.append(rule);
134 rule.pattern = QRegExp(
"//[^\n]*");
135 rule.format = singleLineCommentFormat_;
136 highlightingRules_.append(rule);
139 foreach (QString pattern, keywordPatterns_) {
140 rule.pattern = QRegExp(
"\\b" + pattern +
"\\b" );
141 rule.format = keywordFormat_;
142 highlightingRules_.append(rule);
146 foreach (QString pattern, typePatterns_ ) {
147 rule.pattern = QRegExp(
"\\b" + pattern +
"\\b" );
148 rule.format = typeFormat_;
149 highlightingRules_.append(rule);
154 void RenderObjectHighlighter::highlightBlock(
const QString &text)
159 QRegExp expression(rule.pattern);
160 int index = text.indexOf(expression);
162 int length = expression.matchedLength();
163 setFormat(index, length, rule.format);
164 index = text.indexOf(expression, index + length);
void init()
common initializer function called by the constructors
void update()
Updates the highlighter with the current rule set defined in the patterns.