-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)
-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
***************************************************************************/
#include "channelwidgetinput.h"
-#include <QCompleter>
ChannelWidgetInput::ChannelWidgetInput(QWidget *parent) : QLineEdit(parent) {
idx = 0;
- tabMode = false;
+ //tabMode = false;
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) {
- 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 {
- tabMode = false;
+ tabComplete->disable();
if(event->key() == Qt::Key_Up) {
if(idx > 0) { idx--; setText(history[idx]); }
event->accept();
void ChannelWidgetInput::updateNickList(QStringList l) {
nickList = l;
+ emit nickListUpdated(l);
}
#include <QtCore>
#include <QtGui>
+#include "tabcompleter.h"
class ChannelWidgetInput : public QLineEdit {
Q_OBJECT
public slots:
void updateNickList(QStringList);
+ signals:
+ void nickListUpdated(QStringList);
+
private:
qint32 idx;
QStringList history;
QStringList nickList;
-
- bool tabMode;
- int lastCompletionLength;
- QStringList tabCompleteList;
- QStringList::Iterator nextCompletion;
+
+ TabCompleter *tabComplete;
};
#endif
// serverListDlg = new ServerListDlg(this);
// }
serverListDlg->show();
+ serverListDlg->raise();
}
void MainWin::showSettingsDlg() {
--- /dev/null
+/***************************************************************************
+ * 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;
+}
+
--- /dev/null
+/***************************************************************************
+ * 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