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 | |
parent | 7bca08eb2829982865f1649483f9aa01b3413b1c (diff) | |
download | swift-contrib-087267cdfedeab2ae55776f7b7246c47f1d39d6d.zip swift-contrib-087267cdfedeab2ae55776f7b7246c47f1d39d6d.tar.bz2 |
Tab completion in MUCs.
Resolves: #440
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 31 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 1 |
3 files changed, 35 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); } diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 9d3e3a7..ff2f1cb 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -45,6 +45,7 @@ namespace Swift { QtTabbable::AlertType getWidgetAlertState(); void setContactChatState(ChatState::ChatStateType state); void setRosterModel(Roster* roster); + void setTabComplete(TabComplete* completer); protected slots: void qAppFocusChanged(QWidget* old, QWidget* now); @@ -59,6 +60,7 @@ namespace Swift { private: void updateTitleWithUnreadCount(); + void tabComplete(); void addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath, const QString& style); int unreadCount_; @@ -68,6 +70,7 @@ namespace Swift { QtTextEdit* input_; QComboBox *labelsWidget_; QtTreeWidget *treeWidget_; + TabComplete* completer_; std::vector<SecurityLabel> availableLabels_; bool previousMessageWasSelf_; bool previousMessageWasSystem_; diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 451a18c..89fc68f 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -29,6 +29,7 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) { || (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier) || (key == Qt::Key_Left && modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) || (key == Qt::Key_Right && modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) + || (key == Qt::Key_Tab) ) { emit unhandledKeyPressEvent(event); } else { |