diff options
-rw-r--r-- | utils/themeeditor/gui/codeeditor.cpp | 105 | ||||
-rw-r--r-- | utils/themeeditor/gui/codeeditor.h | 10 | ||||
-rw-r--r-- | utils/themeeditor/gui/preferencesdialog.cpp | 12 | ||||
-rw-r--r-- | utils/themeeditor/gui/preferencesdialog.ui | 9 | ||||
-rw-r--r-- | utils/themeeditor/gui/syntaxcompleter.cpp | 83 | ||||
-rw-r--r-- | utils/themeeditor/gui/syntaxcompleter.h | 44 | ||||
-rw-r--r-- | utils/themeeditor/resources.qrc | 1 | ||||
-rw-r--r-- | utils/themeeditor/resources/tagdb | 10 | ||||
-rw-r--r-- | utils/themeeditor/themeeditor.pro | 18 |
9 files changed, 282 insertions, 10 deletions
diff --git a/utils/themeeditor/gui/codeeditor.cpp b/utils/themeeditor/gui/codeeditor.cpp index 49f441057c..44f331d280 100644 --- a/utils/themeeditor/gui/codeeditor.cpp +++ b/utils/themeeditor/gui/codeeditor.cpp | |||
@@ -34,12 +34,14 @@ | |||
34 | ****************************************************************************/ | 34 | ****************************************************************************/ |
35 | 35 | ||
36 | #include <QtGui> | 36 | #include <QtGui> |
37 | #include <QApplication> | ||
37 | 38 | ||
38 | #include "codeeditor.h" | 39 | #include "codeeditor.h" |
39 | 40 | ||
40 | //![constructor] | 41 | //![constructor] |
41 | 42 | ||
42 | CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) | 43 | CodeEditor::CodeEditor(QWidget *parent) |
44 | : QPlainTextEdit(parent), completer(this) | ||
43 | { | 45 | { |
44 | lineNumberArea = new LineNumberArea(this); | 46 | lineNumberArea = new LineNumberArea(this); |
45 | 47 | ||
@@ -49,6 +51,11 @@ CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) | |||
49 | this, SLOT(updateLineNumberArea(QRect,int))); | 51 | this, SLOT(updateLineNumberArea(QRect,int))); |
50 | 52 | ||
51 | updateLineNumberAreaWidth(0); | 53 | updateLineNumberAreaWidth(0); |
54 | |||
55 | QObject::connect(this, SIGNAL(cursorPositionChanged()), | ||
56 | this, SLOT(cursorMoved())); | ||
57 | completer.hide(); | ||
58 | settings.beginGroup("CodeEditor"); | ||
52 | } | 59 | } |
53 | 60 | ||
54 | //![constructor] | 61 | //![constructor] |
@@ -95,6 +102,19 @@ void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) | |||
95 | 102 | ||
96 | //![slotUpdateRequest] | 103 | //![slotUpdateRequest] |
97 | 104 | ||
105 | void CodeEditor::cursorMoved() | ||
106 | { | ||
107 | /* Closing the completer if the cursor has moved out of its bounds */ | ||
108 | if(completer.isVisible()) | ||
109 | { | ||
110 | if(textCursor().position() < tagBegin | ||
111 | || textCursor().position() > tagEnd) | ||
112 | { | ||
113 | completer.hide(); | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | |||
98 | //![resizeEvent] | 118 | //![resizeEvent] |
99 | 119 | ||
100 | void CodeEditor::resizeEvent(QResizeEvent *e) | 120 | void CodeEditor::resizeEvent(QResizeEvent *e) |
@@ -108,6 +128,89 @@ void CodeEditor::resizeEvent(QResizeEvent *e) | |||
108 | 128 | ||
109 | //![resizeEvent] | 129 | //![resizeEvent] |
110 | 130 | ||
131 | void CodeEditor::keyPressEvent(QKeyEvent *event) | ||
132 | { | ||
133 | |||
134 | if(!settings.value("completeSyntax", false).toBool()) | ||
135 | { | ||
136 | QPlainTextEdit::keyPressEvent(event); | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | if(completer.isVisible()) | ||
141 | { | ||
142 | /* Handling the completer */ | ||
143 | if(event->key() == Qt::Key_Up) | ||
144 | { | ||
145 | /* Up/down arrow presses get sent right along to the completer | ||
146 | * to navigate through the list | ||
147 | */ | ||
148 | if(completer.currentIndex().row() > 0) | ||
149 | QApplication::sendEvent(&completer, event); | ||
150 | } | ||
151 | else if(event->key() == Qt::Key_Down) | ||
152 | { | ||
153 | if(completer.currentIndex().row() | ||
154 | < completer.topLevelItemCount() - 1) | ||
155 | QApplication::sendEvent(&completer, event); | ||
156 | } | ||
157 | else if(event->key() == Qt::Key_Backspace) | ||
158 | { | ||
159 | tagEnd--; | ||
160 | QPlainTextEdit::keyPressEvent(event); | ||
161 | } | ||
162 | else if(event->key() == Qt::Key_Escape) | ||
163 | { | ||
164 | /* Escape hides the completer */ | ||
165 | completer.hide(); | ||
166 | QPlainTextEdit::keyPressEvent(event); | ||
167 | } | ||
168 | else if(event->key() == Qt::Key_Enter) | ||
169 | { | ||
170 | /* The enter key inserts the currently selected tag */ | ||
171 | } | ||
172 | else if(event->key() == Qt::Key_Question) | ||
173 | { | ||
174 | /* The question mark doesn't filter the list */ | ||
175 | tagEnd++; | ||
176 | QPlainTextEdit::keyPressEvent(event); | ||
177 | } | ||
178 | else if(event->key() == Qt::Key_Left | ||
179 | || event->key() == Qt::Key_Right) | ||
180 | { | ||
181 | /* Left and right keys shouldn't affect tagEnd */ | ||
182 | QPlainTextEdit::keyPressEvent(event); | ||
183 | } | ||
184 | else | ||
185 | { | ||
186 | /* Otherwise, we have to filter the list */ | ||
187 | tagEnd++; | ||
188 | QPlainTextEdit::keyPressEvent(event); | ||
189 | |||
190 | QString filterText = ""; | ||
191 | } | ||
192 | } | ||
193 | else | ||
194 | { | ||
195 | /* Deciding whether to show the completer */ | ||
196 | QPlainTextEdit::keyPressEvent(event); | ||
197 | if(event->key() == Qt::Key_Percent) | ||
198 | { | ||
199 | tagBegin = textCursor().position(); | ||
200 | tagEnd = textCursor().position(); | ||
201 | completer.filter(""); | ||
202 | completer.move(cursorRect().left(), cursorRect().bottom()); | ||
203 | if(completer.frameGeometry().right() > width()) | ||
204 | completer.move(width() - completer.width(), completer.y()); | ||
205 | if(completer.frameGeometry().bottom() > height()) | ||
206 | completer.move(completer.x(), | ||
207 | cursorRect().top() - completer.height()); | ||
208 | completer.show(); | ||
209 | } | ||
210 | } | ||
211 | |||
212 | } | ||
213 | |||
111 | //![extraAreaPaintEvent_0] | 214 | //![extraAreaPaintEvent_0] |
112 | 215 | ||
113 | void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) | 216 | void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) |
diff --git a/utils/themeeditor/gui/codeeditor.h b/utils/themeeditor/gui/codeeditor.h index 528dfb2c12..a25c5664f0 100644 --- a/utils/themeeditor/gui/codeeditor.h +++ b/utils/themeeditor/gui/codeeditor.h | |||
@@ -38,6 +38,9 @@ | |||
38 | 38 | ||
39 | #include <QPlainTextEdit> | 39 | #include <QPlainTextEdit> |
40 | #include <QObject> | 40 | #include <QObject> |
41 | #include <QSettings> | ||
42 | |||
43 | #include "syntaxcompleter.h" | ||
41 | 44 | ||
42 | QT_BEGIN_NAMESPACE | 45 | QT_BEGIN_NAMESPACE |
43 | class QPaintEvent; | 46 | class QPaintEvent; |
@@ -68,15 +71,22 @@ public: | |||
68 | 71 | ||
69 | protected: | 72 | protected: |
70 | void resizeEvent(QResizeEvent *event); | 73 | void resizeEvent(QResizeEvent *event); |
74 | void keyPressEvent(QKeyEvent *event); | ||
71 | 75 | ||
72 | private slots: | 76 | private slots: |
73 | void updateLineNumberAreaWidth(int newBlockCount); | 77 | void updateLineNumberAreaWidth(int newBlockCount); |
74 | void updateLineNumberArea(const QRect &, int); | 78 | void updateLineNumberArea(const QRect &, int); |
79 | void cursorMoved(); | ||
75 | 80 | ||
76 | private: | 81 | private: |
77 | QWidget *lineNumberArea; | 82 | QWidget *lineNumberArea; |
78 | QList<int> errors; | 83 | QList<int> errors; |
79 | QColor errorColor; | 84 | QColor errorColor; |
85 | SyntaxCompleter completer; | ||
86 | QSettings settings; | ||
87 | |||
88 | int tagBegin; | ||
89 | int tagEnd; | ||
80 | }; | 90 | }; |
81 | 91 | ||
82 | //![codeeditordefinition] | 92 | //![codeeditordefinition] |
diff --git a/utils/themeeditor/gui/preferencesdialog.cpp b/utils/themeeditor/gui/preferencesdialog.cpp index 34ee8c9b22..d3aec1234d 100644 --- a/utils/themeeditor/gui/preferencesdialog.cpp +++ b/utils/themeeditor/gui/preferencesdialog.cpp | |||
@@ -47,6 +47,12 @@ void PreferencesDialog::loadSettings() | |||
47 | loadColors(); | 47 | loadColors(); |
48 | loadFont(); | 48 | loadFont(); |
49 | loadRender(); | 49 | loadRender(); |
50 | |||
51 | QSettings settings; | ||
52 | settings.beginGroup("CodeEditor"); | ||
53 | ui->completionBox->setChecked(settings.value("completeSyntax", | ||
54 | false).toBool()); | ||
55 | settings.endGroup(); | ||
50 | } | 56 | } |
51 | 57 | ||
52 | void PreferencesDialog::loadColors() | 58 | void PreferencesDialog::loadColors() |
@@ -144,6 +150,12 @@ void PreferencesDialog::saveSettings() | |||
144 | saveColors(); | 150 | saveColors(); |
145 | saveFont(); | 151 | saveFont(); |
146 | saveRender(); | 152 | saveRender(); |
153 | |||
154 | QSettings settings; | ||
155 | settings.beginGroup("CodeEditor"); | ||
156 | settings.setValue("completeSyntax", ui->completionBox->isChecked()); | ||
157 | settings.endGroup(); | ||
158 | |||
147 | } | 159 | } |
148 | 160 | ||
149 | void PreferencesDialog::saveColors() | 161 | void PreferencesDialog::saveColors() |
diff --git a/utils/themeeditor/gui/preferencesdialog.ui b/utils/themeeditor/gui/preferencesdialog.ui index 384f7fced3..c57a38ce20 100644 --- a/utils/themeeditor/gui/preferencesdialog.ui +++ b/utils/themeeditor/gui/preferencesdialog.ui | |||
@@ -7,7 +7,7 @@ | |||
7 | <x>0</x> | 7 | <x>0</x> |
8 | <y>0</y> | 8 | <y>0</y> |
9 | <width>370</width> | 9 | <width>370</width> |
10 | <height>295</height> | 10 | <height>304</height> |
11 | </rect> | 11 | </rect> |
12 | </property> | 12 | </property> |
13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
@@ -63,6 +63,13 @@ | |||
63 | </property> | 63 | </property> |
64 | </widget> | 64 | </widget> |
65 | </item> | 65 | </item> |
66 | <item row="2" column="1"> | ||
67 | <widget class="QCheckBox" name="completionBox"> | ||
68 | <property name="text"> | ||
69 | <string>Enable Syntax Completion</string> | ||
70 | </property> | ||
71 | </widget> | ||
72 | </item> | ||
66 | </layout> | 73 | </layout> |
67 | </item> | 74 | </item> |
68 | <item> | 75 | <item> |
diff --git a/utils/themeeditor/gui/syntaxcompleter.cpp b/utils/themeeditor/gui/syntaxcompleter.cpp new file mode 100644 index 0000000000..0b4f05f487 --- /dev/null +++ b/utils/themeeditor/gui/syntaxcompleter.cpp | |||
@@ -0,0 +1,83 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <QFile> | ||
23 | #include <QTreeWidgetItem> | ||
24 | |||
25 | #include "syntaxcompleter.h" | ||
26 | |||
27 | SyntaxCompleter::SyntaxCompleter(QWidget *parent) : | ||
28 | QTreeWidget(parent) | ||
29 | { | ||
30 | setHeaderHidden(true); | ||
31 | |||
32 | setWordWrap(true); | ||
33 | setColumnCount(2); | ||
34 | |||
35 | QFile fin(":/resources/tagdb"); | ||
36 | fin.open(QFile::ReadOnly | QFile::Text); | ||
37 | |||
38 | while(!fin.atEnd()) | ||
39 | { | ||
40 | QString line(fin.readLine()); | ||
41 | if(line.trimmed().length() == 0 || line.trimmed()[0] == '#') | ||
42 | continue; | ||
43 | |||
44 | QStringList split = line.split(":"); | ||
45 | QStringList tag; | ||
46 | tag.append(split[0].trimmed()); | ||
47 | tag.append(split[1].trimmed()); | ||
48 | tags.insert(split[0].trimmed().toLower(), tag); | ||
49 | } | ||
50 | |||
51 | filter(""); | ||
52 | |||
53 | resizeColumnToContents(0); | ||
54 | setColumnWidth(0, columnWidth(0) + 10); // Auto-resize is too small | ||
55 | |||
56 | } | ||
57 | |||
58 | void SyntaxCompleter::filter(QString text) | ||
59 | { | ||
60 | clear(); | ||
61 | |||
62 | for(QMap<QString, QStringList>::iterator i = tags.begin() | ||
63 | ; i != tags.end(); i++) | ||
64 | { | ||
65 | if(text.length() == 1) | ||
66 | { | ||
67 | if(text[0].toLower() != i.key()[0]) | ||
68 | continue; | ||
69 | } | ||
70 | else if(text.length() == 2) | ||
71 | { | ||
72 | if(text[0].toLower() != i.key()[0] || i.key().length() < 2 | ||
73 | || text[1].toLower() != i.key()[1]) | ||
74 | continue; | ||
75 | } | ||
76 | else if(text.length() > 2) | ||
77 | { | ||
78 | hide(); | ||
79 | } | ||
80 | |||
81 | addTopLevelItem(new QTreeWidgetItem(i.value())); | ||
82 | } | ||
83 | } | ||
diff --git a/utils/themeeditor/gui/syntaxcompleter.h b/utils/themeeditor/gui/syntaxcompleter.h new file mode 100644 index 0000000000..f0e0794d63 --- /dev/null +++ b/utils/themeeditor/gui/syntaxcompleter.h | |||
@@ -0,0 +1,44 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef SYNTAXCOMPLETER_H | ||
23 | #define SYNTAXCOMPLETER_H | ||
24 | |||
25 | #include <QTreeWidget> | ||
26 | |||
27 | class SyntaxCompleter : public QTreeWidget | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | public: | ||
31 | SyntaxCompleter(QWidget *parent = 0); | ||
32 | void filter(QString text); | ||
33 | |||
34 | signals: | ||
35 | |||
36 | public slots: | ||
37 | |||
38 | private: | ||
39 | QMap<QString, QStringList> tags; | ||
40 | QStringList keys; | ||
41 | |||
42 | }; | ||
43 | |||
44 | #endif // SYNTAXCOMPLETER_H | ||
diff --git a/utils/themeeditor/resources.qrc b/utils/themeeditor/resources.qrc index 9674595834..c00953a3c0 100644 --- a/utils/themeeditor/resources.qrc +++ b/utils/themeeditor/resources.qrc | |||
@@ -15,6 +15,7 @@ | |||
15 | <file>resources/rwnd.png</file> | 15 | <file>resources/rwnd.png</file> |
16 | <file>resources/cursor.png</file> | 16 | <file>resources/cursor.png</file> |
17 | <file>resources/lines.png</file> | 17 | <file>resources/lines.png</file> |
18 | <file alias="tagdb">resources/tagdb</file> | ||
18 | </qresource> | 19 | </qresource> |
19 | <qresource prefix="/render"> | 20 | <qresource prefix="/render"> |
20 | <file alias="scenebg.png">resources/render/scenebg.png</file> | 21 | <file alias="scenebg.png">resources/render/scenebg.png</file> |
diff --git a/utils/themeeditor/resources/tagdb b/utils/themeeditor/resources/tagdb new file mode 100644 index 0000000000..d6b230144e --- /dev/null +++ b/utils/themeeditor/resources/tagdb | |||
@@ -0,0 +1,10 @@ | |||
1 | z : Ending tag | ||
2 | aa : Should come at the beginning of everything | ||
3 | za : Should come after z | ||
4 | y : Should come before z | ||
5 | T : Test tag 1 | ||
6 | Ta : Test tag 2 | ||
7 | Tb : Test tag 3 | ||
8 | U : Another test | ||
9 | Ua : Yet another test | ||
10 | Uc : A sixth test | ||
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index a58b878692..bf2be3abd8 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro | |||
@@ -1,11 +1,10 @@ | |||
1 | #Setting the binary name | 1 | # Setting the binary name |
2 | TARGET = rbthemeeditor | 2 | TARGET = rbthemeeditor |
3 | VERSION = 0.5 | 3 | VERSION = 0.5 |
4 | 4 | CONFIG(debug) { | |
5 | CONFIG(debug){ | ||
6 | REVISION = $$system(svnversion) | 5 | REVISION = $$system(svnversion) |
7 | VERSION=$$join(VERSION,,,r) | 6 | VERSION = $$join(VERSION,,,r) |
8 | VERSION=$$join(VERSION,,,$$REVISION) | 7 | VERSION = $$join(VERSION,,,$$REVISION) |
9 | } | 8 | } |
10 | 9 | ||
11 | # Adding network support | 10 | # Adding network support |
@@ -106,7 +105,8 @@ HEADERS += models/parsetreemodel.h \ | |||
106 | qtfindreplacedialog/findform.h \ | 105 | qtfindreplacedialog/findform.h \ |
107 | qtfindreplacedialog/finddialog.h \ | 106 | qtfindreplacedialog/finddialog.h \ |
108 | gui/projectexporter.h \ | 107 | gui/projectexporter.h \ |
109 | gui/targetdownloader.h | 108 | gui/targetdownloader.h \ |
109 | gui/syntaxcompleter.h | ||
110 | SOURCES += main.cpp \ | 110 | SOURCES += main.cpp \ |
111 | models/parsetreemodel.cpp \ | 111 | models/parsetreemodel.cpp \ |
112 | models/parsetreenode.cpp \ | 112 | models/parsetreenode.cpp \ |
@@ -146,7 +146,8 @@ SOURCES += main.cpp \ | |||
146 | qtfindreplacedialog/findform.cpp \ | 146 | qtfindreplacedialog/findform.cpp \ |
147 | qtfindreplacedialog/finddialog.cpp \ | 147 | qtfindreplacedialog/finddialog.cpp \ |
148 | gui/projectexporter.cpp \ | 148 | gui/projectexporter.cpp \ |
149 | gui/targetdownloader.cpp | 149 | gui/targetdownloader.cpp \ |
150 | gui/syntaxcompleter.cpp | ||
150 | OTHER_FILES += README \ | 151 | OTHER_FILES += README \ |
151 | resources/windowicon.png \ | 152 | resources/windowicon.png \ |
152 | resources/appicon.xcf \ | 153 | resources/appicon.xcf \ |
@@ -171,7 +172,8 @@ OTHER_FILES += README \ | |||
171 | resources/targetdb \ | 172 | resources/targetdb \ |
172 | quazip/README.ROCKBOX \ | 173 | quazip/README.ROCKBOX \ |
173 | quazip/LICENSE.GPL \ | 174 | quazip/LICENSE.GPL \ |
174 | qtfindreplacedialog/dialogs.pro | 175 | qtfindreplacedialog/dialogs.pro \ |
176 | resources/tagdb | ||
175 | FORMS += gui/editorwindow.ui \ | 177 | FORMS += gui/editorwindow.ui \ |
176 | gui/preferencesdialog.ui \ | 178 | gui/preferencesdialog.ui \ |
177 | gui/configdocument.ui \ | 179 | gui/configdocument.ui \ |