StelScriptSyntaxHighlighter.cpp   StelScriptSyntaxHighlighter.cpp 
skipping to change at line 25 skipping to change at line 25
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelScriptSyntaxHighlighter.hpp" #include "StelScriptSyntaxHighlighter.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelUtils.hpp"
#include <QtGui> #include <QtGui>
#include <QString>
#include <QColor>
#include <QSettings>
#include <QMetaMethod>
StelScriptSyntaxHighlighter::StelScriptSyntaxHighlighter(QTextDocument *par ent) StelScriptSyntaxHighlighter::StelScriptSyntaxHighlighter(QTextDocument *par ent)
: QSyntaxHighlighter(parent) : QSyntaxHighlighter(parent)
{ {
HighlightingRule rule; HighlightingRule rule;
setFormats();
// comments
rule.pattern = QRegExp("//[^\n]*");
rule.format = &commentFormat;
highlightingRules.append(rule);
// ECMAscript reserved words // ECMAscript reserved words
//keywordFormat.setForeground(Qt::darkBlue);
keywordFormat.setFontWeight(QFont::Bold);
QStringList keywordPatterns; QStringList keywordPatterns;
keywordPatterns << "\\bbreak\\b" keywordPatterns << "\\bbreak\\b"
<< "\\bcase\\b" << "\\bcase\\b"
<< "\\bcatch\\b" << "\\bcatch\\b"
<< "\\bcontinue\\b" << "\\bcontinue\\b"
<< "\\bdefault\\b" << "\\bdefault\\b"
<< "\\bdelete\\b" << "\\bdelete\\b"
<< "\\bdo\\b" << "\\bdo\\b"
<< "\\belse\\b" << "\\belse\\b"
<< "\\bfalse\\b" << "\\bfalse\\b"
skipping to change at line 87 skipping to change at line 97
<< "\\bReferenceError\\b" << "\\bReferenceError\\b"
<< "\\bRegExp\\b" << "\\bRegExp\\b"
<< "\\bString\\b" << "\\bString\\b"
<< "\\bSyntaxError\\b" << "\\bSyntaxError\\b"
<< "\\bTypeError\\b" << "\\bTypeError\\b"
<< "\\bURIError\\b"; << "\\bURIError\\b";
foreach(const QString &pattern, keywordPatterns) foreach(const QString &pattern, keywordPatterns)
{ {
rule.pattern = QRegExp(pattern); rule.pattern = QRegExp(pattern);
rule.format = keywordFormat; rule.format = &keywordFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
} }
// highlight object names which can be used in scripting // highlight object names which can be used in scripting
moduleFormat.setFontWeight(QFont::Bold);
moduleFormat.setForeground(QColor(0,40,0));
QStringList moduleNames; QStringList moduleNames;
QStringList knownFunctionNames;
StelModuleMgr* mmgr = &StelApp::getInstance().getModuleMgr(); StelModuleMgr* mmgr = &StelApp::getInstance().getModuleMgr();
foreach (StelModule* m, mmgr->getAllModules()) foreach (StelModule* m, mmgr->getAllModules())
{ {
moduleNames << "\\b" + m->objectName() + "\\b"; moduleNames << "\\b" + m->objectName() + "\\b";
// for each one dump known public slots
const QMetaObject* metaObject = m->metaObject();
for(int i = metaObject->methodOffset(); i < metaObject->meth
odCount(); ++i)
{
if (metaObject->method(i).methodType() == QMetaMetho
d::Slot && metaObject->method(i).access() == QMetaMethod::Public)
{
QString fn = metaObject->method(i).signature
();
fn.replace(QRegExp("\\(.*$"), "");
fn = m->objectName() + "\\." + fn;
knownFunctionNames << fn;
}
}
} }
moduleNames << "\\bStelSkyImageMgr\\b" << "\\bStelSkyDrawer\\b" << " \\bcore\\b"; moduleNames << "\\bStelSkyImageMgr\\b" << "\\bStelSkyDrawer\\b" << " \\bcore\\b";
foreach(const QString &pattern, moduleNames) foreach(const QString &pattern, moduleNames)
{ {
rule.pattern = QRegExp(pattern); rule.pattern = QRegExp(pattern);
rule.format = moduleFormat; rule.format = &moduleFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
} }
// comments foreach(const QString &pattern, knownFunctionNames)
singleLineCommentFormat.setForeground(Qt::darkBlue); {
rule.pattern = QRegExp("//[^\n]*"); rule.pattern = QRegExp(pattern);
rule.format = singleLineCommentFormat; rule.format = &moduleFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
}
// quotes // quoted strings
quotationFormat.setFontWeight(QFont::Bold);
quotationFormat.setForeground(Qt::darkRed);
rule.pattern = QRegExp("\".*\""); rule.pattern = QRegExp("\".*\"");
rule.format = quotationFormat; rule.format = &constantFormat;
highlightingRules.append(rule);
// decimal numeric constants
rule.pattern = QRegExp("\\b\\d+(\\.\\d+)?\\b");
rule.format = &constantFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
// function calls // function calls
functionFormat.setFontItalic(true);
//functionFormat.setForeground(Qt::darkBlue);
rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()"); rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
rule.format = functionFormat; rule.format = &functionFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
}
void StelScriptSyntaxHighlighter::setFormats(void)
{
Vec3f col;
QString defaultColor = "0.8,0.8,0.8";
QSettings* conf = StelApp::getInstance().getSettings();
QString section;
if (StelApp::getInstance().getVisionModeNight())
section = "night_color";
else
section = "color";
// comments
col = StelUtils::strToVec3f(conf->value(section + "/script_console_c
omment_color", defaultColor).toString());
commentFormat.setForeground(QColor(col[0]*255, col[1]*255, col[2]*25
5));
// ECMAscript reserved words
col = StelUtils::strToVec3f(conf->value(section + "/script_console_k
eyword_color", defaultColor).toString());
keywordFormat.setForeground(QColor(col[0]*255, col[1]*255, col[2]*25
5));
keywordFormat.setFontWeight(QFont::Bold);
// highlight object names which can be used in scripting
moduleFormat.setFontWeight(QFont::Bold);
col = StelUtils::strToVec3f(conf->value(section + "/script_console_m
odule_color", defaultColor).toString());
moduleFormat.setForeground(QColor(col[0]*255, col[1]*255, col[2]*255
));
// constants
constantFormat.setFontWeight(QFont::Bold);
col = StelUtils::strToVec3f(conf->value(section + "/script_console_c
onstant_color", defaultColor).toString());
constantFormat.setForeground(QColor(col[0]*255, col[1]*255, col[2]*2
55));
// function calls
functionFormat.setFontItalic(true);
col = StelUtils::strToVec3f(conf->value(section + "/script_console_f
unction_color", defaultColor).toString());
functionFormat.setForeground(QColor(col[0]*255, col[1]*255, col[2]*2
55));
} }
void StelScriptSyntaxHighlighter::highlightBlock(const QString &text) void StelScriptSyntaxHighlighter::highlightBlock(const QString &text)
{ {
foreach(const HighlightingRule &rule, highlightingRules) foreach(const HighlightingRule &rule, highlightingRules)
{ {
QRegExp expression(rule.pattern); QRegExp expression(rule.pattern);
int index = expression.indexIn(text); int index = expression.indexIn(text);
while (index >= 0) while (index >= 0)
{ {
int length = expression.matchedLength(); int length = expression.matchedLength();
setFormat(index, length, rule.format); setFormat(index, length, *(rule.format));
index = expression.indexIn(text, index + length); index = expression.indexIn(text, index + length);
} }
} }
} }
 End of changes. 16 change blocks. 
19 lines changed or deleted 95 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/