Refactor 'just selected' code

This commit is contained in:
Rebecca Breu 2021-10-15 10:17:02 +02:00
parent 333515913a
commit cf55d1a5e3
3 changed files with 5 additions and 24 deletions

View file

@ -16,6 +16,8 @@ Fixed
* Various typos (by luzpaz)
* Ensure that small items always have an area in the middle for
moving/editing that doesn't trigger transform actions
* Ensure that the first click to select an item doesn't immediately trigger
transform actions
0.2.0 - 2021-09-06

View file

@ -142,7 +142,6 @@ class SelectableMixin(BaseItemMixin):
self.scale_active = False
self.rotate_active = False
self.flip_active = False
self.just_selected = False
def is_action_active(self):
return any((self.scale_active,
@ -394,12 +393,11 @@ class SelectableMixin(BaseItemMixin):
self.event_start = event.scenePos()
self.scene().views()[0].reset_previous_transform(toggle_item=self)
if not self.isSelected():
self.just_selected = True
# User has just selected this item with this click; don't
# activate any transformations yet
super().mousePressEvent(event)
return
self.just_selected = False
if event.pos() in self.select_handle_free_center():
# This area should always trigger regular move operations,
# even if it is covered by selection scale/flip/... handles.
@ -566,8 +564,6 @@ class SelectableMixin(BaseItemMixin):
super().mouseMoveEvent(event)
def mouseReleaseEvent(self, event):
just_selected = self.just_selected
self.just_selected = False
if self.scale_active:
if self.get_scale_factor(event) != 1:
self.scene().undo_stack.push(
@ -591,7 +587,7 @@ class SelectableMixin(BaseItemMixin):
event.accept()
self.reset_actions()
return
elif self.flip_active and not just_selected:
elif self.flip_active:
for edge in self.get_flip_bounds():
if edge['rect'].contains(event.pos()):
# We have already flipped on MousePress, but we

View file

@ -16,7 +16,6 @@ def test_init_selectable(view):
assert item.scale_active is False
assert item.rotate_active is False
assert item.flip_active is False
assert item.just_selected is False
def test_is_action_active_when_no_action(view, item):
@ -781,7 +780,6 @@ def test_hover_enter_event_when_not_selected(view, item):
def test_mouse_press_event_just_selected(view, item):
view.scene.addItem(item)
item.just_selected = False
event = MagicMock()
event.pos.return_value = QtCore.QPointF(0, 0)
event.button.return_value = Qt.MouseButton.LeftButton
@ -789,25 +787,10 @@ def test_mouse_press_event_just_selected(view, item):
with patch.object(item, 'bounding_rect_unselected',
return_value=QtCore.QRectF(0, 0, 100, 80)):
item.mousePressEvent(event)
assert item.just_selected is True
event.accept.assert_not_called()
m.assert_called_once_with(event)
def test_mouse_press_event_previously_selected(view, item):
view.scene.addItem(item)
item.setSelected(True)
item.just_selected = True
event = MagicMock()
event.pos.return_value = QtCore.QPointF(0, 0)
event.scenePos.return_value = QtCore.QPointF(-1, -1)
event.button.return_value = Qt.MouseButton.LeftButton
with patch.object(item, 'bounding_rect_unselected',
return_value=QtCore.QRectF(0, 0, 100, 80)):
item.mousePressEvent(event)
assert item.just_selected is False
def test_mouse_press_event_small_item_inside_handle_free_center(view, item):
view.scene.addItem(item)
item.setSelected(True)