Don't show parent window's context menu on viewers

* When right clicking on image viewers while they are docked, the context menu of the Results window showed up.
* This also enables capture of right click and middle click buttons to drag around images, which solves a conflict with some theme engines that enable left mouse button click to drag a window's position regardless of where the event happens, hence blocking the panning.
* Probably unnecessary to check which button is released.
This commit is contained in:
glubsy 2020-09-03 01:44:01 +02:00
parent 089f00adb8
commit b8af2a4eb5
1 changed files with 22 additions and 9 deletions

View File

@ -758,11 +758,15 @@ class QWidgetImageViewer(QWidget):
return
self.disconnectMouseSignals()
def contextMenuEvent(self, event):
"""Block parent's (main window) context menu on right click."""
event.accept()
def mousePressEvent(self, event):
if self.bestFit or not self.isEnabled():
event.ignore()
return
if event.button() == Qt.LeftButton:
if event.button() & (Qt.LeftButton | Qt.MidButton | Qt.RightButton):
self._drag = True
else:
self._drag = False
@ -790,8 +794,8 @@ class QWidgetImageViewer(QWidget):
if self.bestFit or not self.isEnabled():
event.ignore()
return
if event.button() == Qt.LeftButton:
self._drag = False
# if event.button() == Qt.LeftButton:
self._drag = False
self._app.restoreOverrideCursor()
self.setMouseTracking(False)
@ -956,11 +960,18 @@ class ScrollAreaImageViewer(QScrollArea):
self._horizontalScrollBar.valueChanged.connect(
self.controller.onHScrollBarChanged, Qt.UniqueConnection)
def contextMenuEvent(self, event):
"""Block parent's (main window) context menu on right click."""
# Even though we don't have a context menu right now, and the default
# contextMenuPolicy is DefaultContextMenu, we leverage that handler to
# avoid raising the Result window's Actions menu
event.accept()
def mousePressEvent(self, event):
if self.bestFit:
event.ignore()
return
if event.button() == Qt.LeftButton:
if event.button() & (Qt.LeftButton | Qt.MidButton | Qt.RightButton):
self._drag = True
else:
self._drag = False
@ -985,8 +996,7 @@ class ScrollAreaImageViewer(QScrollArea):
if self.bestFit:
event.ignore()
return
if event.button() == Qt.LeftButton:
self._drag = False
self._drag = False
self._app.restoreOverrideCursor()
self.setMouseTracking(False)
super().mouseReleaseEvent(event)
@ -1203,11 +1213,15 @@ class GraphicsViewViewer(QGraphicsView):
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
def contextMenuEvent(self, event):
"""Block parent's (main window) context menu on right click."""
event.accept()
def mousePressEvent(self, event):
if self.bestFit:
event.ignore()
return
if event.button() == Qt.LeftButton:
if event.button() & (Qt.LeftButton | Qt.MidButton | Qt.RightButton):
self._drag = True
else:
self._drag = False
@ -1223,8 +1237,7 @@ class GraphicsViewViewer(QGraphicsView):
if self.bestFit:
event.ignore()
return
if event.button() == Qt.LeftButton:
self._drag = False
self._drag = False
self._app.restoreOverrideCursor()
self.setMouseTracking(False)
self.updateCenterPoint()