X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fmultilineedit.cpp;h=4c5759f552680752f848e92c55e3d99c2b6c42d3;hp=a0e0e8cc06644c089f97e2ccd7243b61ac1ebbf5;hb=9f33f6e471dedbefe7bbe336a40312894628afe1;hpb=9dc0131dab77e3d3173906f1f8b14d3447523aea diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index a0e0e8cc..4c5759f5 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -40,6 +40,7 @@ MultiLineEdit::MultiLineEdit(QWidget *parent) _maxHeight(5), _scrollBarsEnabled(true), _pasteProtectionEnabled(true), + _emacsMode(false), _lastDocumentHeight(-1) { #if QT_VERSION >= 0x040500 @@ -168,6 +169,10 @@ QSize MultiLineEdit::minimumSizeHint() const { return sizeHint(); } +void MultiLineEdit::setEmacsMode(bool enable) { + _emacsMode = enable; +} + void MultiLineEdit::setSpellCheckEnabled(bool enable) { #ifdef HAVE_KDE setCheckSpellingEnabled(enable); @@ -318,6 +323,107 @@ void MultiLineEdit::keyPressEvent(QKeyEvent *event) { ; } + if(_emacsMode) { + if(event->modifiers() & Qt::ControlModifier) { + switch(event->key()) { + // move + case Qt::Key_A: + moveCursor(QTextCursor::StartOfLine); + return; + case Qt::Key_E: + moveCursor(QTextCursor::EndOfLine); + return; + case Qt::Key_F: + moveCursor(QTextCursor::Right); + return; + case Qt::Key_B: + moveCursor(QTextCursor::Left); + return; + + // modify + case Qt::Key_Y: + paste(); + return; + case Qt::Key_K: + moveCursor(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); + cut(); + return; + + default: + break; + } + } + else if(event->modifiers() & Qt::MetaModifier || + event->modifiers() & Qt::AltModifier) + { + switch(event->key()) { + case Qt::Key_Right: + moveCursor(QTextCursor::WordRight); + return; + case Qt::Key_Left: + moveCursor(QTextCursor::WordLeft); + return; + case Qt::Key_F: + moveCursor(QTextCursor::WordRight); + return; + case Qt::Key_B: + moveCursor(QTextCursor::WordLeft); + return; + case Qt::Key_Less: + moveCursor(QTextCursor::Start); + return; + case Qt::Key_Greater: + moveCursor(QTextCursor::End); + return; + + // modify + case Qt::Key_D: + moveCursor(QTextCursor::WordRight, QTextCursor::KeepAnchor); + cut(); + return; + + case Qt::Key_U: // uppercase word + moveCursor(QTextCursor::WordRight, QTextCursor::KeepAnchor); + textCursor().insertText(textCursor().selectedText().toUpper()); + return; + + case Qt::Key_L: // lowercase word + moveCursor(QTextCursor::WordRight, QTextCursor::KeepAnchor); + textCursor().insertText(textCursor().selectedText().toLower()); + return; + + case Qt::Key_C: { // capitalize word + moveCursor(QTextCursor::WordRight, QTextCursor::KeepAnchor); + QString const text = textCursor().selectedText(); + textCursor().insertText(text.left(1).toUpper() + text.mid(1).toLower()); + return; + } + + case Qt::Key_T: { // transpose words + moveCursor(QTextCursor::StartOfWord); + moveCursor(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + QString const word1 = textCursor().selectedText(); + textCursor().clearSelection(); + moveCursor(QTextCursor::WordRight); + moveCursor(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + QString const word2 = textCursor().selectedText(); + if(!word2.isEmpty() && !word1.isEmpty()) { + textCursor().insertText(word1); + moveCursor(QTextCursor::WordLeft); + moveCursor(QTextCursor::WordLeft); + moveCursor(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + textCursor().insertText(word2); + moveCursor(QTextCursor::WordRight); + moveCursor(QTextCursor::EndOfWord); + } + return; + } + + default: + break; + } + } + } #ifdef HAVE_KDE KTextEdit::keyPressEvent(event); @@ -552,7 +658,7 @@ void MultiLineEdit::on_textChanged() { clear(); if(lines.count() >= 4) { - QString msg = tr("Do you really want to paste %n lines?", "", lines.count()); + QString msg = tr("Do you really want to paste %n line(s)?", "", lines.count()); msg += "

"; for(int i = 0; i < 4; i++) { msg += Qt::escape(lines[i].left(40));