From a645d7f4e5ccbfa3a5708521ab6053eb9945595f Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Tue, 17 May 2016 18:45:37 +0100 Subject: [PATCH] ShortcutWidget: override shortcuts in the way they are meant to be (#10075) I would say "by the books" but the documentation was not really clear. Problems with the logic of the previous implementation were exposed in Qt 5.6 by commit . Note that ShortcutOverride events are used elsewhere in the code where they may need to be corrected in the same way. --- src/frontends/qt4/CustomizedWidgets.cpp | 29 ++++++------------------- src/frontends/qt4/CustomizedWidgets.h | 1 - 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/frontends/qt4/CustomizedWidgets.cpp b/src/frontends/qt4/CustomizedWidgets.cpp index b6dc73faf3..59ebad9cc8 100644 --- a/src/frontends/qt4/CustomizedWidgets.cpp +++ b/src/frontends/qt4/CustomizedWidgets.cpp @@ -45,7 +45,6 @@ namespace frontend { ShortcutWidget::ShortcutWidget(QWidget * parent) : QLabel(parent), keysequence_() { - QApplication::instance()->installEventFilter(this); has_cursor_ = false; setFrameShape(QFrame::Panel); setFrameShadow(QFrame::Raised); @@ -62,24 +61,6 @@ void ShortcutWidget::reset() } -bool ShortcutWidget::eventFilter(QObject * obj, QEvent * e) -{ - if (!has_cursor_) - return false; - - switch (e->type()) { - // swallow these if we have focus and they come from elsewhere - case QEvent::Shortcut: - case QEvent::ShortcutOverride: - if (obj != this) - return true; - default: - break; - } - return false; -} - - KeySequence const ShortcutWidget::getKeySequence() const { return keysequence_; @@ -124,13 +105,17 @@ bool ShortcutWidget::event(QEvent * e) setFrameShadow(QFrame::Sunken); break; case QEvent::ShortcutOverride: + // accepting the ShortcutOverride event lets us override shortcuts + // and capture them as keypress events instead + e->accept(); + return true; + case QEvent::KeyPress: keyPressEvent(static_cast(e)); return true; case QEvent::KeyRelease: case QEvent::Shortcut: - case QEvent::KeyPress: return true; - default: + default: break; } return QLabel::event(e); @@ -141,7 +126,7 @@ void ShortcutWidget::appendToSequence(QKeyEvent * e) { KeySymbol sym; setKeySymbol(&sym, e); - + if (sym.isOK()) { KeyModifier mod = lyx::q_key_state(e->modifiers()); keysequence_.addkey(sym, mod, lyx::NoModifier); diff --git a/src/frontends/qt4/CustomizedWidgets.h b/src/frontends/qt4/CustomizedWidgets.h index 6104d30d8b..3409679556 100644 --- a/src/frontends/qt4/CustomizedWidgets.h +++ b/src/frontends/qt4/CustomizedWidgets.h @@ -31,7 +31,6 @@ class ShortcutWidget : public QLabel { public: ShortcutWidget(QWidget * parent); void reset(); - bool eventFilter(QObject*, QEvent* e ); KeySequence const getKeySequence() const; void setKeySequence(lyx::KeySequence const & s); void removeFromSequence();