Don't let the inputline eat application shortcuts
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 1 May 2010 15:35:28 +0000 (17:35 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 1 May 2010 16:01:01 +0000 (18:01 +0200)
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
src/uisupport/multilineedit.h

index 14eecf2..a0e0e8c 100644 (file)
@@ -23,6 +23,7 @@
 #include <QMessageBox>
 #include <QScrollBar>
 
+#include "actioncollection.h"
 #include "bufferview.h"
 #include "graphicalui.h"
 #include "multilineedit.h"
 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<QKeyEvent *>(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;
   }
 
index 04afed3..b3a9d59 100644 (file)
 
 #include <QKeyEvent>
 #include <QHash>
-#include <QTextEdit>
 
 #ifdef HAVE_KDE
 #  include <KDE/KTextEdit>
+#  define MultiLineEditParent KTextEdit
+#else
+#  include <QTextEdit>
+#  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);