aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/tagwidget.cpp
diff options
context:
space:
mode:
authorGravatar Maximilian Güntner <maximilian.guentner@gmail.com>2013-11-02 17:04:18 +0100
committerGravatar Maximilian Güntner <maximilian.guentner@gmail.com>2013-11-02 17:10:34 +0100
commitc4d8b6a4d5907def9538b024030dc0980cc4182b (patch)
tree5056491e7f73cbb7c5bcf63d2da06ac35ad90f25 /qt-ui/tagwidget.cpp
parent2967391ffe29970862d7baa0ac8396b102716b16 (diff)
downloadsubsurface-c4d8b6a4d5907def9538b024030dc0980cc4182b.tar.gz
Fix the inconsistent behaviour of QCompleter
The TagWidget behaves now similiar to a QLineEdit. Pressing Enter/Return will now close the completion widget. Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
Diffstat (limited to 'qt-ui/tagwidget.cpp')
-rw-r--r--qt-ui/tagwidget.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/qt-ui/tagwidget.cpp b/qt-ui/tagwidget.cpp
index bcefe5704..673242cfa 100644
--- a/qt-ui/tagwidget.cpp
+++ b/qt-ui/tagwidget.cpp
@@ -1,10 +1,12 @@
#include "tagwidget.h"
#include <QPair>
#include <QDebug>
+#include <QAbstractItemView>
TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL)
{
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reparse()));
+ connect(this, SIGNAL(textChanged()), this, SLOT(reparse()));
addColor(QColor(0x00, 0xAE, 0xFF));
addColor(QColor(0x00, 0x78, 0xB0));
@@ -15,6 +17,7 @@ void TagWidget::setCompleter(QCompleter *completer)
m_completer = completer;
m_completer->setWidget(this);
connect(m_completer, SIGNAL(activated(QString)), this, SLOT(completionSelected(QString)));
+ connect(m_completer, SIGNAL(highlighted(QString)), this, SLOT(completionSelected(QString)));
}
QPair<int,int> TagWidget::getCursorTagPosition() {
@@ -98,7 +101,18 @@ void TagWidget::reparse()
currentText = "";
if (m_completer) {
m_completer->setCompletionPrefix(currentText);
- m_completer->complete();
+ if (m_completer->completionCount() == 1) {
+ if (m_completer->currentCompletion() == currentText) {
+ QAbstractItemView *popup = m_completer->popup();
+ if (popup)
+ popup->hide();
+ }
+ else
+ m_completer->complete();
+
+ } else {
+ m_completer->complete();
+ }
}
}
@@ -133,3 +147,21 @@ void TagWidget::clear() {
GroupedLineEdit::clear();
blockSignals(false);
}
+
+void TagWidget::keyPressEvent(QKeyEvent *e) {
+ switch (e->key()) {
+ case Qt::Key_Return:
+ case Qt::Key_Enter:
+ /*
+ * Fake the QLineEdit behaviour by simply
+ * closing the QAbstractViewitem
+ */
+ if (m_completer) {
+ QAbstractItemView *popup = m_completer->popup();
+ if (popup)
+ popup->hide();
+ }
+ }
+ GroupedLineEdit::keyPressEvent(e);
+}
+