- moved tabcompleter in seperate file
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 8 May 2007 19:47:23 +0000 (19:47 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 8 May 2007 19:47:23 +0000 (19:47 +0000)
- now the network list will be raised to the top when selected in the menu

gui/CMakeLists.txt
gui/channelwidgetinput.cpp
gui/channelwidgetinput.h
gui/mainwin.cpp
gui/tabcompleter.cpp [new file with mode: 0644]
gui/tabcompleter.h [new file with mode: 0644]

index fc375b7..64743f3 100644 (file)
@@ -1,7 +1,7 @@
-SET(gui_SRCS chatwidget.cpp channelwidgetinput.cpp mainwin.cpp serverlist.cpp buffer.cpp bufferwidget.cpp
+SET(gui_SRCS chatwidget.cpp channelwidgetinput.cpp tabcompleter.cpp mainwin.cpp serverlist.cpp buffer.cpp bufferwidget.cpp
              identities.cpp coreconnectdlg.cpp guiproxy.cpp networkview.cpp style.cpp settingsdlg.cpp settingspages.cpp)
 SET(gui_HDRS style.h)
              identities.cpp coreconnectdlg.cpp guiproxy.cpp networkview.cpp style.cpp settingsdlg.cpp settingspages.cpp)
 SET(gui_HDRS style.h)
-SET(gui_MOCS chatwidget.h channelwidgetinput.h mainwin.h serverlist.h identities.h coreconnectdlg.h
+SET(gui_MOCS chatwidget.h channelwidgetinput.h tabcompleter.h mainwin.h serverlist.h identities.h coreconnectdlg.h
              guiproxy.h networkview.h buffer.h bufferwidget.h settingsdlg.h settingspages.h)
 SET(gui_UICS identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui mainwin.ui
              nickeditdlg.ui serverlistdlg.ui servereditdlg.ui coreconnectdlg.ui ircwidget.ui
              guiproxy.h networkview.h buffer.h bufferwidget.h settingsdlg.h settingspages.h)
 SET(gui_UICS identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui mainwin.ui
              nickeditdlg.ui serverlistdlg.ui servereditdlg.ui coreconnectdlg.ui ircwidget.ui
index f3276c2..37ec8f7 100644 (file)
  ***************************************************************************/
 
 #include "channelwidgetinput.h"
  ***************************************************************************/
 
 #include "channelwidgetinput.h"
-#include <QCompleter>
 
 ChannelWidgetInput::ChannelWidgetInput(QWidget *parent) : QLineEdit(parent) {
   idx = 0;
 
 ChannelWidgetInput::ChannelWidgetInput(QWidget *parent) : QLineEdit(parent) {
   idx = 0;
-  tabMode = false;
+  //tabMode = false;
   connect(this, SIGNAL(returnPressed()), this, SLOT(enter()));
   connect(this, SIGNAL(returnPressed()), this, SLOT(enter()));
+  TabCompleter *tc = new TabCompleter(this);
+  tabComplete = tc;
+  connect(this, SIGNAL(nickListUpdated(QStringList)), tabComplete, SLOT(updateNickList(QStringList)));
 }
 
 void ChannelWidgetInput::keyPressEvent(QKeyEvent * event) {
   if(event->key() == Qt::Key_Tab) {
     // Tabcomplete
     if(text().length() > 0) {
 }
 
 void ChannelWidgetInput::keyPressEvent(QKeyEvent * event) {
   if(event->key() == Qt::Key_Tab) {
     // Tabcomplete
     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();
-      }
+      tabComplete->complete();
     }
     event->accept();
     
   } else {
     }
     event->accept();
     
   } else {
-    tabMode = false;
+    tabComplete->disable();
     if(event->key() == Qt::Key_Up) {
       if(idx > 0) { idx--; setText(history[idx]); }
       event->accept();
     if(event->key() == Qt::Key_Up) {
       if(idx > 0) { idx--; setText(history[idx]); }
       event->accept();
@@ -89,4 +68,5 @@ void ChannelWidgetInput::enter() {
 
 void ChannelWidgetInput::updateNickList(QStringList l) {
   nickList = l;
 
 void ChannelWidgetInput::updateNickList(QStringList l) {
   nickList = l;
+  emit nickListUpdated(l);
 }
 }
index e466f1d..a901a95 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <QtCore>
 #include <QtGui>
 
 #include <QtCore>
 #include <QtGui>
+#include "tabcompleter.h"
 
 class ChannelWidgetInput : public QLineEdit {
   Q_OBJECT
 
 class ChannelWidgetInput : public QLineEdit {
   Q_OBJECT
@@ -40,15 +41,15 @@ class ChannelWidgetInput : public QLineEdit {
   public slots:
     void updateNickList(QStringList);
     
   public slots:
     void updateNickList(QStringList);
     
+  signals:
+    void nickListUpdated(QStringList);
+    
   private:
     qint32 idx;
     QStringList history;
     QStringList nickList;
   private:
     qint32 idx;
     QStringList history;
     QStringList nickList;
-    
-    bool tabMode;
-    int lastCompletionLength;
-    QStringList tabCompleteList;
-    QStringList::Iterator nextCompletion;
+
+    TabCompleter *tabComplete;
 };
 
 #endif
 };
 
 #endif
index 5beefdf..75b53e8 100644 (file)
@@ -211,6 +211,7 @@ void MainWin::showServerList() {
 //    serverListDlg = new ServerListDlg(this);
 //  }
   serverListDlg->show();
 //    serverListDlg = new ServerListDlg(this);
 //  }
   serverListDlg->show();
+  serverListDlg->raise();
 }
 
 void MainWin::showSettingsDlg() {
 }
 
 void MainWin::showSettingsDlg() {
diff --git a/gui/tabcompleter.cpp b/gui/tabcompleter.cpp
new file mode 100644 (file)
index 0000000..c9a7860
--- /dev/null
@@ -0,0 +1,73 @@
+/***************************************************************************
+ *   Copyright (C) 2005/06 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "tabcompleter.h"
+
+TabCompleter::TabCompleter(QLineEdit *l, QObject *parent) : QObject(parent) {
+  lineEdit = l;
+  enabled = false;
+}
+
+void TabCompleter::updateNickList(QStringList l) {
+  nickList = l;
+}
+
+void TabCompleter::updateChannelList(QStringList l) {
+
+}
+
+void TabCompleter::buildCompletionList() {
+  // this is the first time tab is pressed -> build up the completion list and it's iterator
+  QString tabAbbrev = lineEdit->text().left(lineEdit->cursorPosition()).section(' ',-1,-1);
+  completionList.clear();
+  foreach(QString nick, nickList) {
+    if(nick.toLower().startsWith(tabAbbrev.toLower())) {
+      completionList << nick;
+    }
+  }
+  completionList.sort();
+  nextCompletion = completionList.begin();
+  lastCompletionLength = tabAbbrev.length();
+}
+
+void TabCompleter::complete() {
+  if (not enabled) {
+    buildCompletionList();
+    enabled = true;  
+  }
+  
+  if (nextCompletion != completionList.end()) {
+    // clear previous completion
+    for (int i = 0; i < lastCompletionLength; i++) {
+      lineEdit->backspace();
+    }
+    lineEdit->insert(*nextCompletion + ' ');
+    lastCompletionLength = nextCompletion->length() + 1;
+    nextCompletion++;
+  } else if (completionList.begin() != completionList.end()) {
+    nextCompletion = completionList.begin();
+  }
+  
+}
+
+void TabCompleter::disable() {
+  enabled = false;
+}
+
diff --git a/gui/tabcompleter.h b/gui/tabcompleter.h
new file mode 100644 (file)
index 0000000..b6d9db3
--- /dev/null
@@ -0,0 +1,56 @@
+/***************************************************************************
+ *   Copyright (C) 2005/06 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef _TABCOMPLETER_H_
+#define _TABCOMPLETER_H_
+
+#include <QtCore>
+#include <QObject>
+#include <QLineEdit>
+
+class TabCompleter : public QObject {
+  Q_OBJECT
+  
+  public:
+    TabCompleter(QLineEdit *l, QObject *parent = 0);
+    void disable();
+    void complete();
+  
+  public slots:
+    void updateNickList(QStringList);
+    void updateChannelList(QStringList);
+    
+  private:
+    QLineEdit *lineEdit;
+    QStringList completionTemplates;
+    QStringList nickList;
+    QStringList channelList;
+    int lastCompletionLength;
+    bool enabled;
+      
+
+    QStringList completionList;
+    QStringList::Iterator nextCompletion;
+    
+    void buildCompletionList();
+    
+};
+
+#endif