diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-07-30 08:38:38 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-30 08:38:38 +0000 |
commit | ba41fa537a432210147586b1442ab67b6d400d18 (patch) | |
tree | d65b1bb4e7d20de518b40db98fb4399f419d36be /utils/themeeditor/gui | |
parent | f8dd370ff8ece4d32589767dc4a9b43398c1cf7e (diff) | |
download | rockbox-ba41fa537a432210147586b1442ab67b6d400d18.tar.gz rockbox-ba41fa537a432210147586b1442ab67b6d400d18.zip |
Theme Editor: Made auto-complete functional and enabled it by default. Added a small subset of the available tags to the tagdb file, filling it out is todo
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27625 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/gui')
-rw-r--r-- | utils/themeeditor/gui/codeeditor.cpp | 59 | ||||
-rw-r--r-- | utils/themeeditor/gui/codeeditor.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/gui/preferencesdialog.cpp | 2 | ||||
-rw-r--r-- | utils/themeeditor/gui/preferencesdialog.ui | 3 | ||||
-rw-r--r-- | utils/themeeditor/gui/syntaxcompleter.cpp | 25 | ||||
-rw-r--r-- | utils/themeeditor/gui/syntaxcompleter.h | 4 |
6 files changed, 78 insertions, 17 deletions
diff --git a/utils/themeeditor/gui/codeeditor.cpp b/utils/themeeditor/gui/codeeditor.cpp index 44f331d280..3858460385 100644 --- a/utils/themeeditor/gui/codeeditor.cpp +++ b/utils/themeeditor/gui/codeeditor.cpp | |||
@@ -107,6 +107,11 @@ void CodeEditor::cursorMoved() | |||
107 | /* Closing the completer if the cursor has moved out of its bounds */ | 107 | /* Closing the completer if the cursor has moved out of its bounds */ |
108 | if(completer.isVisible()) | 108 | if(completer.isVisible()) |
109 | { | 109 | { |
110 | if(document()->toPlainText().length() > docLength) | ||
111 | tagEnd++; | ||
112 | else if(document()->toPlainText().length() < docLength) | ||
113 | tagEnd--; | ||
114 | |||
110 | if(textCursor().position() < tagBegin | 115 | if(textCursor().position() < tagBegin |
111 | || textCursor().position() > tagEnd) | 116 | || textCursor().position() > tagEnd) |
112 | { | 117 | { |
@@ -115,6 +120,24 @@ void CodeEditor::cursorMoved() | |||
115 | } | 120 | } |
116 | } | 121 | } |
117 | 122 | ||
123 | void CodeEditor::insertTag() | ||
124 | { | ||
125 | /* Clearing the typed tag and inserting one from the completer */ | ||
126 | QTextCursor at(document()); | ||
127 | at.setPosition(tagBegin, QTextCursor::MoveAnchor); | ||
128 | while(document()->characterAt(at.position()) == QChar('%') | ||
129 | || document()->characterAt(at.position()) == '?') | ||
130 | at.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, 1); | ||
131 | |||
132 | at.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, | ||
133 | tagEnd - at.position()); | ||
134 | at.removeSelectedText(); | ||
135 | |||
136 | at.insertText(completer.currentItem()->text(0)); | ||
137 | |||
138 | completer.hide(); | ||
139 | } | ||
140 | |||
118 | //![resizeEvent] | 141 | //![resizeEvent] |
119 | 142 | ||
120 | void CodeEditor::resizeEvent(QResizeEvent *e) | 143 | void CodeEditor::resizeEvent(QResizeEvent *e) |
@@ -131,7 +154,7 @@ void CodeEditor::resizeEvent(QResizeEvent *e) | |||
131 | void CodeEditor::keyPressEvent(QKeyEvent *event) | 154 | void CodeEditor::keyPressEvent(QKeyEvent *event) |
132 | { | 155 | { |
133 | 156 | ||
134 | if(!settings.value("completeSyntax", false).toBool()) | 157 | if(!settings.value("completeSyntax", true).toBool()) |
135 | { | 158 | { |
136 | QPlainTextEdit::keyPressEvent(event); | 159 | QPlainTextEdit::keyPressEvent(event); |
137 | return; | 160 | return; |
@@ -154,10 +177,22 @@ void CodeEditor::keyPressEvent(QKeyEvent *event) | |||
154 | < completer.topLevelItemCount() - 1) | 177 | < completer.topLevelItemCount() - 1) |
155 | QApplication::sendEvent(&completer, event); | 178 | QApplication::sendEvent(&completer, event); |
156 | } | 179 | } |
157 | else if(event->key() == Qt::Key_Backspace) | 180 | else if(event->key() == Qt::Key_Backspace |
181 | || event->key() == Qt::Key_Delete) | ||
158 | { | 182 | { |
159 | tagEnd--; | 183 | docLength = document()->toPlainText().length(); |
160 | QPlainTextEdit::keyPressEvent(event); | 184 | QPlainTextEdit::keyPressEvent(event); |
185 | |||
186 | QString filterText; | ||
187 | |||
188 | for(int i = tagBegin; i < tagEnd; i++) | ||
189 | { | ||
190 | QChar c = document()->characterAt(i); | ||
191 | if(c != '%' && c != '?') | ||
192 | filterText.append(c); | ||
193 | } | ||
194 | |||
195 | completer.filter(filterText); | ||
161 | } | 196 | } |
162 | else if(event->key() == Qt::Key_Escape) | 197 | else if(event->key() == Qt::Key_Escape) |
163 | { | 198 | { |
@@ -165,14 +200,15 @@ void CodeEditor::keyPressEvent(QKeyEvent *event) | |||
165 | completer.hide(); | 200 | completer.hide(); |
166 | QPlainTextEdit::keyPressEvent(event); | 201 | QPlainTextEdit::keyPressEvent(event); |
167 | } | 202 | } |
168 | else if(event->key() == Qt::Key_Enter) | 203 | else if(event->key() == Qt::Key_Return) |
169 | { | 204 | { |
170 | /* The enter key inserts the currently selected tag */ | 205 | /* The enter key inserts the currently selected tag */ |
206 | insertTag(); | ||
171 | } | 207 | } |
172 | else if(event->key() == Qt::Key_Question) | 208 | else if(event->key() == Qt::Key_Question) |
173 | { | 209 | { |
174 | /* The question mark doesn't filter the list */ | 210 | /* The question mark doesn't filter the list */ |
175 | tagEnd++; | 211 | docLength = document()->toPlainText().length(); |
176 | QPlainTextEdit::keyPressEvent(event); | 212 | QPlainTextEdit::keyPressEvent(event); |
177 | } | 213 | } |
178 | else if(event->key() == Qt::Key_Left | 214 | else if(event->key() == Qt::Key_Left |
@@ -184,10 +220,19 @@ void CodeEditor::keyPressEvent(QKeyEvent *event) | |||
184 | else | 220 | else |
185 | { | 221 | { |
186 | /* Otherwise, we have to filter the list */ | 222 | /* Otherwise, we have to filter the list */ |
187 | tagEnd++; | 223 | docLength = document()->toPlainText().length(); |
188 | QPlainTextEdit::keyPressEvent(event); | 224 | QPlainTextEdit::keyPressEvent(event); |
189 | 225 | ||
190 | QString filterText = ""; | 226 | QString filterText; |
227 | |||
228 | for(int i = tagBegin; i < tagEnd; i++) | ||
229 | { | ||
230 | QChar c = document()->characterAt(i); | ||
231 | if(c != '%' && c != '?') | ||
232 | filterText.append(c); | ||
233 | } | ||
234 | |||
235 | completer.filter(filterText); | ||
191 | } | 236 | } |
192 | } | 237 | } |
193 | else | 238 | else |
diff --git a/utils/themeeditor/gui/codeeditor.h b/utils/themeeditor/gui/codeeditor.h index a25c5664f0..21f1c561cf 100644 --- a/utils/themeeditor/gui/codeeditor.h +++ b/utils/themeeditor/gui/codeeditor.h | |||
@@ -77,6 +77,7 @@ private slots: | |||
77 | void updateLineNumberAreaWidth(int newBlockCount); | 77 | void updateLineNumberAreaWidth(int newBlockCount); |
78 | void updateLineNumberArea(const QRect &, int); | 78 | void updateLineNumberArea(const QRect &, int); |
79 | void cursorMoved(); | 79 | void cursorMoved(); |
80 | void insertTag(); | ||
80 | 81 | ||
81 | private: | 82 | private: |
82 | QWidget *lineNumberArea; | 83 | QWidget *lineNumberArea; |
@@ -87,6 +88,7 @@ private: | |||
87 | 88 | ||
88 | int tagBegin; | 89 | int tagBegin; |
89 | int tagEnd; | 90 | int tagEnd; |
91 | int docLength; | ||
90 | }; | 92 | }; |
91 | 93 | ||
92 | //![codeeditordefinition] | 94 | //![codeeditordefinition] |
diff --git a/utils/themeeditor/gui/preferencesdialog.cpp b/utils/themeeditor/gui/preferencesdialog.cpp index d3aec1234d..2c4acaee84 100644 --- a/utils/themeeditor/gui/preferencesdialog.cpp +++ b/utils/themeeditor/gui/preferencesdialog.cpp | |||
@@ -51,7 +51,7 @@ void PreferencesDialog::loadSettings() | |||
51 | QSettings settings; | 51 | QSettings settings; |
52 | settings.beginGroup("CodeEditor"); | 52 | settings.beginGroup("CodeEditor"); |
53 | ui->completionBox->setChecked(settings.value("completeSyntax", | 53 | ui->completionBox->setChecked(settings.value("completeSyntax", |
54 | false).toBool()); | 54 | true).toBool()); |
55 | settings.endGroup(); | 55 | settings.endGroup(); |
56 | } | 56 | } |
57 | 57 | ||
diff --git a/utils/themeeditor/gui/preferencesdialog.ui b/utils/themeeditor/gui/preferencesdialog.ui index c57a38ce20..f63ab4748f 100644 --- a/utils/themeeditor/gui/preferencesdialog.ui +++ b/utils/themeeditor/gui/preferencesdialog.ui | |||
@@ -68,6 +68,9 @@ | |||
68 | <property name="text"> | 68 | <property name="text"> |
69 | <string>Enable Syntax Completion</string> | 69 | <string>Enable Syntax Completion</string> |
70 | </property> | 70 | </property> |
71 | <property name="checked"> | ||
72 | <bool>true</bool> | ||
73 | </property> | ||
71 | </widget> | 74 | </widget> |
72 | </item> | 75 | </item> |
73 | </layout> | 76 | </layout> |
diff --git a/utils/themeeditor/gui/syntaxcompleter.cpp b/utils/themeeditor/gui/syntaxcompleter.cpp index 0b4f05f487..8baace46b1 100644 --- a/utils/themeeditor/gui/syntaxcompleter.cpp +++ b/utils/themeeditor/gui/syntaxcompleter.cpp | |||
@@ -23,15 +23,20 @@ | |||
23 | #include <QTreeWidgetItem> | 23 | #include <QTreeWidgetItem> |
24 | 24 | ||
25 | #include "syntaxcompleter.h" | 25 | #include "syntaxcompleter.h" |
26 | #include "codeeditor.h" | ||
26 | 27 | ||
27 | SyntaxCompleter::SyntaxCompleter(QWidget *parent) : | 28 | SyntaxCompleter::SyntaxCompleter(CodeEditor *parent) : |
28 | QTreeWidget(parent) | 29 | QTreeWidget(parent) |
29 | { | 30 | { |
30 | setHeaderHidden(true); | 31 | setHeaderHidden(true); |
32 | setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); | ||
31 | 33 | ||
32 | setWordWrap(true); | 34 | setWordWrap(true); |
33 | setColumnCount(2); | 35 | setColumnCount(2); |
34 | 36 | ||
37 | QObject::connect(this, SIGNAL(activated(QModelIndex)), | ||
38 | parent, SLOT(insertTag())); | ||
39 | |||
35 | QFile fin(":/resources/tagdb"); | 40 | QFile fin(":/resources/tagdb"); |
36 | fin.open(QFile::ReadOnly | QFile::Text); | 41 | fin.open(QFile::ReadOnly | QFile::Text); |
37 | 42 | ||
@@ -45,14 +50,11 @@ SyntaxCompleter::SyntaxCompleter(QWidget *parent) : | |||
45 | QStringList tag; | 50 | QStringList tag; |
46 | tag.append(split[0].trimmed()); | 51 | tag.append(split[0].trimmed()); |
47 | tag.append(split[1].trimmed()); | 52 | tag.append(split[1].trimmed()); |
48 | tags.insert(split[0].trimmed().toLower(), tag); | 53 | tags.insertMulti(split[0].trimmed().toLower(), tag); |
49 | } | 54 | } |
50 | 55 | ||
51 | filter(""); | 56 | filter(""); |
52 | 57 | ||
53 | resizeColumnToContents(0); | ||
54 | setColumnWidth(0, columnWidth(0) + 10); // Auto-resize is too small | ||
55 | |||
56 | } | 58 | } |
57 | 59 | ||
58 | void SyntaxCompleter::filter(QString text) | 60 | void SyntaxCompleter::filter(QString text) |
@@ -64,13 +66,13 @@ void SyntaxCompleter::filter(QString text) | |||
64 | { | 66 | { |
65 | if(text.length() == 1) | 67 | if(text.length() == 1) |
66 | { | 68 | { |
67 | if(text[0].toLower() != i.key()[0]) | 69 | if(text[0].toLower() != i.key()[0].toLower()) |
68 | continue; | 70 | continue; |
69 | } | 71 | } |
70 | else if(text.length() == 2) | 72 | else if(text.length() == 2) |
71 | { | 73 | { |
72 | if(text[0].toLower() != i.key()[0] || i.key().length() < 2 | 74 | if(text[0].toLower() != i.key()[0].toLower() || i.key().length() < 2 |
73 | || text[1].toLower() != i.key()[1]) | 75 | || text[1].toLower() != i.key()[1].toLower()) |
74 | continue; | 76 | continue; |
75 | } | 77 | } |
76 | else if(text.length() > 2) | 78 | else if(text.length() > 2) |
@@ -80,4 +82,11 @@ void SyntaxCompleter::filter(QString text) | |||
80 | 82 | ||
81 | addTopLevelItem(new QTreeWidgetItem(i.value())); | 83 | addTopLevelItem(new QTreeWidgetItem(i.value())); |
82 | } | 84 | } |
85 | |||
86 | if(topLevelItemCount() > 0) | ||
87 | setCurrentIndex(indexFromItem(topLevelItem(0))); | ||
88 | |||
89 | resizeColumnToContents(0); | ||
90 | setColumnWidth(0, columnWidth(0) + 10); // Auto-resize is too small | ||
91 | resizeColumnToContents(1); | ||
83 | } | 92 | } |
diff --git a/utils/themeeditor/gui/syntaxcompleter.h b/utils/themeeditor/gui/syntaxcompleter.h index f0e0794d63..99a1c77c37 100644 --- a/utils/themeeditor/gui/syntaxcompleter.h +++ b/utils/themeeditor/gui/syntaxcompleter.h | |||
@@ -24,11 +24,13 @@ | |||
24 | 24 | ||
25 | #include <QTreeWidget> | 25 | #include <QTreeWidget> |
26 | 26 | ||
27 | class CodeEditor; | ||
28 | |||
27 | class SyntaxCompleter : public QTreeWidget | 29 | class SyntaxCompleter : public QTreeWidget |
28 | { | 30 | { |
29 | Q_OBJECT | 31 | Q_OBJECT |
30 | public: | 32 | public: |
31 | SyntaxCompleter(QWidget *parent = 0); | 33 | SyntaxCompleter(CodeEditor *parent = 0); |
32 | void filter(QString text); | 34 | void filter(QString text); |
33 | 35 | ||
34 | signals: | 36 | signals: |