X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=gui%2Fchannelwidgetinput.cpp;h=f3276c2adfc2d2b3ab62a1d92a0e6709eb0c24ef;hb=9cbaab34158d0f2e77c18d6ac055582102812553;hp=c029bdd74b9fd6801f591da36f6fbe99dde3d702;hpb=11ee1cf78677b51d8fea2749e8501216a831dfd7;p=quassel.git diff --git a/gui/channelwidgetinput.cpp b/gui/channelwidgetinput.cpp index c029bdd7..f3276c2a 100644 --- a/gui/channelwidgetinput.cpp +++ b/gui/channelwidgetinput.cpp @@ -19,30 +19,58 @@ ***************************************************************************/ #include "channelwidgetinput.h" +#include ChannelWidgetInput::ChannelWidgetInput(QWidget *parent) : QLineEdit(parent) { idx = 0; + tabMode = false; connect(this, SIGNAL(returnPressed()), this, SLOT(enter())); } void ChannelWidgetInput::keyPressEvent(QKeyEvent * event) { - if(event->key() == Qt::Key_Up) { - if(idx > 0) { idx--; setText(history[idx]); } - event->accept(); - } else if(event->key() == Qt::Key_Down) { - if(idx < history.count()) idx++; - if(idx < history.count()) setText(history[idx]); - else setText(""); - event->accept(); - } else if(event->key() == Qt::Key_Tab) { + if(event->key() == Qt::Key_Tab) { // Tabcomplete - if(cursorPosition() == text().length()) { - - + if(text().length() > 0) { + if (not tabMode) { + QString tabAbbrev = text().left(cursorPosition()).section(' ',-1,-1); + tabCompleteList.clear(); + foreach(QString nick, nickList) { + if(nick.toLower().startsWith(tabAbbrev.toLower())) { + tabCompleteList << nick; + } + } + + tabCompleteList.sort(); + lastCompletionLength = tabAbbrev.length(); + tabMode = true; + nextCompletion = tabCompleteList.begin(); + } + if (nextCompletion != tabCompleteList.end()) { + for (int i = 0; i < lastCompletionLength; i++) { + backspace(); + } + insert(*nextCompletion); + lastCompletionLength = nextCompletion->length(); + nextCompletion++; + } else if (tabCompleteList.end() != tabCompleteList.begin()) { + nextCompletion = tabCompleteList.begin(); + } } event->accept(); + } else { - QLineEdit::keyPressEvent(event); + tabMode = false; + if(event->key() == Qt::Key_Up) { + if(idx > 0) { idx--; setText(history[idx]); } + event->accept(); + } else if(event->key() == Qt::Key_Down) { + if(idx < history.count()) idx++; + if(idx < history.count()) setText(history[idx]); + else setText(""); + event->accept(); + } else { + QLineEdit::keyPressEvent(event); + } } }