X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Ftabcompleter.cpp;h=87a745adc6b138cccc04215850ebefb42b9132d2;hp=fdd2c68c562beed80abefb37f727e74184081569;hb=9f923167f8c8bdadf24f41ab02ae478123f83caa;hpb=2a04cb443a50e37165fc2d5447cc705a813efd3e diff --git a/src/uisupport/tabcompleter.cpp b/src/uisupport/tabcompleter.cpp index fdd2c68c..87a745ad 100644 --- a/src/uisupport/tabcompleter.cpp +++ b/src/uisupport/tabcompleter.cpp @@ -27,6 +27,9 @@ #include "network.h" #include "ircchannel.h" #include "ircuser.h" +#include "uisettings.h" + +#include TabCompleter::TabCompleter(InputLine *inputLine_) : QObject(inputLine_), @@ -34,6 +37,7 @@ TabCompleter::TabCompleter(InputLine *inputLine_) enabled(false), nickSuffix(": ") { + inputLine->installEventFilter(this); } void TabCompleter::buildCompletionList() { @@ -47,7 +51,7 @@ void TabCompleter::buildCompletionList() { NetworkId networkId = currentIndex.data(NetworkModel::NetworkIdRole).value(); QString channelName = currentIndex.sibling(currentIndex.row(), 0).data().toString(); - Network *network = Client::network(networkId); + const Network *network = Client::network(networkId); if(!network) return; @@ -55,21 +59,29 @@ void TabCompleter::buildCompletionList() { if(!channel) return; + // FIXME commented for debugging + /* disconnect(this, SLOT(ircUserJoinedOrParted(IrcUser *))); connect(channel, SIGNAL(ircUserJoined(IrcUser *)), this, SLOT(ircUserJoinedOrParted(IrcUser *))); connect(channel, SIGNAL(ircUserParted(IrcUser *)), this, SLOT(ircUserJoinedOrParted(IrcUser *))); - + */ + completionList.clear(); QString tabAbbrev = inputLine->text().left(inputLine->cursorPosition()).section(' ',-1,-1); completionList.clear(); + QRegExp regex(QString("^[^a-zA-Z]*").append(tabAbbrev), Qt::CaseInsensitive); + QMap sortMap; + foreach(IrcUser *ircUser, channel->ircUsers()) { - if(ircUser->nick().toLower().startsWith(tabAbbrev.toLower())) { - completionList << ircUser->nick(); + if(regex.indexIn(ircUser->nick()) > -1) { + sortMap[ircUser->nick().toLower()] = ircUser->nick(); } } - completionList.sort(); + foreach (QString str, sortMap) + completionList << str; + nextCompletion = completionList.begin(); lastCompletionLength = tabAbbrev.length(); } @@ -80,6 +92,9 @@ void TabCompleter::ircUserJoinedOrParted(IrcUser *ircUser) { } void TabCompleter::complete() { + UiSettings uiSettings; + nickSuffix = uiSettings.value("CompletionSuffix", QString(": ")).toString(); + if(!enabled) { buildCompletionList(); enabled = true; @@ -115,3 +130,18 @@ void TabCompleter::reset() { enabled = false; } +bool TabCompleter::eventFilter(QObject *obj, QEvent *event) { + if(obj != inputLine || event->type() != QEvent::KeyPress) + return QObject::eventFilter(obj, event); + + QKeyEvent *keyEvent = static_cast(event); + + if(keyEvent->key() == Qt::Key_Tab) { + complete(); + return true; + } else { + reset(); + return false; + } +} +