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
10//10//
11 11
12#include "ScriptHighlighting.h"12#include "ScriptHighlighting.h"
13#include <QTextDocument>
13 14
14ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) :15ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) :
15 QSyntaxHighlighter(parent)16 QSyntaxHighlighter(parent)
@@ -19,13 +20,16 @@ ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) : · 3 unmodified lines
19 multiLineCommentBegin = QRegExp("/\\*");20 multiLineCommentBegin = QRegExp("/\\*");
20 multiLineCommentEnd = QRegExp("\\*/");21 multiLineCommentEnd = QRegExp("\\*/");
21 numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");22 numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");
23 singleLineComment = QRegExp("//[^\n]*");
24 truefalseRegex = QRegExp("\\b(true|false)\\b");
22}25}
23 26
24void ScriptHighlighting::highlightBlock(const QString &text) {27void ScriptHighlighting::highlightBlock(const QString &text) {
25 this->highlightKeywords(text);28 this->highlightKeywords(text);
26 this->formatComments(text);
27 this->formatQoutedText(text);
28 this->formatNumbers(text);29 this->formatNumbers(text);
30 this->formatTrueFalse(text);
31 this->formatQoutedText(text);
32 this->formatComments(text);
29}33}
30 34
31void ScriptHighlighting::highlightKeywords(const QString &text) {35void ScriptHighlighting::highlightKeywords(const QString &text) {
@@ -50,6 +54,13 @@ void ScriptHighlighting::formatComments(const QString &text) { · 18 unmodified lines
50 start = text.indexOf(multiLineCommentBegin, start + length);54 start = text.indexOf(multiLineCommentBegin, start + length);
51 if (end == -1) setCurrentBlockState(BlockStateInMultiComment);55 if (end == -1) setCurrentBlockState(BlockStateInMultiComment);
52 }56 }
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 }
53}64}
54 65
55void ScriptHighlighting::formatQoutedText(const QString &text){66void ScriptHighlighting::formatQoutedText(const QString &text){
@@ -69,3 +80,14 @@ void ScriptHighlighting::formatNumbers(const QString &text){ · 13 unmodified lines
69 index = numberRegex.indexIn(text, index + length);80 index = numberRegex.indexIn(text, index + length);
70 }81 }
71}82}
83
84void 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}