X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Finputline.cpp;h=c297694ce8acc42743e4082cec1cd0d259f34c92;hp=05f97554cc6b7fff43191b3c4810b6cab4f7cbf0;hb=c030e0d5e910fe8af376e5462c9e58d45fd59e40;hpb=18803d933df24b9bda564ad730ca30b32e0e9d62 diff --git a/src/uisupport/inputline.cpp b/src/uisupport/inputline.cpp index 05f97554..c297694c 100644 --- a/src/uisupport/inputline.cpp +++ b/src/uisupport/inputline.cpp @@ -24,11 +24,10 @@ InputLine::InputLine(QWidget *parent) : QLineEdit(parent), - idx(0) + idx(0), + tabCompleter(new TabCompleter(this)) { - connect(this, SIGNAL(returnPressed()), this, SLOT(enter())); - tabComplete = new TabCompleter(this); - + #ifdef Q_WS_MAC bindModifier = Qt::ControlModifier | Qt::AltModifier; jumpModifier = Qt::ControlModifier; @@ -36,6 +35,10 @@ InputLine::InputLine(QWidget *parent) bindModifier = Qt::ControlModifier; jumpModifier = Qt::AltModifier; #endif + + connect(this, SIGNAL(returnPressed()), this, SLOT(on_returnPressed())); + connect(this, SIGNAL(textChanged(QString)), this, SLOT(on_textChanged(QString))); + } InputLine::~InputLine() { @@ -48,42 +51,55 @@ void InputLine::keyPressEvent(QKeyEvent * event) { return; } - if(event->key() == Qt::Key_Tab) { // Tabcomplete - tabComplete->complete(); + 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_Select) { // for Qtopia + emit returnPressed(); + QLineEdit::keyPressEvent(event); } else { - tabComplete->reset(); - 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_Select) { // for Qtopia - emit returnPressed(); - QLineEdit::keyPressEvent(event); - } else { - QLineEdit::keyPressEvent(event); - } + QLineEdit::keyPressEvent(event); } -} -bool InputLine::event(QEvent *e) { - if(e->type() == QEvent::KeyPress) { - keyPressEvent(static_cast(e)); - return true; - } - return QLineEdit::event(e); } -void InputLine::enter() { +void InputLine::on_returnPressed() { history << text(); idx = history.count(); + emit sendText(text()); + clear(); } -void InputLine::updateNickList(QStringList l) { - nickList = l; - emit nickListUpdated(l); +void InputLine::on_textChanged(QString newText) { + QStringList lineSeperators; + lineSeperators << QString("\r\n") + << QString('\n') + << QString('\r'); + + QString lineSep; + foreach(QString seperator, lineSeperators) { + if(newText.contains(seperator)) { + lineSep = seperator; + break; + } + } + + if(lineSep.isEmpty()) + return; + + if(newText.contains(lineSep)) { + clear(); + QString line = newText.section(lineSep, 0, 0); + QString remainder = newText.section(lineSep, 1); + insert(line); + emit returnPressed(); + insert(remainder); + } + } +