summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor/gui
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/gui
parentf8dd370ff8ece4d32589767dc4a9b43398c1cf7e (diff)
downloadrockbox-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.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
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()
/* 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: