diff options
| author | Derek Christ <[email protected]> | 2021-06-18 15:12:54 +0200 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2021-06-22 08:53:55 +0000 |
| commit | dc3beae3ab2c55cd3501e17f93b51e93e876a177 (patch) | |
| tree | 0d1f9b1a1f536046734f69124940d6c68802a8fd | |
| parent | 0a0d0c48ee228e5117a85ee6ebdf8af93aa54d60 (diff) | |
Fix shift-action modifier in context menu
Before this patch, the shift-action modifier in context menus did not
work when a sub-context menu is open, that does not have the main
context menu as its parent.
The new fix installs an event filter on QApplication whenever a new
context menu is opened to make the context menu aware of shift-presses
even when a sub-context menu is in focus.
BUG: 425997
FIXED-IN: 21.04
| -rw-r--r-- | src/dolphincontextmenu.cpp | 21 | ||||
| -rw-r--r-- | src/dolphincontextmenu.h | 3 |
2 files changed, 9 insertions, 15 deletions
diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index eb3f641e5..2b216ce03 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -63,7 +63,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const DolphinView* view = m_mainWindow->activeViewContainer()->view(); m_selectedItems = view->selectedItems(); - installEventFilter(this); + QApplication::instance()->installEventFilter(this); } DolphinContextMenu::~DolphinContextMenu() @@ -112,28 +112,23 @@ DolphinContextMenu::Command DolphinContextMenu::open() return m_command; } -void DolphinContextMenu::childEvent(QChildEvent* event) +bool DolphinContextMenu::eventFilter(QObject* object, QEvent* event) { - if(event->added()) { - event->child()->installEventFilter(this); - } - QMenu::childEvent(event); -} + Q_UNUSED(object) -bool DolphinContextMenu::eventFilter(QObject* dest, QEvent* event) -{ if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); - if(m_removeAction && keyEvent->key() == Qt::Key_Shift) { - if(event->type() == QEvent::KeyPress) { + + if (m_removeAction && keyEvent->key() == Qt::Key_Shift) { + if (event->type() == QEvent::KeyPress) { m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed); } else { m_removeAction->update(DolphinRemoveAction::ShiftState::Released); } - return true; } } - return QMenu::eventFilter(dest, event); + + return false; } void DolphinContextMenu::openTrashContextMenu() diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h index 7f0b6988a..afd8b8c4d 100644 --- a/src/dolphincontextmenu.h +++ b/src/dolphincontextmenu.h @@ -74,8 +74,7 @@ public: Command open(); protected: - void childEvent(QChildEvent* event) override; - bool eventFilter(QObject* dest, QEvent* event) override; + bool eventFilter(QObject* object, QEvent* event) override; private: void openTrashContextMenu(); |
