From: Akiko Date: Fri, 11 Oct 2013 10:59:28 +0000 (+0200) Subject: - updated makefiles (new syntax highlighter) X-Git-Url: http://community.linux-addicted.net/gitweb/?a=commitdiff_plain;h=6696274be4f0505a47baab5bb0415aace811a425;p=qtinns.git - updated makefiles (new syntax highlighter) - added syntax highlighting for .tsc files - all syntax highlighters have a similar look now --- diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index c0dd324..e47ce78 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -1,8 +1,8 @@ # Qt sources set (ED_SOURCES Main.cxx MainWindow.cxx ImageWindow.cxx TextWindow.cxx DatWindow.cxx - ObjectWindow.cxx DefSyntax.cxx FxSyntax.cxx IniSyntax.cxx) + ObjectWindow.cxx DefSyntax.cxx FxSyntax.cxx IniSyntax.cxx TscSyntax.cxx) set (ED_HEADERS MainWindow.hxx ImageWindow.hxx TextWindow.hxx DatWindow.hxx ObjectWindow.hxx - DefSyntax.hxx FxSyntax.hxx IniSyntax.hxx) + DefSyntax.hxx FxSyntax.hxx IniSyntax.hxx TscSyntax.hxx) set (ED_UI_FILES MainWindow.ui ImageWindow.ui TextWindow.ui DatWindow.ui ObjectWindow.ui) set (ED_RES_FILES Resources.qrc) set (ED_TS_FILES i18n_english.ts i18n_french.ts i18n_german.ts) diff --git a/editor/DefSyntax.cxx b/editor/DefSyntax.cxx index 78852f9..2167980 100644 --- a/editor/DefSyntax.cxx +++ b/editor/DefSyntax.cxx @@ -90,7 +90,6 @@ void DefSyntax::setup() _floats_f.setFontWeight(QFont::Bold); _floats_f.setForeground(Qt::darkRed); - _strings_f.setFontWeight(QFont::Bold); _strings_f.setFontItalic(true); _strings_f.setForeground(Qt::darkYellow); diff --git a/editor/FxSyntax.cxx b/editor/FxSyntax.cxx index 52fb94b..d1a8235 100644 --- a/editor/FxSyntax.cxx +++ b/editor/FxSyntax.cxx @@ -104,7 +104,6 @@ void FxSyntax::setup() _floats_f.setFontWeight(QFont::Bold); _floats_f.setForeground(Qt::darkRed); - _strings_f.setFontWeight(QFont::Bold); _strings_f.setFontItalic(true); _strings_f.setForeground(Qt::darkYellow); diff --git a/editor/IniSyntax.cxx b/editor/IniSyntax.cxx index 7b2e547..794d23c 100644 --- a/editor/IniSyntax.cxx +++ b/editor/IniSyntax.cxx @@ -77,7 +77,6 @@ void IniSyntax::setup() _ints_f.setFontWeight(QFont::Bold); _ints_f.setForeground(Qt::darkBlue); - _strings_f.setFontWeight(QFont::Bold); _strings_f.setFontItalic(true); _strings_f.setForeground(Qt::darkYellow); diff --git a/editor/TextWindow.cxx b/editor/TextWindow.cxx index 3ba7bff..0dc8476 100644 --- a/editor/TextWindow.cxx +++ b/editor/TextWindow.cxx @@ -4,6 +4,7 @@ #include "DefSyntax.hxx" #include "FxSyntax.hxx" #include "IniSyntax.hxx" +#include "TscSyntax.hxx" // --- constructors and deconstructors --- @@ -74,6 +75,9 @@ void TextWindow::slotTextView(NCFile& entry, quint32 row) if (entry.name().contains(".ini", Qt::CaseInsensitive)) _syn = new IniSyntax(_ui->ed_text->document()); + + if (entry.name().contains(".tsc", Qt::CaseInsensitive)) + _syn = new TscSyntax(_ui->ed_text->document()); } void TextWindow::slotTextChanged() diff --git a/editor/TscSyntax.cxx b/editor/TscSyntax.cxx new file mode 100644 index 0000000..a41c7e1 --- /dev/null +++ b/editor/TscSyntax.cxx @@ -0,0 +1,151 @@ +#include "TscSyntax.hxx" + +// --- internal constants --- + +const QString preprocs("include"); +const QString structs("BUTTON DATACONTROLBOX EDITBOX FRAME HEADER_BOX LEFT LISTBOX SCROLLBAR TEXT TEXTBUTTON"); +const QString functions("Alpha Background ChangePage Color DataColumn DataFunctionColumn Document FunctionText " + "GetControlText GetEnv Image Layout LineHeight MaxBuffer OnAccess OnAccessError OnData OnLoad " + "OnMouse PlaySound Pos ReceiveDB RenderHeader Resource SelectionColumn ServerMessage Set " + "SetContent SetEnv SetFunctionContent Settings ShowLineNumbers Size SubImage Target UpdateDB " + "TryAccess Width"); + +// --- constructors and deconstructors --- + +TscSyntax::TscSyntax(QObject *parent) +: QSyntaxHighlighter(parent) +{ + setup(); +} + +TscSyntax::TscSyntax(QTextDocument *parent) +: QSyntaxHighlighter(parent) +{ + setup(); +} + +TscSyntax::~TscSyntax() +{ +} + +// --- protected methods --- + +void TscSyntax::highlightBlock(const QString& text) +{ + qint32 index = 0; + + setCurrentBlockState(0); + + // structs + index = text.indexOf(_structs_re); + while (index >= 0) + { + auto len = _structs_re.matchedLength(); + + setFormat(index, len, _structs_f); + index = text.indexOf(_structs_re, index + len); + } + + // functions + index = text.indexOf(_functions_re); + while (index >= 0) + { + auto len = _functions_re.matchedLength(); + + setFormat(index, len, _functions_f); + index = text.indexOf(_functions_re, index + len); + } + + // ints + index = text.indexOf(_ints_re); + while (index >= 0) + { + auto len = _ints_re.matchedLength(); + + setFormat(index, len, _ints_f); + index = text.indexOf(_ints_re, index + len); + } + + // floats + index = text.indexOf(_floats_re); + while (index >= 0) + { + auto len = _floats_re.matchedLength(); + + setFormat(index, len, _floats_f); + index = text.indexOf(_floats_re, index + len); + } + + // strings + index = text.indexOf(_strings_re); + while (index >= 0) + { + auto len = _strings_re.matchedLength(); + + setFormat(index, len, _strings_f); + index = text.indexOf(_strings_re, index + len); + } + + // single line comments + index = text.indexOf(_comment_re); + if (index >= 0) + setFormat(index, _comment_re.matchedLength(), _comment_f); + + // preprocessor + index = text.indexOf(_preprocs_re); + if (index >= 0) + setFormat(index, _preprocs_re.matchedLength(), _preprocs_f); +} + +void TscSyntax::setup() +{ + QString pattern; + + // format + _structs_f.setFontWeight(QFont::Bold); + _structs_f.setForeground(Qt::green); + + _functions_f.setFontWeight(QFont::Bold); + _functions_f.setForeground(Qt::darkGreen); + + _ints_f.setFontWeight(QFont::Bold); + _ints_f.setForeground(Qt::darkBlue); + + _floats_f.setFontWeight(QFont::Bold); + _floats_f.setForeground(Qt::darkRed); + + _strings_f.setFontItalic(true); + _strings_f.setForeground(Qt::darkYellow); + + _comment_f.setFontItalic(true); + _comment_f.setForeground(Qt::darkGray); + + _preprocs_f.setFontWeight(QFont::Bold); + _preprocs_f.setForeground(Qt::magenta); + + // regexp + pattern.append("\\b("); + pattern.append(structs.split(" ").join("|")); + pattern.append(")\\b"); + _structs_re.setPattern(pattern); + + pattern.clear(); + pattern.append("\\b("); + pattern.append(functions.split(" ").join("|")); + pattern.append(")\\b"); + _functions_re.setPattern(pattern); + + _ints_re.setPattern("\\b[0-9]+\\b"); + + _floats_re.setPattern("\\b[0-9]+\\.[0-9]+\\b"); + + _strings_re.setPattern("(\"[^\"]*)\""); + + _comment_re.setPattern("//[^\n]*"); + + pattern.clear(); + pattern.append("#("); + pattern.append(preprocs.split(" ").join("|")); + pattern.append(")[^\n]*"); + _preprocs_re.setPattern(pattern); +} diff --git a/editor/TscSyntax.hxx b/editor/TscSyntax.hxx new file mode 100644 index 0000000..fbd9f76 --- /dev/null +++ b/editor/TscSyntax.hxx @@ -0,0 +1,31 @@ +#pragma once + +#include + +class TscSyntax : public QSyntaxHighlighter { + Q_OBJECT +public: + explicit TscSyntax(QObject *parent = 0); + explicit TscSyntax(QTextDocument *parent = 0); + virtual ~TscSyntax(); + +protected: + virtual void highlightBlock(const QString& text) override; + void setup(); + +private: + QTextCharFormat _structs_f; + QTextCharFormat _functions_f; + QTextCharFormat _ints_f; + QTextCharFormat _floats_f; + QTextCharFormat _strings_f; + QTextCharFormat _comment_f; + QTextCharFormat _preprocs_f; + QRegExp _structs_re; + QRegExp _functions_re; + QRegExp _ints_re; + QRegExp _floats_re; + QRegExp _strings_re; + QRegExp _comment_re; + QRegExp _preprocs_re; +};