Make the style engine fix a little less obscure by copying the string explicitely...
[quassel.git] / src / uisupport / tabcompleter.cpp
index 547bba0..8c29e8a 100644 (file)
@@ -34,6 +34,7 @@ TabCompleter::TabCompleter(InputLine *inputLine_)
     enabled(false),
     nickSuffix(": ")
 {
+  inputLine->installEventFilter(this);
 }
 
 void TabCompleter::buildCompletionList() {
@@ -55,12 +56,15 @@ 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();
@@ -80,7 +84,6 @@ void TabCompleter::ircUserJoinedOrParted(IrcUser *ircUser) {
 }
 
 void TabCompleter::complete() {
-  return; // FIXME
   if(!enabled) {
     buildCompletionList();
     enabled = true;
@@ -116,3 +119,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<QKeyEvent *>(event);
+  
+  if(keyEvent->key() == Qt::Key_Tab) {
+    complete();
+    return true;
+  } else {
+    reset();
+    return false;
+  }
+}
+