From: Marcus Eggenberger Date: Tue, 8 May 2007 10:29:52 +0000 (+0000) Subject: added first and simple version of Tabcompletion (Nicks only atm) X-Git-Tag: 0.1.0~246 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=9cbaab34158d0f2e77c18d6ac055582102812553 added first and simple version of Tabcompletion (Nicks only atm) --- diff --git a/gui/bufferwidget.cpp b/gui/bufferwidget.cpp index 98f8dd83..8185cbcf 100644 --- a/gui/bufferwidget.cpp +++ b/gui/bufferwidget.cpp @@ -36,6 +36,7 @@ BufferWidget::BufferWidget(QWidget *parent) : QWidget(parent) { //setBaseSize(QSize(600,400)); //setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed())); + connect(this, SIGNAL(nickListUpdated(QStringList)), ui.inputEdit, SLOT(updateNickList(QStringList))); } @@ -215,6 +216,7 @@ void BufferWidget::updateNickList(VarMap nicks) { // TODO Use 005 void BufferWidget::updateNickList(BufferState *state, VarMap nicks) { + emit nickListUpdated(nicks.keys()); QTreeWidget *tree = state->nickTree; if(!tree) return; tree->clear(); diff --git a/gui/bufferwidget.h b/gui/bufferwidget.h index e72ebb8a..94ff0bc3 100644 --- a/gui/bufferwidget.h +++ b/gui/bufferwidget.h @@ -50,9 +50,10 @@ class BufferWidget : public QWidget { signals: void userInput(QString msg); void aboutToClose(); - + void layoutMessages(LayoutTask); - + void nickListUpdated(QStringList l); + protected: public slots: diff --git a/gui/channelwidgetinput.cpp b/gui/channelwidgetinput.cpp index 893623d2..f3276c2a 100644 --- a/gui/channelwidgetinput.cpp +++ b/gui/channelwidgetinput.cpp @@ -19,30 +19,58 @@ ***************************************************************************/ #include "channelwidgetinput.h" +#include ChannelWidgetInput::ChannelWidgetInput(QWidget *parent) : QLineEdit(parent) { idx = 0; + tabMode = false; connect(this, SIGNAL(returnPressed()), this, SLOT(enter())); } void ChannelWidgetInput::keyPressEvent(QKeyEvent * event) { - if(event->key() == Qt::Key_Up) { - if(idx > 0) { idx--; setText(history[idx]); } - event->accept(); - } else if(event->key() == Qt::Key_Down) { - if(idx < history.count()) idx++; - if(idx < history.count()) setText(history[idx]); - else setText(""); - event->accept(); - } else if(event->key() == Qt::Key_Tab) { + if(event->key() == Qt::Key_Tab) { // Tabcomplete - if(cursorPosition() == text().length()) { - - + 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(); + } } event->accept(); + } else { - QLineEdit::keyPressEvent(event); + tabMode = false; + if(event->key() == Qt::Key_Up) { + if(idx > 0) { idx--; setText(history[idx]); } + event->accept(); + } else if(event->key() == Qt::Key_Down) { + if(idx < history.count()) idx++; + if(idx < history.count()) setText(history[idx]); + else setText(""); + event->accept(); + } else { + QLineEdit::keyPressEvent(event); + } } } diff --git a/gui/channelwidgetinput.h b/gui/channelwidgetinput.h index 4d848e64..e466f1db 100644 --- a/gui/channelwidgetinput.h +++ b/gui/channelwidgetinput.h @@ -30,9 +30,6 @@ class ChannelWidgetInput : public QLineEdit { public: ChannelWidgetInput(QWidget *parent = 0); - public slots: - void updateNickList(QStringList); - protected: virtual bool event(QEvent *); virtual void keyPressEvent(QKeyEvent * event); @@ -40,11 +37,18 @@ class ChannelWidgetInput : public QLineEdit { private slots: void enter(); + public slots: + void updateNickList(QStringList); + private: qint32 idx; QStringList history; QStringList nickList; - + + bool tabMode; + int lastCompletionLength; + QStringList tabCompleteList; + QStringList::Iterator nextCompletion; }; #endif diff --git a/gui/chatwidget.cpp b/gui/chatwidget.cpp index 331fdb0b..a3ab3add 100644 --- a/gui/chatwidget.cpp +++ b/gui/chatwidget.cpp @@ -915,12 +915,14 @@ void LayoutThread::run() { Q_ASSERT(queue.count()); //qDebug() << "process"; LayoutTask task = queue.takeFirst(); mutex.unlock(); + /* foreach(Message msg, task.messages) { //qDebug() << msg.text; ChatLine *line = new ChatLine(msg, task.net, task.buf); task.lines.append(line); } emit taskProcessed(task); + */ //msleep(500); } }