From f72dadb0c16a023c444e406b8acfa84f09f2ab31 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 20 Feb 2017 12:22:06 +0000 Subject: [PATCH] Work round missing right click event after dismissing a context menu There is a bug that can happen in the following situation: - user right clicks to open a menu - that context menu grabs input - the QGrabphicsView also notes the mouse was pressed, but not that the mouse was released because it doesn't have mouse events any more - when a user clicks to dismiss the menu and then without moving clicks quickly again to send, we don't get another press event because the QGraphicsScene still thinks the mouse is pressed from the first time the context menu was shown and QGraphicsScenePrivate::lastMouseGrabberItemHasImplicitMouseGrab still points to the old object. This is a known bug in QGraphicsView and you can see QGraphicsScenePrivate::sendMouseEvent has a workaround to reset the lastMouseGrabberItemHasImplicitMouseGrab on mouse moves, with the comment: "This is a temporary fix for until we get proper mouse grab events." Realistically this isn't going to happen in QGraphicsView now. We do get a double click event though. By checking for double click events we can grab those missed clicks. It doesn't cause any other side effects because normally the context menu will fire after the first click and this rarely gets processed. REVIEW: 129960 --- src/kitemviews/kitemlistcontroller.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 1c86ff03f..a95969771 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -801,6 +801,22 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, } } + if (event->button() & Qt::RightButton) { + m_selectionManager->clearSelection(); + if (index >= 0) { + m_selectionManager->setSelected(index); + emit itemContextMenuRequested(index, event->screenPos()); + } else { + const QRectF headerBounds = m_view->headerBoundaries(); + if (headerBounds.contains(event->pos())) { + emit headerContextMenuRequested(event->screenPos()); + } else { + emit viewContextMenuRequested(event->screenPos()); + } + } + return true; + } + bool emitItemActivated = !(m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) && (event->button() & Qt::LeftButton) && index >= 0 && index < m_model->count(); -- 2.47.3