45 #include "renderObjectHighLighter.hh" 47 RenderObjectHighlighter::RenderObjectHighlighter(QTextDocument *parent)
48 : QSyntaxHighlighter(parent)
53 RenderObjectHighlighter::RenderObjectHighlighter(QTextEdit *parent)
54 : QSyntaxHighlighter(parent)
61 vertexShaderFormat_.setBackground(Qt::green);
62 vertexShaderFormat_.setFontWeight(QFont::Bold);
64 vertexShaderStartExpression_ = QRegExp(
"---------------------vertex-shader--------------------");
65 vertexShaderEndExpression_ = QRegExp(
"---------------------end-vertex-shader--------------------");
67 geometryShaderFormat_.setBackground(Qt::blue);
68 geometryShaderFormat_.setFontWeight(QFont::Bold);
70 geometryShaderStartExpression_ = QRegExp(
"---------------------geometry-shader--------------------");;
71 geometryShaderEndExpression_ = QRegExp(
"---------------------end-geometry-shader--------------------");;
74 fragmentShaderFormat_.setBackground(Qt::red);
75 fragmentShaderFormat_.setFontWeight(QFont::Bold);
77 fragmentShaderStartExpression_ = QRegExp(
"---------------------fragment-shader--------------------");
78 fragmentShaderEndExpression_ = QRegExp(
"---------------------end-fragment-shader--------------------");
81 defineFormat_.setForeground(Qt::green);
82 defineFormat_.setFontWeight(QFont::Bold);
85 singleLineCommentFormat_.setForeground(Qt::red);
88 keywordFormat_.setForeground(Qt::darkGreen);
89 keywordFormat_.setFontWeight(QFont::Bold);
92 keywordPatterns_ <<
"main" <<
"while" <<
"for" <<
"if" <<
"dot" <<
"sqrt" <<
"max" <<
"pow" <<
"return" <<
"normalize";
93 keywordPatterns_ <<
"min" <<
"clamp" <<
"step";
95 typeFormat_.setForeground(Qt::darkMagenta);
96 typeFormat_.setFontWeight(QFont::Bold);
99 typePatterns_ <<
"in" <<
"out" <<
"mat3" <<
"mat4" <<
"vec2" <<
"vec3" <<
"vec4" <<
"float" <<
"double" <<
"uniform" <<
"layout" ;
106 highlightingRules_.clear();
111 rule.pattern = QRegExp(
"(#define|#ifdef|#else|#endif|#ifndef).*");
112 rule.format = defineFormat_;
113 highlightingRules_.append(rule);
116 rule.pattern = QRegExp(
"#version.*");
117 rule.format = defineFormat_;
118 highlightingRules_.append(rule);
121 rule.pattern = QRegExp(
"//[^\n]*");
122 rule.format = singleLineCommentFormat_;
123 highlightingRules_.append(rule);
126 foreach (QString pattern, keywordPatterns_) {
127 rule.pattern = QRegExp(
"\\b" + pattern +
"\\b" );
128 rule.format = keywordFormat_;
129 highlightingRules_.append(rule);
133 foreach (QString pattern, typePatterns_ ) {
134 rule.pattern = QRegExp(
"\\b" + pattern +
"\\b" );
135 rule.format = typeFormat_;
136 highlightingRules_.append(rule);
141 void RenderObjectHighlighter::highlightBlock(
const QString &text)
146 QRegExp expression(rule.pattern);
147 int index = text.indexOf(expression);
149 int length = expression.matchedLength();
150 setFormat(index, length, rule.format);
151 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.