summaryrefslogtreecommitdiff
path: root/utils/themeeditor
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor')
-rw-r--r--utils/themeeditor/gui/codeeditor.cpp59
-rw-r--r--utils/themeeditor/gui/codeeditor.h2
-rw-r--r--utils/themeeditor/gui/preferencesdialog.cpp2
-rw-r--r--utils/themeeditor/gui/preferencesdialog.ui3
-rw-r--r--utils/themeeditor/gui/syntaxcompleter.cpp25
-rw-r--r--utils/themeeditor/gui/syntaxcompleter.h4
-rw-r--r--utils/themeeditor/resources/deviceoptions20
-rw-r--r--utils/themeeditor/resources/tagdb86
8 files changed, 174 insertions, 27 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
123void 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
120void CodeEditor::resizeEvent(QResizeEvent *e) 143void CodeEditor::resizeEvent(QResizeEvent *e)
@@ -131,7 +154,7 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
131void CodeEditor::keyPressEvent(QKeyEvent *event) 154void 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
81private: 82private:
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
27SyntaxCompleter::SyntaxCompleter(QWidget *parent) : 28SyntaxCompleter::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
58void SyntaxCompleter::filter(QString text) 60void 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
27class CodeEditor;
28
27class SyntaxCompleter : public QTreeWidget 29class SyntaxCompleter : public QTreeWidget
28{ 30{
29Q_OBJECT 31Q_OBJECT
30public: 32public:
31 SyntaxCompleter(QWidget *parent = 0); 33 SyntaxCompleter(CodeEditor *parent = 0);
32 void filter(QString text); 34 void filter(QString text);
33 35
34signals: 36signals:
diff --git a/utils/themeeditor/resources/deviceoptions b/utils/themeeditor/resources/deviceoptions
index cc349c5418..4b883ae422 100644
--- a/utils/themeeditor/resources/deviceoptions
+++ b/utils/themeeditor/resources/deviceoptions
@@ -1,3 +1,23 @@
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############################################################################/
1# This file defines the options for the device configuration panel 21# This file defines the options for the device configuration panel
2# Declare a section with a line containing a string inside brackets, i.e. 22# Declare a section with a line containing a string inside brackets, i.e.
3# [Some Section] 23# [Some Section]
diff --git a/utils/themeeditor/resources/tagdb b/utils/themeeditor/resources/tagdb
index d6b230144e..8aa58fd0f8 100644
--- a/utils/themeeditor/resources/tagdb
+++ b/utils/themeeditor/resources/tagdb
@@ -1,10 +1,76 @@
1z : Ending tag 1###########################################################################
2aa : Should come at the beginning of everything 2# __________ __ ___.
3za : Should come after z 3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4y : Should come before z 4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5T : Test tag 1 5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6Ta : Test tag 2 6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7Tb : Test tag 3 7# \/ \/ \/ \/ \/
8U : Another test 8# $Id$
9Ua : Yet another test 9#
10Uc : A sixth test 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# Enter tags in the format "tag : Description"
23# Empty lines and lines beginning with '#' are ignored
24# The descriptions are going to be displayed in a little auto-complete
25# pop-up, so keep them as terse as possible
26#
27# Like the deviceoptions file, this is compiled into the executable and
28# could segfault things if improperly formatted, so be careful---treat it
29# like part of the source code, because it is.
30#
31
32# Viewport tags
33
34V : Viewport declaration
35Vl : Viewport preload
36Vd : Viewport display
37Vi : Custom UI viewport
38VI : Pick custom UI viewport
39Vf : Foreground color
40Vb : Background color
41
42# Fonts
43
44Fl : Load a font
45
46# Status Bar
47
48we : Enable status bar
49wd : Disable status bar
50wi : Display inbuilt status bar
51
52# ID3 Info
53ia : Artist
54ic : Composer
55iA : Album artist
56id : Album Name
57iG : Grouping
58in : Track #
59it : Track Title
60iC : Comment
61iv : ID3 version
62iy : ID3 year
63ik : Disc number
64
65# Next track ID3
66Ia : Next Artist
67Ic : Next Composer
68IA : Next Album artist
69Id : Next Album Name
70IG : Next Grouping
71In : Next Track #
72It : Next Track Title
73IC : Next Comment
74Iv : Next ID3 version
75Iy : Next ID3 year
76Ik : Next Disc number