X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Finputline.cpp;h=03087fb610540c461a057bbbac7f01e5568f0194;hp=745a3e332ee57d0d30a6627c9f1eb0feacf9aab4;hb=758d3568fe1a9cd08bd6c62c87ac3ac2c48f2f4d;hpb=dc9de5af386f61e6dc5537d04ccc8aceb8126b21 diff --git a/src/uisupport/inputline.cpp b/src/uisupport/inputline.cpp index 745a3e33..03087fb6 100644 --- a/src/uisupport/inputline.cpp +++ b/src/uisupport/inputline.cpp @@ -19,14 +19,31 @@ ***************************************************************************/ #include "bufferview.h" +#include "graphicalui.h" #include "inputline.h" #include "tabcompleter.h" InputLine::InputLine(QWidget *parent) - : QLineEdit(parent), + : +#ifdef HAVE_KDE + KTextEdit(parent), +#else + QLineEdit(parent), +#endif idx(0), tabCompleter(new TabCompleter(this)) { +#ifdef HAVE_KDE +//This is done to make the KTextEdit look like a lineedit + setMaximumHeight(document()->size().toSize().height()); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setAcceptRichText(false); + setLineWrapMode(NoWrap); + enableFindReplace(false); + connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged())); +#endif + connect(this, SIGNAL(returnPressed()), this, SLOT(on_returnPressed())); connect(this, SIGNAL(textChanged(QString)), this, SLOT(on_textChanged(QString))); } @@ -34,6 +51,13 @@ InputLine::InputLine(QWidget *parent) InputLine::~InputLine() { } +void InputLine::setCustomFont(const QFont &font) { + setFont(font); +#ifdef HAVE_KDE + setMaximumHeight(document()->size().toSize().height()); +#endif +} + bool InputLine::eventFilter(QObject *watched, QEvent *event) { if(event->type() != QEvent::KeyPress) return false; @@ -42,7 +66,7 @@ bool InputLine::eventFilter(QObject *watched, QEvent *event) { BufferView *view = qobject_cast(watched); if(view) { QKeyEvent *keyEvent = static_cast(event); - if(keyEvent->text().length() == 1) { // normal key press + if(keyEvent->text().length() == 1 && !(keyEvent->modifiers() & (Qt::ControlModifier ^ Qt::AltModifier)) ) { // normal key press QChar c = keyEvent->text().at(0); if(c.isLetterOrNumber() || c.isSpace() || c.isPunct() || c.isSymbol()) { setFocus(); @@ -56,6 +80,18 @@ bool InputLine::eventFilter(QObject *watched, QEvent *event) { } void InputLine::keyPressEvent(QKeyEvent * event) { + +#ifdef HAVE_KDE + if(event->matches(QKeySequence::Find)) { + QAction *act = GraphicalUi::actionCollection()->action("ToggleSearchBar"); + if(act) { + act->toggle(); + event->accept(); + return; + } + } +#endif + switch(event->key()) { case Qt::Key_Up: event->accept(); @@ -89,9 +125,24 @@ void InputLine::keyPressEvent(QKeyEvent * event) { case Qt::Key_Select: // for Qtopia emit returnPressed(); + break; + +#ifdef HAVE_KDE +//Since this is a ktextedit, we don't have this signal "natively" + case Qt::Key_Return: + case Qt::Key_Enter: + event->accept(); + emit returnPressed(); + break; + +#endif default: +#ifdef HAVE_KDE + KTextEdit::keyPressEvent(event); +#else QLineEdit::keyPressEvent(event); +#endif } } @@ -118,9 +169,11 @@ bool InputLine::addToHistory(const QString &text, bool temporary) { } void InputLine::on_returnPressed() { - addToHistory(text()); - emit sendText(text()); - resetLine(); + if(!text().isEmpty()) { + addToHistory(text()); + emit sendText(text()); + resetLine(); + } } void InputLine::on_textChanged(QString newText) { @@ -140,14 +193,43 @@ void InputLine::on_textChanged(QString newText) { 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); + QStringList lines = newText.split(lineSep); + clear(); + + if(lines.count() >= 4) { + QString msg = tr("Do you really want to paste %n lines?", "", lines.count()); + msg += "

"; + for(int i = 0; i < 3; i++) { + msg += lines[i].left(40); + if(lines[i].count() > 40) + msg += "..."; + msg += "
"; + } + msg += "...

"; + QMessageBox question(QMessageBox::NoIcon, tr("Paste Protection"), msg, QMessageBox::Yes|QMessageBox::No); + question.setDefaultButton(QMessageBox::No); +#ifdef Q_WS_MAC + question.setWindowFlags(question.windowFlags() | Qt::Sheet); +#endif + if(question.exec() == QMessageBox::No) + return; + } + + foreach(QString line, lines) { + if(!line.isEmpty()) { + clear(); + insert(line); + emit returnPressed(); + } } +// if(newText.contains(lineSep)) { +// clear(); +// QString line = newText.section(lineSep, 0, 0); +// QString remainder = newText.section(lineSep, 1); +// insert(line); +// emit returnPressed(); +// insert(remainder); +// } } void InputLine::resetLine() { @@ -159,4 +241,9 @@ void InputLine::resetLine() { void InputLine::showHistoryEntry() { // if the user changed the history, display the changed line tempHistory.contains(idx) ? setText(tempHistory[idx]) : setText(history[idx]); +#ifdef HAVE_KDE + QTextCursor cursor = textCursor(); + cursor.movePosition(QTextCursor::End); + setTextCursor(cursor); +#endif }