summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-03 07:38:59 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-03 07:38:59 +0000
commit6feac4a315574b9cc037a328018e6ba9398a77d5 (patch)
treedc72d398a354ee9bc01cc4cc3ae24bad857460c4 /utils
parent1dc7f490c91993a06b0de1988efece102353455f (diff)
downloadrockbox-6feac4a315574b9cc037a328018e6ba9398a77d5.tar.gz
rockbox-6feac4a315574b9cc037a328018e6ba9398a77d5.tar.bz2
rockbox-6feac4a315574b9cc037a328018e6ba9398a77d5.zip
Theme Editor: Added syntax highlighting
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26506 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/editorwindow.cpp7
-rw-r--r--utils/themeeditor/editorwindow.h2
-rw-r--r--utils/themeeditor/editorwindow.ui6
-rw-r--r--utils/themeeditor/skinhighlighter.cpp132
-rw-r--r--utils/themeeditor/skinhighlighter.h36
-rw-r--r--utils/themeeditor/themeeditor.pro7
6 files changed, 183 insertions, 7 deletions
diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp
index feaac6fe47..ada9ecd137 100644
--- a/utils/themeeditor/editorwindow.cpp
+++ b/utils/themeeditor/editorwindow.cpp
@@ -34,6 +34,11 @@ EditorWindow::EditorWindow(QWidget *parent) :
tree = new ParseTreeModel(ui->code->document()->toPlainText().toAscii());
ui->parseTree->setModel(tree);
+ /* Setting up the syntax highlighter */
+ highlighter = new SkinHighlighter(QColor(0,255,0), QColor(255,0,0),
+ QColor(0,0,255), QColor(150,150,150),
+ ui->code->document());
+
/* Connecting the buttons */
QObject::connect(ui->code, SIGNAL(cursorPositionChanged()),
this, SLOT(updateTree()));
@@ -50,7 +55,7 @@ void EditorWindow::updateTree()
void EditorWindow::updateCode()
{
tree->genCode();
- ui->code->setDocument(new QTextDocument(tree->genCode()));
+ ui->code->document()->setPlainText(tree->genCode());
}
EditorWindow::~EditorWindow()
diff --git a/utils/themeeditor/editorwindow.h b/utils/themeeditor/editorwindow.h
index 03cdf66caf..a13bd4b6bb 100644
--- a/utils/themeeditor/editorwindow.h
+++ b/utils/themeeditor/editorwindow.h
@@ -25,6 +25,7 @@
#include <QMainWindow>
#include "parsetreemodel.h"
+#include "skinhighlighter.h"
namespace Ui {
class EditorWindow;
@@ -43,6 +44,7 @@ private slots:
private:
Ui::EditorWindow *ui;
ParseTreeModel* tree;
+ SkinHighlighter* highlighter;
};
diff --git a/utils/themeeditor/editorwindow.ui b/utils/themeeditor/editorwindow.ui
index 35ff3738c9..ca69a21c77 100644
--- a/utils/themeeditor/editorwindow.ui
+++ b/utils/themeeditor/editorwindow.ui
@@ -32,7 +32,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QTextEdit" name="code"/>
+ <widget class="QPlainTextEdit" name="code"/>
</item>
</layout>
</item>
@@ -74,8 +74,8 @@
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
- <x>65</x>
- <y>57</y>
+ <x>-1</x>
+ <y>-1</y>
</hint>
<hint type="destinationlabel">
<x>299</x>
diff --git a/utils/themeeditor/skinhighlighter.cpp b/utils/themeeditor/skinhighlighter.cpp
new file mode 100644
index 0000000000..4b8de9a804
--- /dev/null
+++ b/utils/themeeditor/skinhighlighter.cpp
@@ -0,0 +1,132 @@
+#include "skinhighlighter.h"
+
+SkinHighlighter::SkinHighlighter(QColor comment, QColor tag, QColor conditional,
+ QColor escaped, QTextDocument* doc)
+ :QSyntaxHighlighter(doc),
+ escaped(escaped), tag(tag),
+ conditional(conditional), comment(comment)
+{
+
+}
+
+SkinHighlighter::~SkinHighlighter()
+{
+
+}
+
+void SkinHighlighter::highlightBlock(const QString& text)
+{
+ for(int i = 0; i < text.length(); i++)
+ {
+ QChar c = text[i];
+
+ /* Checking for delimiters */
+ if(c == ARGLISTOPENSYM
+ || c == ARGLISTCLOSESYM
+ || c == ARGLISTSEPERATESYM)
+ setFormat(i, 1, tag);
+
+ if(c == ENUMLISTOPENSYM
+ || c == ENUMLISTCLOSESYM
+ || c == ENUMLISTSEPERATESYM)
+ setFormat(i, 1, conditional);
+
+ /* Checking for comments */
+ if(c == COMMENTSYM)
+ {
+ setFormat(i, text.length() - i, comment);
+ return;
+ }
+
+ if(c == TAGSYM)
+ {
+ if(text.length() - i < 2)
+ return;
+
+ if(find_escape_character(text[i + 1].toAscii()))
+ {
+ /* Checking for escaped characters */
+
+ setFormat(i, 2, escaped);
+ i++;
+ }
+ else if(text[i + 1] != CONDITIONSYM)
+ {
+ /* Checking for normal tags */
+
+ char lookup[3];
+ struct tag_info* found = 0;
+
+ /* First checking for a two-character tag name */
+ lookup[2] = '\0';
+
+ if(text.length() - i >= 3)
+ {
+ lookup[0] = text[i + 1].toAscii();
+ lookup[1] = text[i + 2].toAscii();
+
+ found = find_tag(lookup);
+ }
+
+ if(found)
+ {
+ setFormat(i, 3, tag);
+ i += 2;
+ }
+ else
+ {
+ lookup[1] = '\0';
+ lookup[0] = text[i + 1].toAscii();
+ found = find_tag(lookup);
+
+ if(found)
+ {
+ setFormat(i, 2, tag);
+ i++;
+ }
+ }
+
+ }
+ else if(text[i + 1] == CONDITIONSYM)
+ {
+ /* Checking for conditional tags */
+
+ if(text.length() - i < 3)
+ return;
+
+ char lookup[3];
+ struct tag_info* found = 0;
+
+ lookup[2] = '\0';
+
+ if(text.length() - i >= 4)
+ {
+ lookup[0] = text[i + 2].toAscii();
+ lookup[1] = text[i + 3].toAscii();
+
+ found = find_tag(lookup);
+ }
+
+ if(found)
+ {
+ setFormat(i, 4, conditional);
+ i += 3;
+ }
+ else
+ {
+ lookup[1] = '\0';
+ lookup[0] = text[i + 2].toAscii();
+
+ found = find_tag(lookup);
+
+ if(found)
+ {
+ setFormat(i, 3, conditional);
+ i += 2;
+ }
+ }
+
+ }
+ }
+ }
+}
diff --git a/utils/themeeditor/skinhighlighter.h b/utils/themeeditor/skinhighlighter.h
new file mode 100644
index 0000000000..ea3e2c5af5
--- /dev/null
+++ b/utils/themeeditor/skinhighlighter.h
@@ -0,0 +1,36 @@
+#ifndef SKINHIGHLIGHTER_H
+#define SKINHIGHLIGHTER_H
+
+#include <QSyntaxHighlighter>
+#include <QPlainTextEdit>
+
+#include "tag_table.h"
+#include "symbols.h"
+
+class SkinHighlighter : public QSyntaxHighlighter
+{
+Q_OBJECT
+public:
+ /*
+ * font - The font used for all text
+ * normal - The normal text color
+ * escaped - The color for escaped characters
+ * tag - The color for tags and their delimiters
+ * conditional - The color for conditionals and their delimiters
+ *
+ */
+ SkinHighlighter(QColor comment, QColor tag, QColor conditional,
+ QColor escaped, QTextDocument* doc);
+ virtual ~SkinHighlighter();
+
+ void highlightBlock(const QString& text);
+
+private:
+ QColor escaped;
+ QColor tag;
+ QColor conditional;
+ QColor comment;
+
+};
+
+#endif // SKINHIGHLIGHTER_H
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro
index 9bc78149d2..ede17109b5 100644
--- a/utils/themeeditor/themeeditor.pro
+++ b/utils/themeeditor/themeeditor.pro
@@ -4,7 +4,6 @@ OBJECTS_DIR = $$MYBUILDDIR/o
UI_DIR = $$MYBUILDDIR/ui
MOC_DIR = $$MYBUILDDIR/moc
RCC_DIR = $$MYBUILDDIR/rcc
-
HEADERS += tag_table.h \
symbols.h \
skin_parser.h \
@@ -12,7 +11,8 @@ HEADERS += tag_table.h \
skin_debug.h \
parsetreemodel.h \
parsetreenode.h \
- editorwindow.h
+ editorwindow.h \
+ skinhighlighter.h
SOURCES += tag_table.c \
skin_parser.c \
skin_scan.c \
@@ -20,6 +20,7 @@ SOURCES += tag_table.c \
main.cpp \
parsetreemodel.cpp \
parsetreenode.cpp \
- editorwindow.cpp
+ editorwindow.cpp \
+ skinhighlighter.cpp
OTHER_FILES += README
FORMS += editorwindow.ui