┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Christ <[email protected]>2020-10-15 23:11:17 +0200
committerElvis Angelaccio <[email protected]>2020-11-23 22:07:31 +0000
commit9e4642d435085f27134ed6c8431734dcacf65834 (patch)
treee3b1cd42199c70935a405dc614e6fc8833aac454
parentc3b238bbe924f5c58496407ceb9f90c88c0738fa (diff)
Fix delete action switching via 'Shift' when sub-context-menu is open
Switching the 'Move to Trash' action to 'Delete' using the shift key does not work when the mouse hovers a submenu. This fix resolves the issue by using an event filter instead of the key event functions. BUG: 425997
-rw-r--r--src/dolphincontextmenu.cpp27
-rw-r--r--src/dolphincontextmenu.h4
2 files changed, 21 insertions, 10 deletions
diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp
index 126baf6e8..0c192de38 100644
--- a/src/dolphincontextmenu.cpp
+++ b/src/dolphincontextmenu.cpp
@@ -61,6 +61,8 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
// or the items itself. To increase the performance both lists are cached.
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
m_selectedItems = view->selectedItems();
+
+ installEventFilter(this);
}
DolphinContextMenu::~DolphinContextMenu()
@@ -110,20 +112,28 @@ DolphinContextMenu::Command DolphinContextMenu::open()
return m_command;
}
-void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
+void DolphinContextMenu::childEvent(QChildEvent* event)
{
- if (m_removeAction && ev->key() == Qt::Key_Shift) {
- m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
+ if(event->added()) {
+ event->child()->installEventFilter(this);
}
- QMenu::keyPressEvent(ev);
+ QMenu::childEvent(event);
}
-void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev)
+bool DolphinContextMenu::eventFilter(QObject* dest, QEvent* event)
{
- if (m_removeAction && ev->key() == Qt::Key_Shift) {
- m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
+ 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) {
+ m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
+ } else {
+ m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
+ }
+ return true;
+ }
}
- QMenu::keyReleaseEvent(ev);
+ return QMenu::eventFilter(dest, event);
}
void DolphinContextMenu::openTrashContextMenu()
@@ -198,6 +208,7 @@ void DolphinContextMenu::addDirectoryItemContextMenu(KFileItemActions &fileItemA
QMenu* menu = newFileMenu->menu();
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
+ menu->setParent(this, Qt::Popup);
addMenu(menu);
addSeparator();
diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h
index 523c0555a..7f0b6988a 100644
--- a/src/dolphincontextmenu.h
+++ b/src/dolphincontextmenu.h
@@ -74,8 +74,8 @@ public:
Command open();
protected:
- void keyPressEvent(QKeyEvent *ev) override;
- void keyReleaseEvent(QKeyEvent *ev) override;
+ void childEvent(QChildEvent* event) override;
+ bool eventFilter(QObject* dest, QEvent* event) override;
private:
void openTrashContextMenu();