Commit dc3beae3 authored by Derek Christ's avatar Derek Christ Committed by Méven Car
Browse files

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
parent 0a0d0c48
Pipeline #67060 passed with stage
in 4 minutes and 45 seconds
...@@ -63,7 +63,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, ...@@ -63,7 +63,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
const DolphinView* view = m_mainWindow->activeViewContainer()->view(); const DolphinView* view = m_mainWindow->activeViewContainer()->view();
m_selectedItems = view->selectedItems(); m_selectedItems = view->selectedItems();
installEventFilter(this); QApplication::instance()->installEventFilter(this);
} }
DolphinContextMenu::~DolphinContextMenu() DolphinContextMenu::~DolphinContextMenu()
...@@ -112,28 +112,23 @@ DolphinContextMenu::Command DolphinContextMenu::open() ...@@ -112,28 +112,23 @@ DolphinContextMenu::Command DolphinContextMenu::open()
return m_command; return m_command;
} }
void DolphinContextMenu::childEvent(QChildEvent* event) bool DolphinContextMenu::eventFilter(QObject* object, QEvent* event)
{ {
if(event->added()) { Q_UNUSED(object)
event->child()->installEventFilter(this);
}
QMenu::childEvent(event);
}
bool DolphinContextMenu::eventFilter(QObject* dest, QEvent* event)
{
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); 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); m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
} else { } else {
m_removeAction->update(DolphinRemoveAction::ShiftState::Released); m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
} }
return true;
} }
} }
return QMenu::eventFilter(dest, event);
return false;
} }
void DolphinContextMenu::openTrashContextMenu() void DolphinContextMenu::openTrashContextMenu()
......
...@@ -74,8 +74,7 @@ public: ...@@ -74,8 +74,7 @@ public:
Command open(); Command open();
protected: protected:
void childEvent(QChildEvent* event) override; bool eventFilter(QObject* object, QEvent* event) override;
bool eventFilter(QObject* dest, QEvent* event) override;
private: private:
void openTrashContextMenu(); void openTrashContextMenu();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment