summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-30 08:38:38 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-30 08:38:38 +0000
commitba41fa537a432210147586b1442ab67b6d400d18 (patch)
treed65b1bb4e7d20de518b40db98fb4399f419d36be /utils/themeeditor
parentf8dd370ff8ece4d32589767dc4a9b43398c1cf7e (diff)
downloadrockbox-ba41fa537a432210147586b1442ab67b6d400d18.tar.gz
rockbox-ba41fa537a432210147586b1442ab67b6d400d18.tar.bz2
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')
-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()
/* Closing the completer if the cursor has moved out of its bounds */
if(completer.isVisible())
{
+ if(document()->toPlainText().length() > docLength)
+ tagEnd++;
+ else if(document()->toPlainText().length() < docLength)
+ tagEnd--;
+
if(textCursor().position() < tagBegin
|| textCursor().position() > tagEnd)
{
@@ -115,6 +120,24 @@ void CodeEditor::cursorMoved()
}
}
+void CodeEditor::insertTag()
+{
+ /* Clearing the typed tag and inserting one from the completer */
+ QTextCursor at(document());
+ at.setPosition(tagBegin, QTextCursor::MoveAnchor);
+ while(document()->characterAt(at.position()) == QChar('%')
+ || document()->characterAt(at.position()) == '?')
+ at.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, 1);
+
+ at.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,
+ tagEnd - at.position());
+ at.removeSelectedText();
+
+ at.insertText(completer.currentItem()->text(0));
+
+ completer.hide();
+}
+
//![resizeEvent]
void CodeEditor::resizeEvent(QResizeEvent *e)
@@ -131,7 +154,7 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
void CodeEditor::keyPressEvent(QKeyEvent *event)
{
- if(!settings.value("completeSyntax", false).toBool())
+ if(!settings.value("completeSyntax", true).toBool())
{
QPlainTextEdit::keyPressEvent(event);
return;
@@ -154,10 +177,22 @@ void CodeEditor::keyPressEvent(QKeyEvent *event)
< completer.topLevelItemCount() - 1)
QApplication::sendEvent(&completer, event);
}
- else if(event->key() == Qt::Key_Backspace)
+ else if(event->key() == Qt::Key_Backspace
+ || event->key() == Qt::Key_Delete)
{
- tagEnd--;
+ docLength = document()->toPlainText().length();
QPlainTextEdit::keyPressEvent(event);
+
+ QString filterText;
+
+ for(int i = tagBegin; i < tagEnd; i++)
+ {
+ QChar c = document()->characterAt(i);
+ if(c != '%' && c != '?')
+ filterText.append(c);
+ }
+
+ completer.filter(filterText);
}
else if(event->key() == Qt::Key_Escape)
{
@@ -165,14 +200,15 @@ void CodeEditor::keyPressEvent(QKeyEvent *event)
completer.hide();
QPlainTextEdit::keyPressEvent(event);
}
- else if(event->key() == Qt::Key_Enter)
+ else if(event->key() == Qt::Key_Return)
{
/* The enter key inserts the currently selected tag */
+ insertTag();
}
else if(event->key() == Qt::Key_Question)
{
/* The question mark doesn't filter the list */
- tagEnd++;
+ docLength = document()->toPlainText().length();
QPlainTextEdit::keyPressEvent(event);
}
else if(event->key() == Qt::Key_Left
@@ -184,10 +220,19 @@ void CodeEditor::keyPressEvent(QKeyEvent *event)
else
{
/* Otherwise, we have to filter the list */
- tagEnd++;
+ docLength = document()->toPlainText().length();
QPlainTextEdit::keyPressEvent(event);
- QString filterText = "";
+ QString filterText;
+
+ for(int i = tagBegin; i < tagEnd; i++)
+ {
+ QChar c = document()->characterAt(i);
+ if(c != '%' && c != '?')
+ filterText.append(c);
+ }
+
+ completer.filter(filterText);
}
}
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:
void updateLineNumberAreaWidth(int newBlockCount);
void updateLineNumberArea(const QRect &, int);
void cursorMoved();
+ void insertTag();
private:
QWidget *lineNumberArea;
@@ -87,6 +88,7 @@ private:
int tagBegin;
int tagEnd;
+ int docLength;
};
//![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()
QSettings settings;
settings.beginGroup("CodeEditor");
ui->completionBox->setChecked(settings.value("completeSyntax",
- false).toBool());
+ true).toBool());
settings.endGroup();
}
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 @@
<property name="text">
<string>Enable Syntax Completion</string>
</property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
</widget>
</item>
</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 @@
#include <QTreeWidgetItem>
#include "syntaxcompleter.h"
+#include "codeeditor.h"
-SyntaxCompleter::SyntaxCompleter(QWidget *parent) :
+SyntaxCompleter::SyntaxCompleter(CodeEditor *parent) :
QTreeWidget(parent)
{
setHeaderHidden(true);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setWordWrap(true);
setColumnCount(2);
+ QObject::connect(this, SIGNAL(activated(QModelIndex)),
+ parent, SLOT(insertTag()));
+
QFile fin(":/resources/tagdb");
fin.open(QFile::ReadOnly | QFile::Text);
@@ -45,14 +50,11 @@ SyntaxCompleter::SyntaxCompleter(QWidget *parent) :
QStringList tag;
tag.append(split[0].trimmed());
tag.append(split[1].trimmed());
- tags.insert(split[0].trimmed().toLower(), tag);
+ tags.insertMulti(split[0].trimmed().toLower(), tag);
}
filter("");
- resizeColumnToContents(0);
- setColumnWidth(0, columnWidth(0) + 10); // Auto-resize is too small
-
}
void SyntaxCompleter::filter(QString text)
@@ -64,13 +66,13 @@ void SyntaxCompleter::filter(QString text)
{
if(text.length() == 1)
{
- if(text[0].toLower() != i.key()[0])
+ if(text[0].toLower() != i.key()[0].toLower())
continue;
}
else if(text.length() == 2)
{
- if(text[0].toLower() != i.key()[0] || i.key().length() < 2
- || text[1].toLower() != i.key()[1])
+ if(text[0].toLower() != i.key()[0].toLower() || i.key().length() < 2
+ || text[1].toLower() != i.key()[1].toLower())
continue;
}
else if(text.length() > 2)
@@ -80,4 +82,11 @@ void SyntaxCompleter::filter(QString text)
addTopLevelItem(new QTreeWidgetItem(i.value()));
}
+
+ if(topLevelItemCount() > 0)
+ setCurrentIndex(indexFromItem(topLevelItem(0)));
+
+ resizeColumnToContents(0);
+ setColumnWidth(0, columnWidth(0) + 10); // Auto-resize is too small
+ resizeColumnToContents(1);
}
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 @@
#include <QTreeWidget>
+class CodeEditor;
+
class SyntaxCompleter : public QTreeWidget
{
Q_OBJECT
public:
- SyntaxCompleter(QWidget *parent = 0);
+ SyntaxCompleter(CodeEditor *parent = 0);
void filter(QString text);
signals:
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 @@
+###########################################################################
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+# $Id$
+#
+# Copyright (C) 2010 Robert Bieber
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+############################################################################/
# This file defines the options for the device configuration panel
# Declare a section with a line containing a string inside brackets, i.e.
# [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 @@
-z : Ending tag
-aa : Should come at the beginning of everything
-za : Should come after z
-y : Should come before z
-T : Test tag 1
-Ta : Test tag 2
-Tb : Test tag 3
-U : Another test
-Ua : Yet another test
-Uc : A sixth test
+###########################################################################
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+# $Id$
+#
+# Copyright (C) 2010 Robert Bieber
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+############################################################################/
+
+# Enter tags in the format "tag : Description"
+# Empty lines and lines beginning with '#' are ignored
+# The descriptions are going to be displayed in a little auto-complete
+# pop-up, so keep them as terse as possible
+#
+# Like the deviceoptions file, this is compiled into the executable and
+# could segfault things if improperly formatted, so be careful---treat it
+# like part of the source code, because it is.
+#
+
+# Viewport tags
+
+V : Viewport declaration
+Vl : Viewport preload
+Vd : Viewport display
+Vi : Custom UI viewport
+VI : Pick custom UI viewport
+Vf : Foreground color
+Vb : Background color
+
+# Fonts
+
+Fl : Load a font
+
+# Status Bar
+
+we : Enable status bar
+wd : Disable status bar
+wi : Display inbuilt status bar
+
+# ID3 Info
+ia : Artist
+ic : Composer
+iA : Album artist
+id : Album Name
+iG : Grouping
+in : Track #
+it : Track Title
+iC : Comment
+iv : ID3 version
+iy : ID3 year
+ik : Disc number
+
+# Next track ID3
+Ia : Next Artist
+Ic : Next Composer
+IA : Next Album artist
+Id : Next Album Name
+IG : Next Grouping
+In : Next Track #
+It : Next Track Title
+IC : Next Comment
+Iv : Next ID3 version
+Iy : Next ID3 year
+Ik : Next Disc number