diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/tagwidget.cpp | 16 | ||||
-rw-r--r-- | qt-ui/tagwidget.h | 1 |
2 files changed, 16 insertions, 1 deletions
diff --git a/qt-ui/tagwidget.cpp b/qt-ui/tagwidget.cpp index 6ba4a0404..2733a144c 100644 --- a/qt-ui/tagwidget.cpp +++ b/qt-ui/tagwidget.cpp @@ -35,7 +35,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))); + connect(m_completer, SIGNAL(highlighted(QString)), this, SLOT(completionHighlighted(QString))); } QPair<int, int> TagWidget::getCursorTagPosition() @@ -152,6 +152,20 @@ void TagWidget::completionSelected(QString completion) emit(textChanged()); } +void TagWidget::completionHighlighted(QString completion) +{ + QPair<int, int> pos; + pos = getCursorTagPosition(); + if (pos.first >= 0 && pos.second > 0) { + setText(text().remove(pos.first, pos.second - pos.first).insert(pos.first, completion)); + setCursorPosition(pos.first + completion.length()); + } else { + setText(completion.append(", ")); + setCursorPosition(text().length()); + } + +} + void TagWidget::setCursorPosition(int position) { blockSignals(true); diff --git a/qt-ui/tagwidget.h b/qt-ui/tagwidget.h index 161ec0601..42c94b4e0 100644 --- a/qt-ui/tagwidget.h +++ b/qt-ui/tagwidget.h @@ -20,6 +20,7 @@ public slots: void reparse(); void completionSelected(QString); + void completionHighlighted(QString); protected: void keyPressEvent(QKeyEvent *e); |