diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-06-05 12:30:16 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-06-05 12:30:16 (GMT) |
commit | 087267cdfedeab2ae55776f7b7246c47f1d39d6d (patch) | |
tree | 47c5a3bedd1fa7eb61587a7bd17934f0927dbb9f /Swift/QtUI/QtChatWindow.cpp | |
parent | 7bca08eb2829982865f1649483f9aa01b3413b1c (diff) | |
download | swift-contrib-087267cdfedeab2ae55776f7b7246c47f1d39d6d.zip swift-contrib-087267cdfedeab2ae55776f7b7246c47f1d39d6d.tar.bz2 |
Tab completion in MUCs.
Resolves: #440
Diffstat (limited to 'Swift/QtUI/QtChatWindow.cpp')
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index cb4c437..6f49082 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -14,6 +14,8 @@ #include "SystemMessageSnippet.h" #include "QtTextEdit.h" +#include "SwifTools/TabComplete.h" + #include <QApplication> #include <QBoxLayout> #include <QCloseEvent> @@ -80,6 +82,10 @@ QtChatWindow::~QtChatWindow() { } +void QtChatWindow::setTabComplete(TabComplete* completer) { + completer_ = completer; +} + void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) { int key = event->key(); Qt::KeyboardModifiers modifiers = event->modifiers(); @@ -95,11 +101,36 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) { || (key == Qt::Key_Right && modifiers == (Qt::ControlModifier & Qt::ShiftModifier)) ) { emit requestNextTab(); + } else if (key == Qt::Key_Tab) { + tabComplete(); } else { messageLog_->handleKeyPressEvent(event); } } +void QtChatWindow::tabComplete() { + if (!completer_) { + return; + } +// QTextDocument* document = input_->document(); + QTextCursor cursor = input_->textCursor(); + cursor.select(QTextCursor::WordUnderCursor); + QString root = cursor.selectedText(); + bool firstWord = cursor.selectionStart() == 0; + QString suggestion = P2QSTRING(completer_->completeWord(Q2PSTRING(root))); + if (root == suggestion) { + return; + } + cursor.beginEditBlock(); + cursor.removeSelectedText(); + cursor.insertText(suggestion); + if (firstWord) { + // cursor.insertText(":"); + } + //cursor.insertText(" "); + cursor.endEditBlock(); +} + void QtChatWindow::setRosterModel(Roster* roster) { treeWidget_->setRosterModel(roster); } |