summaryrefslogtreecommitdiff
path: root/utils/themeeditor/gui/codeeditor.cpp
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-30 01:26:10 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-30 01:26:10 +0000
commitf8dd370ff8ece4d32589767dc4a9b43398c1cf7e (patch)
tree15fe9b11ee498b0e4d9c9ef301ffc15e7cc7d43f /utils/themeeditor/gui/codeeditor.cpp
parent5848f5f72464708aa08cb0bb5060349ae7577265 (diff)
downloadrockbox-f8dd370ff8ece4d32589767dc4a9b43398c1cf7e.zip
rockbox-f8dd370ff8ece4d32589767dc4a9b43398c1cf7e.tar.gz
rockbox-f8dd370ff8ece4d32589767dc4a9b43398c1cf7e.tar.bz2
rockbox-f8dd370ff8ece4d32589767dc4a9b43398c1cf7e.tar.xz
Theme Editor: Began implementing syntax highlighting. What I've accomplished so far isn't particularly useful for anything other than testing, so at the moment it will only function if activated in the preferences dialog
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27624 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to '')
-rw-r--r--utils/themeeditor/gui/codeeditor.cpp105
1 files changed, 104 insertions, 1 deletions
diff --git a/utils/themeeditor/gui/codeeditor.cpp b/utils/themeeditor/gui/codeeditor.cpp
index 49f4410..44f331d 100644
--- a/utils/themeeditor/gui/codeeditor.cpp
+++ b/utils/themeeditor/gui/codeeditor.cpp
@@ -34,12 +34,14 @@
****************************************************************************/
#include <QtGui>
+#include <QApplication>
#include "codeeditor.h"
//![constructor]
-CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
+CodeEditor::CodeEditor(QWidget *parent)
+ : QPlainTextEdit(parent), completer(this)
{
lineNumberArea = new LineNumberArea(this);
@@ -49,6 +51,11 @@ CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
this, SLOT(updateLineNumberArea(QRect,int)));
updateLineNumberAreaWidth(0);
+
+ QObject::connect(this, SIGNAL(cursorPositionChanged()),
+ this, SLOT(cursorMoved()));
+ completer.hide();
+ settings.beginGroup("CodeEditor");
}
//![constructor]
@@ -95,6 +102,19 @@ void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
//![slotUpdateRequest]
+void CodeEditor::cursorMoved()
+{
+ /* Closing the completer if the cursor has moved out of its bounds */
+ if(completer.isVisible())
+ {
+ if(textCursor().position() < tagBegin
+ || textCursor().position() > tagEnd)
+ {
+ completer.hide();
+ }
+ }
+}
+
//![resizeEvent]
void CodeEditor::resizeEvent(QResizeEvent *e)
@@ -108,6 +128,89 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
//![resizeEvent]
+void CodeEditor::keyPressEvent(QKeyEvent *event)
+{
+
+ if(!settings.value("completeSyntax", false).toBool())
+ {
+ QPlainTextEdit::keyPressEvent(event);
+ return;
+ }
+
+ if(completer.isVisible())
+ {
+ /* Handling the completer */
+ if(event->key() == Qt::Key_Up)
+ {
+ /* Up/down arrow presses get sent right along to the completer
+ * to navigate through the list
+ */
+ if(completer.currentIndex().row() > 0)
+ QApplication::sendEvent(&completer, event);
+ }
+ else if(event->key() == Qt::Key_Down)
+ {
+ if(completer.currentIndex().row()
+ < completer.topLevelItemCount() - 1)
+ QApplication::sendEvent(&completer, event);
+ }
+ else if(event->key() == Qt::Key_Backspace)
+ {
+ tagEnd--;
+ QPlainTextEdit::keyPressEvent(event);
+ }
+ else if(event->key() == Qt::Key_Escape)
+ {
+ /* Escape hides the completer */
+ completer.hide();
+ QPlainTextEdit::keyPressEvent(event);
+ }
+ else if(event->key() == Qt::Key_Enter)
+ {
+ /* The enter key inserts the currently selected tag */
+ }
+ else if(event->key() == Qt::Key_Question)
+ {
+ /* The question mark doesn't filter the list */
+ tagEnd++;
+ QPlainTextEdit::keyPressEvent(event);
+ }
+ else if(event->key() == Qt::Key_Left
+ || event->key() == Qt::Key_Right)
+ {
+ /* Left and right keys shouldn't affect tagEnd */
+ QPlainTextEdit::keyPressEvent(event);
+ }
+ else
+ {
+ /* Otherwise, we have to filter the list */
+ tagEnd++;
+ QPlainTextEdit::keyPressEvent(event);
+
+ QString filterText = "";
+ }
+ }
+ else
+ {
+ /* Deciding whether to show the completer */
+ QPlainTextEdit::keyPressEvent(event);
+ if(event->key() == Qt::Key_Percent)
+ {
+ tagBegin = textCursor().position();
+ tagEnd = textCursor().position();
+ completer.filter("");
+ completer.move(cursorRect().left(), cursorRect().bottom());
+ if(completer.frameGeometry().right() > width())
+ completer.move(width() - completer.width(), completer.y());
+ if(completer.frameGeometry().bottom() > height())
+ completer.move(completer.x(),
+ cursorRect().top() - completer.height());
+ completer.show();
+ }
+ }
+
+}
+
//![extraAreaPaintEvent_0]
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)