History

- few Adjustments in Application class for Script editor - Shortkey for script editor (Alt+S) - highlighter: bold true/false , single line comments - Run scripts from the editor works - More icons from Maximillian, Thanks - Run on the fly checkbox, works if the script is running. - Load/save features

Thijs Wenker committed 12 years ago

Commit c016d651 parent d2d393715 files · +1160 −48Browse files

Showing the changes to interface/src/ScriptHighlighting.cpp (1 of 15 files). Show all

Unified · Split

interface/src/ScriptHighlighting.cpp+24−2
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 //
1111
1212 #include "ScriptHighlighting.h"
13+#include <QTextDocument>
1314
1415 ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) :
1516 QSyntaxHighlighter(parent)
@@ -19,13 +20,16 @@ ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) : · 3 unmodified lines
1920 multiLineCommentBegin = QRegExp("/\\*");
2021 multiLineCommentEnd = QRegExp("\\*/");
2122 numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");
23+ singleLineComment = QRegExp("//[^\n]*");
24+ truefalseRegex = QRegExp("\\b(true|false)\\b");
2225 }
2326
2427 void ScriptHighlighting::highlightBlock(const QString &text) {
2528 this->highlightKeywords(text);
26− this->formatComments(text);
27− this->formatQoutedText(text);
2829 this->formatNumbers(text);
30+ this->formatTrueFalse(text);
31+ this->formatQoutedText(text);
32+ this->formatComments(text);
2933 }
3034
3135 void ScriptHighlighting::highlightKeywords(const QString &text) {
@@ -50,6 +54,13 @@ void ScriptHighlighting::formatComments(const QString &text) { · 18 unmodified lines
5054 start = text.indexOf(multiLineCommentBegin, start + length);
5155 if (end == -1) setCurrentBlockState(BlockStateInMultiComment);
5256 }
57+
58+ int index = singleLineComment.indexIn(text);
59+ while (index >= 0) {
60+ int length = singleLineComment.matchedLength();
61+ setFormat(index, length, Qt::lightGray);
62+ index = singleLineComment.indexIn(text, index + length);
63+ }
5364 }
5465
5566 void ScriptHighlighting::formatQoutedText(const QString &text){
@@ -69,3 +80,14 @@ void ScriptHighlighting::formatNumbers(const QString &text){ · 13 unmodified lines
6980 index = numberRegex.indexIn(text, index + length);
7081 }
7182 }
83+
84+void ScriptHighlighting::formatTrueFalse(const QString text){
85+ int index = truefalseRegex.indexIn(text);
86+ while (index >= 0) {
87+ int length = truefalseRegex.matchedLength();
88+ QFont* font = new QFont(this->document()->defaultFont());
89+ font->setBold(true);
90+ setFormat(index, length, *font);
91+ index = truefalseRegex.indexIn(text, index + length);
92+ }
93+}