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)
: 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,11 +105,15 @@ 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<QKeyEvent *>(e));
return true;
case QEvent::KeyRelease:
case QEvent::Shortcut:
case QEvent::KeyPress:
return true;
default:
break;

View File

@ -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();