From: Marcus Eggenberger Date: Tue, 8 May 2007 19:47:23 +0000 (+0000) Subject: - moved tabcompleter in seperate file X-Git-Tag: 0.1.0~245 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=a37f958a6db77af048619b4af1553ef47dca295f - moved tabcompleter in seperate file - now the network list will be raised to the top when selected in the menu --- diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index fc375b70..64743f35 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -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) -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 diff --git a/gui/channelwidgetinput.cpp b/gui/channelwidgetinput.cpp index f3276c2a..37ec8f77 100644 --- a/gui/channelwidgetinput.cpp +++ b/gui/channelwidgetinput.cpp @@ -19,47 +19,26 @@ ***************************************************************************/ #include "channelwidgetinput.h" -#include 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(); @@ -89,4 +68,5 @@ void ChannelWidgetInput::enter() { void ChannelWidgetInput::updateNickList(QStringList l) { nickList = l; + emit nickListUpdated(l); } diff --git a/gui/channelwidgetinput.h b/gui/channelwidgetinput.h index e466f1db..a901a95f 100644 --- a/gui/channelwidgetinput.h +++ b/gui/channelwidgetinput.h @@ -23,6 +23,7 @@ #include #include +#include "tabcompleter.h" class ChannelWidgetInput : public QLineEdit { Q_OBJECT @@ -40,15 +41,15 @@ class ChannelWidgetInput : public QLineEdit { 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 diff --git a/gui/mainwin.cpp b/gui/mainwin.cpp index 5beefdf2..75b53e8f 100644 --- a/gui/mainwin.cpp +++ b/gui/mainwin.cpp @@ -211,6 +211,7 @@ void MainWin::showServerList() { // serverListDlg = new ServerListDlg(this); // } serverListDlg->show(); + serverListDlg->raise(); } void MainWin::showSettingsDlg() { diff --git a/gui/tabcompleter.cpp b/gui/tabcompleter.cpp new file mode 100644 index 00000000..c9a7860d --- /dev/null +++ b/gui/tabcompleter.cpp @@ -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 index 00000000..b6d9db3b --- /dev/null +++ b/gui/tabcompleter.h @@ -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 +#include +#include + +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