From 9dc0131dab77e3d3173906f1f8b14d3447523aea Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sat, 1 May 2010 17:35:28 +0200 Subject: [PATCH] Don't let the inputline eat application shortcuts We'd like to use Ctrl+R and possibly others for actions, but KTextEdit eats it (without using it, in fact). So now we check the application shortcuts and prevent them from being used by KTextEdit if we have them defined. --- src/uisupport/multilineedit.cpp | 30 +++++++++++++++++++----------- src/uisupport/multilineedit.h | 14 ++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index 14eecf23..a0e0e8cc 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), @@ -237,6 +233,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 +267,7 @@ void MultiLineEdit::keyPressEvent(QKeyEvent *event) { on_returnPressed(); return; } -#ifdef HAVE_KDE - KTextEdit::keyPressEvent(event); -#else - QTextEdit::keyPressEvent(event); -#endif + MultiLineEditParent::keyPressEvent(event); return; } diff --git a/src/uisupport/multilineedit.h b/src/uisupport/multilineedit.h index 04afed31..b3a9d593 100644 --- a/src/uisupport/multilineedit.h +++ b/src/uisupport/multilineedit.h @@ -23,22 +23,19 @@ #include #include -#include #ifdef HAVE_KDE # include +# define MultiLineEditParent KTextEdit +#else +# include +# define MultiLineEditParent QTextEdit #endif class QKeyEvent; class TabCompleter; -class MultiLineEdit : public -#ifdef HAVE_KDE - KTextEdit -#else - QTextEdit -#endif -{ +class MultiLineEdit : public MultiLineEditParent { Q_OBJECT public: @@ -94,6 +91,7 @@ signals: void noTextEntered(); protected: + virtual bool event(QEvent *e); virtual void keyPressEvent(QKeyEvent * event); virtual void resizeEvent(QResizeEvent *event); -- 2.20.1