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 <https://codereview.qt-project.org/125142>.

<http://mid.gmane.org/20160510070413.wzjpk4w4turnx6pr@cotopaxi>

Note that ShortcutOverride events are used elsewhere in the code where they may
need to be corrected in the same way.
This commit is contained in:
Guillaume Munch 2016-05-17 18:45:37 +01:00
parent 0f3dbc472f
commit a645d7f4e5
2 changed files with 7 additions and 23 deletions

View File

@ -45,7 +45,6 @@ namespace frontend {
ShortcutWidget::ShortcutWidget(QWidget * parent) ShortcutWidget::ShortcutWidget(QWidget * parent)
: QLabel(parent), keysequence_() : QLabel(parent), keysequence_()
{ {
QApplication::instance()->installEventFilter(this);
has_cursor_ = false; has_cursor_ = false;
setFrameShape(QFrame::Panel); setFrameShape(QFrame::Panel);
setFrameShadow(QFrame::Raised); 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 KeySequence const ShortcutWidget::getKeySequence() const
{ {
return keysequence_; return keysequence_;
@ -124,13 +105,17 @@ bool ShortcutWidget::event(QEvent * e)
setFrameShadow(QFrame::Sunken); setFrameShadow(QFrame::Sunken);
break; break;
case QEvent::ShortcutOverride: 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<QKeyEvent *>(e)); keyPressEvent(static_cast<QKeyEvent *>(e));
return true; return true;
case QEvent::KeyRelease: case QEvent::KeyRelease:
case QEvent::Shortcut: case QEvent::Shortcut:
case QEvent::KeyPress:
return true; return true;
default: default:
break; break;
} }
return QLabel::event(e); return QLabel::event(e);
@ -141,7 +126,7 @@ void ShortcutWidget::appendToSequence(QKeyEvent * e)
{ {
KeySymbol sym; KeySymbol sym;
setKeySymbol(&sym, e); setKeySymbol(&sym, e);
if (sym.isOK()) { if (sym.isOK()) {
KeyModifier mod = lyx::q_key_state(e->modifiers()); KeyModifier mod = lyx::q_key_state(e->modifiers());
keysequence_.addkey(sym, mod, lyx::NoModifier); keysequence_.addkey(sym, mod, lyx::NoModifier);

View File

@ -31,7 +31,6 @@ class ShortcutWidget : public QLabel {
public: public:
ShortcutWidget(QWidget * parent); ShortcutWidget(QWidget * parent);
void reset(); void reset();
bool eventFilter(QObject*, QEvent* e );
KeySequence const getKeySequence() const; KeySequence const getKeySequence() const;
void setKeySequence(lyx::KeySequence const & s); void setKeySequence(lyx::KeySequence const & s);
void removeFromSequence(); void removeFromSequence();