Add Select All/Deselect All

This commit is contained in:
Rebecca Breu 2021-04-17 13:01:15 +02:00
parent 6f77c43d76
commit 7ab442f6b5
6 changed files with 54 additions and 1 deletions

View file

@ -163,4 +163,16 @@ actions = [
'group': 'active_when_selection',
'enabled': False,
},
{
'id': 'select_all',
'text': '&Select All',
'shortcuts': ['Ctrl+A'],
'callback': 'on_action_select_all',
},
{
'id': 'deselect_all',
'text': 'Deselect &All',
'shortcuts': ['Ctrl+Shift+A'],
'callback': 'on_action_deselect_all',
},
]

View file

@ -33,6 +33,10 @@ menu_structure = [
'items': [
'undo',
'redo',
MENU_SEPARATOR,
'select_all',
'deselect_all',
MENU_SEPARATOR,
'paste',
'delete',
],

View file

@ -84,5 +84,7 @@ class BeePixmapItem(SelectableMixin, QtWidgets.QGraphicsPixmapItem):
return [self]
def on_selected_change(self, value):
if(value and self.scene() and not self.scene().has_selection()):
if(value and self.scene()
and not self.scene().has_selection()
and not self.scene().rubberband_active):
self.bring_to_front()

View file

@ -95,6 +95,11 @@ class BeeGraphicsScene(QtWidgets.QGraphicsScene):
self.get_selection_center(),
vertical=vertical))
def set_selected_all_items(self, value):
"""Sets the selection mode of all items to ``value``."""
for item in self.items():
item.setSelected(value)
def has_selection(self):
"""Checks whether there are currently items selected."""

View file

@ -151,6 +151,12 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
logger.debug('Redo: %s' % self.undo_stack.redoText())
self.undo_stack.redo()
def on_action_select_all(self):
self.scene.set_selected_all_items(True)
def on_action_deselect_all(self):
self.scene.set_selected_all_items(False)
def on_action_delete_items(self):
logger.debug('Deleting items...')
self.undo_stack.push(

View file

@ -82,6 +82,30 @@ class BeeGraphicsSceneTestCase(BeeTestCase):
assert cmd.anchor == QtCore.QPointF(60, 50)
assert cmd.vertical is True
def test_set_selection_all_items_when_true(self):
item1 = BeePixmapItem(QtGui.QImage())
self.scene.addItem(item1)
item1.setSelected(True)
item2 = BeePixmapItem(QtGui.QImage())
self.scene.addItem(item2)
item2.setSelected(True)
self.scene.set_selected_all_items(True)
assert item1.isSelected() is True
assert item2.isSelected() is True
def test_set_selection_all_items_when_false(self):
item1 = BeePixmapItem(QtGui.QImage())
self.scene.addItem(item1)
item1.setSelected(True)
item2 = BeePixmapItem(QtGui.QImage())
self.scene.addItem(item2)
item2.setSelected(True)
self.scene.set_selected_all_items(False)
assert item1.isSelected() is False
assert item2.isSelected() is False
def test_has_selection_when_no_selection(self):
item = BeePixmapItem(QtGui.QImage())
self.scene.addItem(item)