summaryrefslogtreecommitdiff
path: root/utils/themeeditor/gui/codeeditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/gui/codeeditor.cpp')
-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 49f441057c..44f331d280 100644
--- a/utils/themeeditor/gui/codeeditor.cpp
+++ b/utils/themeeditor/gui/codeeditor.cpp
@@ -34,12 +34,14 @@
34****************************************************************************/ 34****************************************************************************/
35 35
36#include <QtGui> 36#include <QtGui>
37#include <QApplication>
37 38
38#include "codeeditor.h" 39#include "codeeditor.h"
39 40
40//![constructor] 41//![constructor]
41 42
42CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) 43CodeEditor::CodeEditor(QWidget *parent)
44 : QPlainTextEdit(parent), completer(this)
43{ 45{
44 lineNumberArea = new LineNumberArea(this); 46 lineNumberArea = new LineNumberArea(this);
45 47
@@ -49,6 +51,11 @@ CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
49 this, SLOT(updateLineNumberArea(QRect,int))); 51 this, SLOT(updateLineNumberArea(QRect,int)));
50 52
51 updateLineNumberAreaWidth(0); 53 updateLineNumberAreaWidth(0);
54
55 QObject::connect(this, SIGNAL(cursorPositionChanged()),
56 this, SLOT(cursorMoved()));
57 completer.hide();
58 settings.beginGroup("CodeEditor");
52} 59}
53 60
54//![constructor] 61//![constructor]
@@ -95,6 +102,19 @@ void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
95 102
96//![slotUpdateRequest] 103//![slotUpdateRequest]
97 104
105void CodeEditor::cursorMoved()
106{
107 /* Closing the completer if the cursor has moved out of its bounds */
108 if(completer.isVisible())
109 {
110 if(textCursor().position() < tagBegin
111 || textCursor().position() > tagEnd)
112 {
113 completer.hide();
114 }
115 }
116}
117
98//![resizeEvent] 118//![resizeEvent]
99 119
100void CodeEditor::resizeEvent(QResizeEvent *e) 120void CodeEditor::resizeEvent(QResizeEvent *e)
@@ -108,6 +128,89 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
108 128
109//![resizeEvent] 129//![resizeEvent]
110 130
131void CodeEditor::keyPressEvent(QKeyEvent *event)
132{
133
134 if(!settings.value("completeSyntax", false).toBool())
135 {
136 QPlainTextEdit::keyPressEvent(event);
137 return;
138 }
139
140 if(completer.isVisible())
141 {
142 /* Handling the completer */
143 if(event->key() == Qt::Key_Up)
144 {
145 /* Up/down arrow presses get sent right along to the completer
146 * to navigate through the list
147 */
148 if(completer.currentIndex().row() > 0)
149 QApplication::sendEvent(&completer, event);
150 }
151 else if(event->key() == Qt::Key_Down)
152 {
153 if(completer.currentIndex().row()
154 < completer.topLevelItemCount() - 1)
155 QApplication::sendEvent(&completer, event);
156 }
157 else if(event->key() == Qt::Key_Backspace)
158 {
159 tagEnd--;
160 QPlainTextEdit::keyPressEvent(event);
161 }
162 else if(event->key() == Qt::Key_Escape)
163 {
164 /* Escape hides the completer */
165 completer.hide();
166 QPlainTextEdit::keyPressEvent(event);
167 }
168 else if(event->key() == Qt::Key_Enter)
169 {
170 /* The enter key inserts the currently selected tag */
171 }
172 else if(event->key() == Qt::Key_Question)
173 {
174 /* The question mark doesn't filter the list */
175 tagEnd++;
176 QPlainTextEdit::keyPressEvent(event);
177 }
178 else if(event->key() == Qt::Key_Left
179 || event->key() == Qt::Key_Right)
180 {
181 /* Left and right keys shouldn't affect tagEnd */
182 QPlainTextEdit::keyPressEvent(event);
183 }
184 else
185 {
186 /* Otherwise, we have to filter the list */
187 tagEnd++;
188 QPlainTextEdit::keyPressEvent(event);
189
190 QString filterText = "";
191 }
192 }
193 else
194 {
195 /* Deciding whether to show the completer */
196 QPlainTextEdit::keyPressEvent(event);
197 if(event->key() == Qt::Key_Percent)
198 {
199 tagBegin = textCursor().position();
200 tagEnd = textCursor().position();
201 completer.filter("");
202 completer.move(cursorRect().left(), cursorRect().bottom());
203 if(completer.frameGeometry().right() > width())
204 completer.move(width() - completer.width(), completer.y());
205 if(completer.frameGeometry().bottom() > height())
206 completer.move(completer.x(),
207 cursorRect().top() - completer.height());
208 completer.show();
209 }
210 }
211
212}
213
111//![extraAreaPaintEvent_0] 214//![extraAreaPaintEvent_0]
112 215
113void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) 216void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)