X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fmultilineedit.cpp;h=b856954f9c352a17db1c769f302401920b05d859;hp=14eecf23b0f822c42ae95f3bf26381adb03f870b;hb=2c98de2f80025d91d287299f56b9a22f8e670559;hpb=0d35728dcfe4190f2580931e806372ca800ee5bf diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index 14eecf23..b856954f 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -23,6 +23,7 @@ #include #include +#include "actioncollection.h" #include "bufferview.h" #include "graphicalui.h" #include "multilineedit.h" @@ -31,12 +32,7 @@ const int leftMargin = 3; MultiLineEdit::MultiLineEdit(QWidget *parent) - : -#ifdef HAVE_KDE - KTextEdit(parent), -#else - QTextEdit(parent), -#endif + : MultiLineEditParent(parent), _idx(0), _mode(SingleLine), _singleLine(true), @@ -172,6 +168,10 @@ QSize MultiLineEdit::minimumSizeHint() const { return sizeHint(); } +void MultiLineEdit::setEmacsMode(bool enable) { + _emacsMode = enable; +} + void MultiLineEdit::setSpellCheckEnabled(bool enable) { #ifdef HAVE_KDE setCheckSpellingEnabled(enable); @@ -237,6 +237,22 @@ bool MultiLineEdit::addToHistory(const QString &text, bool temporary) { return false; } +bool MultiLineEdit::event(QEvent *e) { + // We need to make sure that global shortcuts aren't eaten + if(e->type() == QEvent::ShortcutOverride) { + QKeyEvent* event = static_cast(e); + QKeySequence key = QKeySequence(event->key() | event->modifiers()); + foreach(QAction *action, GraphicalUi::actionCollection()->actions()) { + if(action->shortcuts().contains(key)) { + e->ignore(); + return false; + } + } + } + + return MultiLineEditParent::event(e); +} + void MultiLineEdit::keyPressEvent(QKeyEvent *event) { // Workaround the fact that Qt < 4.5 doesn't know InsertLineSeparator yet #if QT_VERSION >= 0x040500 @@ -255,11 +271,7 @@ void MultiLineEdit::keyPressEvent(QKeyEvent *event) { on_returnPressed(); return; } -#ifdef HAVE_KDE - KTextEdit::keyPressEvent(event); -#else - QTextEdit::keyPressEvent(event); -#endif + MultiLineEditParent::keyPressEvent(event); return; } @@ -310,6 +322,58 @@ 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; + } + } + 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; + } + } + } #ifdef HAVE_KDE KTextEdit::keyPressEvent(event);