summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) :
34 tree = new ParseTreeModel(ui->code->document()->toPlainText().toAscii()); 34 tree = new ParseTreeModel(ui->code->document()->toPlainText().toAscii());
35 ui->parseTree->setModel(tree); 35 ui->parseTree->setModel(tree);
36 36
37 /* Setting up the syntax highlighter */
38 highlighter = new SkinHighlighter(QColor(0,255,0), QColor(255,0,0),
39 QColor(0,0,255), QColor(150,150,150),
40 ui->code->document());
41
37 /* Connecting the buttons */ 42 /* Connecting the buttons */
38 QObject::connect(ui->code, SIGNAL(cursorPositionChanged()), 43 QObject::connect(ui->code, SIGNAL(cursorPositionChanged()),
39 this, SLOT(updateTree())); 44 this, SLOT(updateTree()));
@@ -50,7 +55,7 @@ void EditorWindow::updateTree()
50void EditorWindow::updateCode() 55void EditorWindow::updateCode()
51{ 56{
52 tree->genCode(); 57 tree->genCode();
53 ui->code->setDocument(new QTextDocument(tree->genCode())); 58 ui->code->document()->setPlainText(tree->genCode());
54} 59}
55 60
56EditorWindow::~EditorWindow() 61EditorWindow::~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 @@
25#include <QMainWindow> 25#include <QMainWindow>
26 26
27#include "parsetreemodel.h" 27#include "parsetreemodel.h"
28#include "skinhighlighter.h"
28 29
29namespace Ui { 30namespace Ui {
30 class EditorWindow; 31 class EditorWindow;
@@ -43,6 +44,7 @@ private slots:
43private: 44private:
44 Ui::EditorWindow *ui; 45 Ui::EditorWindow *ui;
45 ParseTreeModel* tree; 46 ParseTreeModel* tree;
47 SkinHighlighter* highlighter;
46 48
47}; 49};
48 50
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 @@
32 <item> 32 <item>
33 <layout class="QVBoxLayout" name="verticalLayout"> 33 <layout class="QVBoxLayout" name="verticalLayout">
34 <item> 34 <item>
35 <widget class="QTextEdit" name="code"/> 35 <widget class="QPlainTextEdit" name="code"/>
36 </item> 36 </item>
37 </layout> 37 </layout>
38 </item> 38 </item>
@@ -74,8 +74,8 @@
74 <slot>close()</slot> 74 <slot>close()</slot>
75 <hints> 75 <hints>
76 <hint type="sourcelabel"> 76 <hint type="sourcelabel">
77 <x>65</x> 77 <x>-1</x>
78 <y>57</y> 78 <y>-1</y>
79 </hint> 79 </hint>
80 <hint type="destinationlabel"> 80 <hint type="destinationlabel">
81 <x>299</x> 81 <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 @@
1#include "skinhighlighter.h"
2
3SkinHighlighter::SkinHighlighter(QColor comment, QColor tag, QColor conditional,
4 QColor escaped, QTextDocument* doc)
5 :QSyntaxHighlighter(doc),
6 escaped(escaped), tag(tag),
7 conditional(conditional), comment(comment)
8{
9
10}
11
12SkinHighlighter::~SkinHighlighter()
13{
14
15}
16
17void SkinHighlighter::highlightBlock(const QString& text)
18{
19 for(int i = 0; i < text.length(); i++)
20 {
21 QChar c = text[i];
22
23 /* Checking for delimiters */
24 if(c == ARGLISTOPENSYM
25 || c == ARGLISTCLOSESYM
26 || c == ARGLISTSEPERATESYM)
27 setFormat(i, 1, tag);
28
29 if(c == ENUMLISTOPENSYM
30 || c == ENUMLISTCLOSESYM
31 || c == ENUMLISTSEPERATESYM)
32 setFormat(i, 1, conditional);
33
34 /* Checking for comments */
35 if(c == COMMENTSYM)
36 {
37 setFormat(i, text.length() - i, comment);
38 return;
39 }
40
41 if(c == TAGSYM)
42 {
43 if(text.length() - i < 2)
44 return;
45
46 if(find_escape_character(text[i + 1].toAscii()))
47 {
48 /* Checking for escaped characters */
49
50 setFormat(i, 2, escaped);
51 i++;
52 }
53 else if(text[i + 1] != CONDITIONSYM)
54 {
55 /* Checking for normal tags */
56
57 char lookup[3];
58 struct tag_info* found = 0;
59
60 /* First checking for a two-character tag name */
61 lookup[2] = '\0';
62
63 if(text.length() - i >= 3)
64 {
65 lookup[0] = text[i + 1].toAscii();
66 lookup[1] = text[i + 2].toAscii();
67
68 found = find_tag(lookup);
69 }
70
71 if(found)
72 {
73 setFormat(i, 3, tag);
74 i += 2;
75 }
76 else
77 {
78 lookup[1] = '\0';
79 lookup[0] = text[i + 1].toAscii();
80 found = find_tag(lookup);
81
82 if(found)
83 {
84 setFormat(i, 2, tag);
85 i++;
86 }
87 }
88
89 }
90 else if(text[i + 1] == CONDITIONSYM)
91 {
92 /* Checking for conditional tags */
93
94 if(text.length() - i < 3)
95 return;
96
97 char lookup[3];
98 struct tag_info* found = 0;
99
100 lookup[2] = '\0';
101
102 if(text.length() - i >= 4)
103 {
104 lookup[0] = text[i + 2].toAscii();
105 lookup[1] = text[i + 3].toAscii();
106
107 found = find_tag(lookup);
108 }
109
110 if(found)
111 {
112 setFormat(i, 4, conditional);
113 i += 3;
114 }
115 else
116 {
117 lookup[1] = '\0';
118 lookup[0] = text[i + 2].toAscii();
119
120 found = find_tag(lookup);
121
122 if(found)
123 {
124 setFormat(i, 3, conditional);
125 i += 2;
126 }
127 }
128
129 }
130 }
131 }
132}
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 @@
1#ifndef SKINHIGHLIGHTER_H
2#define SKINHIGHLIGHTER_H
3
4#include <QSyntaxHighlighter>
5#include <QPlainTextEdit>
6
7#include "tag_table.h"
8#include "symbols.h"
9
10class SkinHighlighter : public QSyntaxHighlighter
11{
12Q_OBJECT
13public:
14 /*
15 * font - The font used for all text
16 * normal - The normal text color
17 * escaped - The color for escaped characters
18 * tag - The color for tags and their delimiters
19 * conditional - The color for conditionals and their delimiters
20 *
21 */
22 SkinHighlighter(QColor comment, QColor tag, QColor conditional,
23 QColor escaped, QTextDocument* doc);
24 virtual ~SkinHighlighter();
25
26 void highlightBlock(const QString& text);
27
28private:
29 QColor escaped;
30 QColor tag;
31 QColor conditional;
32 QColor comment;
33
34};
35
36#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
4UI_DIR = $$MYBUILDDIR/ui 4UI_DIR = $$MYBUILDDIR/ui
5MOC_DIR = $$MYBUILDDIR/moc 5MOC_DIR = $$MYBUILDDIR/moc
6RCC_DIR = $$MYBUILDDIR/rcc 6RCC_DIR = $$MYBUILDDIR/rcc
7
8HEADERS += tag_table.h \ 7HEADERS += tag_table.h \
9 symbols.h \ 8 symbols.h \
10 skin_parser.h \ 9 skin_parser.h \
@@ -12,7 +11,8 @@ HEADERS += tag_table.h \
12 skin_debug.h \ 11 skin_debug.h \
13 parsetreemodel.h \ 12 parsetreemodel.h \
14 parsetreenode.h \ 13 parsetreenode.h \
15 editorwindow.h 14 editorwindow.h \
15 skinhighlighter.h
16SOURCES += tag_table.c \ 16SOURCES += tag_table.c \
17 skin_parser.c \ 17 skin_parser.c \
18 skin_scan.c \ 18 skin_scan.c \
@@ -20,6 +20,7 @@ SOURCES += tag_table.c \
20 main.cpp \ 20 main.cpp \
21 parsetreemodel.cpp \ 21 parsetreemodel.cpp \
22 parsetreenode.cpp \ 22 parsetreenode.cpp \
23 editorwindow.cpp 23 editorwindow.cpp \
24 skinhighlighter.cpp
24OTHER_FILES += README 25OTHER_FILES += README
25FORMS += editorwindow.ui 26FORMS += editorwindow.ui