mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Use different cursor for moving the BeeRef window
This commit is contained in:
parent
0e3fdf5c72
commit
51b9bafbeb
4 changed files with 42 additions and 41 deletions
|
|
@ -1,6 +1,13 @@
|
|||
0.3.3 - (unreleased)
|
||||
====================
|
||||
|
||||
Added
|
||||
-----
|
||||
|
||||
* Moving the window from within BeeRef now changes to a diffent cursor from
|
||||
the default arrow cursor.
|
||||
|
||||
|
||||
Fixed
|
||||
-----
|
||||
|
||||
|
|
|
|||
|
|
@ -119,13 +119,16 @@ class BaseItemMixin:
|
|||
return self.mapToScene(self.center)
|
||||
|
||||
def set_cursor(self, cursor):
|
||||
self.scene().cursor_changed.emit(cursor)
|
||||
# Can't use setCursor on the item itself because of bug
|
||||
# https://bugreports.qt.io/browse/QTBUG-4190
|
||||
if self.scene():
|
||||
self.scene().cursor_changed.emit(cursor)
|
||||
|
||||
def unset_cursor(self):
|
||||
self.scene().cursor_cleared.emit()
|
||||
|
||||
def hoverLeaveEvent(self, event):
|
||||
self.unset_cursor()
|
||||
# Can't use unsetCursor on the item itself because of bug
|
||||
# https://bugreports.qt.io/browse/QTBUG-4190
|
||||
if self.scene():
|
||||
self.scene().cursor_cleared.emit()
|
||||
|
||||
|
||||
class SelectableMixin(BaseItemMixin):
|
||||
|
|
@ -378,7 +381,8 @@ class SelectableMixin(BaseItemMixin):
|
|||
for corner in self.corners:
|
||||
# See if we need to change the cursor for interactable areas
|
||||
if self.get_scale_bounds(corner).contains(event.pos()):
|
||||
self.scene().cursor_changed.emit(self.get_corner_scale_cursor(corner))
|
||||
self.scene().cursor_changed.emit(
|
||||
self.get_corner_scale_cursor(corner))
|
||||
self.set_cursor(self.get_corner_scale_cursor(corner))
|
||||
return
|
||||
elif self.get_rotate_bounds(corner).contains(event.pos()):
|
||||
|
|
@ -394,10 +398,8 @@ class SelectableMixin(BaseItemMixin):
|
|||
|
||||
self.unset_cursor()
|
||||
|
||||
def hoverEnterEvent(self, event):
|
||||
# Always set regular cursor when there aren't any selection handles
|
||||
if not self.has_selection_handles():
|
||||
self.unset_cursor()
|
||||
def hoverLeaveEvent(self, event):
|
||||
self.unset_cursor()
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
self.event_start = event.scenePos()
|
||||
|
|
|
|||
|
|
@ -606,12 +606,10 @@ class BeeGraphicsView(MainControlsMixin,
|
|||
self.viewport().repaint()
|
||||
|
||||
def on_cursor_changed(self, cursor):
|
||||
print('set', cursor.shape())
|
||||
if not self.pan_active:
|
||||
self.viewport().setCursor(cursor)
|
||||
|
||||
def on_cursor_cleared(self):
|
||||
print('unset')
|
||||
if not self.pan_active:
|
||||
self.viewport().unsetCursor()
|
||||
|
||||
|
|
@ -728,11 +726,13 @@ class BeeGraphicsView(MainControlsMixin,
|
|||
if (event.button() == Qt.MouseButton.MiddleButton
|
||||
or (event.button() == Qt.MouseButton.LeftButton
|
||||
and event.modifiers() == Qt.KeyboardModifier.AltModifier)):
|
||||
logger.debug('Begin pan')
|
||||
logger.trace('Begin pan')
|
||||
self.pan_active = True
|
||||
self.event_start = event.position()
|
||||
self.viewport().setCursor(Qt.CursorShape.ClosedHandCursor)
|
||||
self.setCursor(Qt.CursorShape.ClosedHandCursor)
|
||||
# ClosedHandCursor and OpenHandCursor don't work, but I
|
||||
# don't know if that's only on my system or a general
|
||||
# problem. It works with other cursors.
|
||||
event.accept()
|
||||
return
|
||||
|
||||
|
|
@ -762,7 +762,7 @@ class BeeGraphicsView(MainControlsMixin,
|
|||
|
||||
def mouseReleaseEvent(self, event):
|
||||
if self.pan_active:
|
||||
logger.debug('End pan')
|
||||
logger.trace('End pan')
|
||||
self.viewport().unsetCursor()
|
||||
self.pan_active = False
|
||||
event.accept()
|
||||
|
|
|
|||
|
|
@ -634,11 +634,11 @@ def test_hover_move_event_no_selection(view, item):
|
|||
view.scene.addItem(item)
|
||||
event = MagicMock()
|
||||
event.pos.return_value = QtCore.QPointF(0, 0)
|
||||
item.setCursor = MagicMock()
|
||||
item.set_cursor = MagicMock()
|
||||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
item.setCursor.assert_not_called()
|
||||
item.set_cursor.assert_not_called()
|
||||
|
||||
|
||||
def test_hover_move_event_small_item_inside_handle_free_center(view, item):
|
||||
|
|
@ -646,11 +646,11 @@ def test_hover_move_event_small_item_inside_handle_free_center(view, item):
|
|||
item.setSelected(True)
|
||||
event = MagicMock()
|
||||
event.pos.return_value = QtCore.QPointF(10, 10)
|
||||
item.setCursor = MagicMock()
|
||||
item.unset_cursor = MagicMock()
|
||||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 20, 20)):
|
||||
item.hoverMoveEvent(event)
|
||||
item.setCursor.assert_called_once_with(Qt.CursorShape.ArrowCursor)
|
||||
item.unset_cursor.assert_called_once_with()
|
||||
|
||||
|
||||
@mark.parametrize('pos,flipped,rotation, expected',
|
||||
|
|
@ -684,7 +684,7 @@ def test_hover_move_event_scale(
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == getattr(Qt.CursorShape, expected)
|
||||
assert view.viewport().cursor() == getattr(Qt.CursorShape, expected)
|
||||
|
||||
|
||||
def test_hover_move_event_scale_bottomright_very_wide_item(view, item):
|
||||
|
|
@ -695,7 +695,7 @@ def test_hover_move_event_scale_bottomright_very_wide_item(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 1000, 100)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == Qt.CursorShape.SizeFDiagCursor
|
||||
assert view.viewport().cursor() == Qt.CursorShape.SizeFDiagCursor
|
||||
|
||||
|
||||
def test_hover_move_event_rotate(view, item):
|
||||
|
|
@ -706,7 +706,7 @@ def test_hover_move_event_rotate(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == BeeAssets().cursor_rotate
|
||||
assert view.viewport().cursor() == BeeAssets().cursor_rotate
|
||||
|
||||
|
||||
def test_hover_flip_event_top_edge(view, item):
|
||||
|
|
@ -717,7 +717,7 @@ def test_hover_flip_event_top_edge(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == BeeAssets().cursor_flip_v
|
||||
assert view.viewport().cursor() == BeeAssets().cursor_flip_v
|
||||
|
||||
|
||||
def test_hover_flip_event_bottom_edge(view, item):
|
||||
|
|
@ -728,7 +728,7 @@ def test_hover_flip_event_bottom_edge(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == BeeAssets().cursor_flip_v
|
||||
assert view.viewport().cursor() == BeeAssets().cursor_flip_v
|
||||
|
||||
|
||||
def test_hover_flip_event_left_edge(view, item):
|
||||
|
|
@ -739,7 +739,7 @@ def test_hover_flip_event_left_edge(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == BeeAssets().cursor_flip_h
|
||||
assert view.viewport().cursor() == BeeAssets().cursor_flip_h
|
||||
|
||||
|
||||
def test_hover_flip_event_right_edge(view, item):
|
||||
|
|
@ -750,7 +750,7 @@ def test_hover_flip_event_right_edge(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == BeeAssets().cursor_flip_h
|
||||
assert view.viewport().cursor() == BeeAssets().cursor_flip_h
|
||||
|
||||
|
||||
def test_hover_flip_event_top_edge_rotated_90(view, item):
|
||||
|
|
@ -762,7 +762,7 @@ def test_hover_flip_event_top_edge_rotated_90(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == BeeAssets().cursor_flip_h
|
||||
assert view.viewport().cursor() == BeeAssets().cursor_flip_h
|
||||
|
||||
|
||||
def test_hover_flip_event_left_edge_when_rotated_90(view, item):
|
||||
|
|
@ -774,7 +774,7 @@ def test_hover_flip_event_left_edge_when_rotated_90(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 100, 80)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == BeeAssets().cursor_flip_v
|
||||
assert view.viewport().cursor() == BeeAssets().cursor_flip_v
|
||||
|
||||
|
||||
def test_hover_move_event_not_in_handles(view, item):
|
||||
|
|
@ -785,24 +785,16 @@ def test_hover_move_event_not_in_handles(view, item):
|
|||
with patch.object(item, 'bounding_rect_unselected',
|
||||
return_value=QtCore.QRectF(0, 0, 1000, 800)):
|
||||
item.hoverMoveEvent(event)
|
||||
assert item.cursor() == Qt.CursorShape.ArrowCursor
|
||||
assert view.viewport().cursor() == Qt.CursorShape.ArrowCursor
|
||||
|
||||
|
||||
def test_hover_enter_event_when_selected(view, item):
|
||||
def test_hover_leave_event(view, item):
|
||||
view.scene.addItem(item)
|
||||
event = MagicMock()
|
||||
item.setSelected(True)
|
||||
item.setCursor = MagicMock()
|
||||
item.hoverEnterEvent(event)
|
||||
item.setCursor.assert_not_called()
|
||||
|
||||
|
||||
def test_hover_enter_event_when_not_selected(view, item):
|
||||
view.scene.addItem(item)
|
||||
event = MagicMock()
|
||||
item.setSelected(False)
|
||||
item.hoverEnterEvent(event)
|
||||
assert item.cursor() == Qt.CursorShape.ArrowCursor
|
||||
item.unset_cursor = MagicMock()
|
||||
item.hoverLeaveEvent(event)
|
||||
item.unset_cursor.assert_called_once_with()
|
||||
|
||||
|
||||
def test_mouse_press_event_just_selected(view, item):
|
||||
|
|
|
|||
Loading…
Reference in a new issue