Skip to content

Commit

Permalink
globalPosition for PySide2
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzFTD committed Jan 21, 2024
1 parent 0e04b5e commit 5444383
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions grill/views/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ def _parallel_line(line, distance, head_offset=0):
return parallel_line


_EVENT_POSITION_FUNC = QtGui.QMouseEvent if _IS_QT5 else lambda event: event.globalPosition().toPoint()


class _GraphicsViewport(QtWidgets.QGraphicsView):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -394,7 +397,7 @@ def mousePressEvent(self, event):
if event.button() == QtCore.Qt.MiddleButton:
self._dragging = True
QtWidgets.QApplication.setOverrideCursor(QtGui.Qt.ClosedHandCursor)
self._last_pan_pos = event.globalPosition().toPoint()
self._last_pan_pos = _EVENT_POSITION_FUNC(event)
event.accept()

return super().mousePressEvent(event)
Expand All @@ -410,10 +413,10 @@ def mouseReleaseEvent(self, event):
def mouseMoveEvent(self, event):
if self._dragging and event.buttons() == QtCore.Qt.MiddleButton:
# Pan the scene when middle mouse button is held down
delta = event.globalPosition().toPoint() - self._last_pan_pos
delta = _EVENT_POSITION_FUNC(event) - self._last_pan_pos
self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - delta.x())
self.verticalScrollBar().setValue(self.verticalScrollBar().value() - delta.y())
self._last_pan_pos = event.globalPosition().toPoint()
self._last_pan_pos = _EVENT_POSITION_FUNC(event)
return
return super().mouseMoveEvent(event)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _sub_test_scenegraph_composition(self):

widget.deleteLater()

def test_layer_stack_bidirectionality(self):
def _sub_test_layer_stack_bidirectionality(self):
"""Confirm that bidirectionality between layer stacks completes.
Bidirectionality in the composition graph is achieved by:
Expand Down Expand Up @@ -713,7 +713,7 @@ def test_pan(self):
self.assertTrue(view._dragging)

# 2. Mouse move
view._last_pan_pos = middle_button_event.globalPosition().toPoint() + QtCore.QPoint(10,10)
view._last_pan_pos = _graph._EVENT_POSITION_FUNC(middle_button_event) + QtCore.QPoint(10,10)
move_event = QtGui.QMouseEvent(QtCore.QEvent.MouseMove, end_position, QtCore.Qt.MiddleButton, QtCore.Qt.MiddleButton, QtCore.Qt.NoModifier)
view.mouseMoveEvent(move_event)
last_vertical_scroll_bar = vertical_scroll_bar.value()
Expand All @@ -723,7 +723,7 @@ def test_pan(self):

# 3. Release
view.mouseReleaseEvent(middle_button_event)
view._last_pan_pos = middle_button_event.globalPosition().toPoint() + QtCore.QPoint(20, 20)
view._last_pan_pos = _graph._EVENT_POSITION_FUNC(middle_button_event) + QtCore.QPoint(20, 20)
view.mouseMoveEvent(move_event)
# Confirm no further move is performed
self.assertEqual(last_vertical_scroll_bar, vertical_scroll_bar.value())
Expand Down

0 comments on commit 5444383

Please sign in to comment.