From b10bb4b6768536f34fd5e7b00cb8755279af135d Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Thu, 17 May 2007 16:44:32 +0000 Subject: [PATCH] - small tweak to tabcompletion - doubleclick on channel now joins the channel --- core/server.cpp | 1 - gui/channelwidgetinput.cpp | 8 ++------ gui/networkview.cpp | 12 ++++++++++++ gui/networkview.h | 7 +++++-- gui/tabcompleter.cpp | 21 +++++++++++++++++---- gui/tabcompleter.h | 10 +++++----- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/core/server.cpp b/core/server.cpp index 442fe0fe..df7b576b 100644 --- a/core/server.cpp +++ b/core/server.cpp @@ -726,7 +726,6 @@ void Server::handleServer432(QString prefix, QStringList params) { /* ERR_NICKNAMEINUSE */ void Server::handleServer433(QString prefix, QStringList params) { - qDebug() << "433:" << params; QString errnick = params[0]; emit displayMsg(Message::Error, "", tr("Nick %1 is already taken").arg(errnick)); // if there is a problem while connecting to the server -> we handle it diff --git a/gui/channelwidgetinput.cpp b/gui/channelwidgetinput.cpp index 813d1c8c..c4d1a06f 100644 --- a/gui/channelwidgetinput.cpp +++ b/gui/channelwidgetinput.cpp @@ -32,13 +32,9 @@ ChannelWidgetInput::~ChannelWidgetInput() { } void ChannelWidgetInput::keyPressEvent(QKeyEvent * event) { - if(event->key() == Qt::Key_Tab) { - // Tabcomplete - if(text().length() > 0) { - tabComplete->complete(); - } + if(event->key() == Qt::Key_Tab) { // Tabcomplete + tabComplete->complete(); event->accept(); - } else { tabComplete->disable(); if(event->key() == Qt::Key_Up) { diff --git a/gui/networkview.cpp b/gui/networkview.cpp index c97e2880..e9f1bd6e 100644 --- a/gui/networkview.cpp +++ b/gui/networkview.cpp @@ -46,6 +46,9 @@ NetworkView::NetworkView(QString n, int m, QStringList nets, QWidget *parent) : tree->header()->hide(); tree->setSortingEnabled(true); connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(itemClicked(QTreeWidgetItem*))); + connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); + connect(this, SIGNAL(fakeUserInput(BufferId, QString)), guiProxy, SLOT(gsUserInput(BufferId, QString))); + } void NetworkView::setBuffers(QList buffers) { @@ -127,6 +130,15 @@ void NetworkView::itemClicked(QTreeWidgetItem *item) { } } +void NetworkView::itemDoubleClicked(QTreeWidgetItem *item) { + Buffer *b = bufitems.key(item); + if(b) { + if(Buffer::ChannelBuffer == b->bufferType()) { + emit fakeUserInput(b->bufferId(), QString("/join " + b->bufferName())); + } + } +} + void NetworkView::selectBuffer(Buffer *b) { QTreeWidgetItem *item = 0; if(bufitems.contains(b)) item = bufitems[b]; diff --git a/gui/networkview.h b/gui/networkview.h index 2ed94b66..f6842b68 100644 --- a/gui/networkview.h +++ b/gui/networkview.h @@ -23,6 +23,7 @@ #include #include "ui_networkview.h" +#include "guiproxy.h" #include "buffer.h" typedef QHash > BufferHash; @@ -71,10 +72,12 @@ class NetworkView : public QDockWidget { signals: void bufferSelected(Buffer *); - + void fakeUserInput(BufferId, QString); + private slots: void itemClicked(QTreeWidgetItem *item); - + void itemDoubleClicked(QTreeWidgetItem *item); + private: int mode; QString name; diff --git a/gui/tabcompleter.cpp b/gui/tabcompleter.cpp index c9a7860d..5b3e97f1 100644 --- a/gui/tabcompleter.cpp +++ b/gui/tabcompleter.cpp @@ -23,6 +23,7 @@ TabCompleter::TabCompleter(QLineEdit *l, QObject *parent) : QObject(parent) { lineEdit = l; enabled = false; + startOfLineSuffix = QString(": "); // TODO make start of line suffix configurable } void TabCompleter::updateNickList(QStringList l) { @@ -30,7 +31,7 @@ void TabCompleter::updateNickList(QStringList l) { } void TabCompleter::updateChannelList(QStringList l) { - + channelList = l; } void TabCompleter::buildCompletionList() { @@ -58,10 +59,22 @@ void TabCompleter::complete() { for (int i = 0; i < lastCompletionLength; i++) { lineEdit->backspace(); } - lineEdit->insert(*nextCompletion + ' '); - lastCompletionLength = nextCompletion->length() + 1; + + // insert completion + lineEdit->insert(*nextCompletion); + + // remember charcount to delete next time and advance to next completion + lastCompletionLength = nextCompletion->length(); nextCompletion++; - } else if (completionList.begin() != completionList.end()) { + + // we're completing the first word of the line + if(lineEdit->text().length() == lastCompletionLength) { + lineEdit->insert(startOfLineSuffix); + lastCompletionLength += 2; + } + + // we're at the end of the list -> start over again + } else { nextCompletion = completionList.begin(); } diff --git a/gui/tabcompleter.h b/gui/tabcompleter.h index b6d9db3b..c8a75f74 100644 --- a/gui/tabcompleter.h +++ b/gui/tabcompleter.h @@ -38,17 +38,17 @@ class TabCompleter : public QObject { void updateChannelList(QStringList); private: + bool enabled; + QString startOfLineSuffix; QLineEdit *lineEdit; QStringList completionTemplates; - QStringList nickList; QStringList channelList; - int lastCompletionLength; - bool enabled; - + QStringList nickList; QStringList completionList; QStringList::Iterator nextCompletion; - + int lastCompletionLength; + void buildCompletionList(); }; -- 2.20.1