mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Action for toggling scrollbars
This commit is contained in:
parent
a358d86620
commit
a9d360dcb4
5 changed files with 52 additions and 6 deletions
|
|
@ -181,4 +181,10 @@ actions = [
|
|||
'shortcuts': ['Ctrl+H'],
|
||||
'callback': 'on_action_help',
|
||||
},
|
||||
{
|
||||
'id': 'show_scrollbars',
|
||||
'text': 'Show &Scrollbars',
|
||||
'checkable': True,
|
||||
'callback': 'on_action_show_scrollbars',
|
||||
},
|
||||
]
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ menu_structure = [
|
|||
'items': [
|
||||
'fit_scene',
|
||||
'fit_selection',
|
||||
MENU_SEPARATOR,
|
||||
'show_scrollbars',
|
||||
],
|
||||
},
|
||||
'insert_images',
|
||||
|
|
|
|||
|
|
@ -42,9 +42,13 @@ class ActionsMixin:
|
|||
qaction = QtGui.QAction(action['text'], self)
|
||||
if 'shortcuts' in action:
|
||||
qaction.setShortcuts(action['shortcuts'])
|
||||
qaction.triggered.connect(getattr(self, action['callback']))
|
||||
if action.get('checkable', False):
|
||||
qaction.toggled.connect(getattr(self, action['callback']))
|
||||
else:
|
||||
qaction.triggered.connect(getattr(self, action['callback']))
|
||||
self.addAction(qaction)
|
||||
qaction.setEnabled(action.get('enabled', True))
|
||||
qaction.setCheckable(action.get('checkable', False))
|
||||
self.bee_actions[action['id']] = qaction
|
||||
if 'group' in action:
|
||||
self.bee_actiongroups[action['group']].append(qaction)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
|
|||
self.scene = BeeGraphicsScene(self.undo_stack)
|
||||
self.filename = None
|
||||
|
||||
# TBD: make scrollbar configurable
|
||||
self.setHorizontalScrollBarPolicy(
|
||||
Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||
self.setVerticalScrollBarPolicy(
|
||||
|
|
@ -143,6 +142,18 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
|
|||
def on_action_fit_selection(self):
|
||||
self.fit_rect(self.scene.itemsBoundingRect(selection_only=True))
|
||||
|
||||
def on_action_show_scrollbars(self, checked):
|
||||
if checked:
|
||||
self.setHorizontalScrollBarPolicy(
|
||||
Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||
self.setVerticalScrollBarPolicy(
|
||||
Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||
else:
|
||||
self.setHorizontalScrollBarPolicy(
|
||||
Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||
self.setVerticalScrollBarPolicy(
|
||||
Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||
|
||||
def on_action_undo(self):
|
||||
logger.debug('Undo: %s' % self.undo_stack.undoText())
|
||||
self.undo_stack.undo()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ class ActionsMixinTestCase(BeeTestCase):
|
|||
self.addCleanup(actions_patcher.stop)
|
||||
self.widget = FooWidget()
|
||||
|
||||
def test_create_actions(self):
|
||||
@patch('PyQt6.QtGui.QAction.triggered')
|
||||
@patch('PyQt6.QtGui.QAction.toggled')
|
||||
def test_create_actions(self, toggle_mock, trigger_mock):
|
||||
self.actions_mock.__iter__.return_value = [{
|
||||
'id': 'foo',
|
||||
'text': '&Foo',
|
||||
|
|
@ -31,9 +33,10 @@ class ActionsMixinTestCase(BeeTestCase):
|
|||
'callback': 'on_foo',
|
||||
}]
|
||||
|
||||
with patch('PyQt6.QtGui.QAction.triggered') as trigger_mock:
|
||||
self.widget._create_actions()
|
||||
trigger_mock.connect.assert_called_once_with(self.widget.on_foo)
|
||||
self.widget._create_actions()
|
||||
trigger_mock.connect.assert_called_once_with(self.widget.on_foo)
|
||||
toggle_mock.connect.assert_not_called()
|
||||
|
||||
assert len(self.widget.actions()) == 1
|
||||
qaction = self.widget.actions()[0]
|
||||
qaction.text() == '&Foo'
|
||||
|
|
@ -41,6 +44,26 @@ class ActionsMixinTestCase(BeeTestCase):
|
|||
qaction.isEnabled() is True
|
||||
assert self.widget.bee_actions['foo'] == qaction
|
||||
|
||||
@patch('PyQt6.QtGui.QAction.triggered')
|
||||
@patch('PyQt6.QtGui.QAction.toggled')
|
||||
def test_create_actions_checkable(self, toggle_mock, trigger_mock):
|
||||
self.actions_mock.__iter__.return_value = [{
|
||||
'id': 'foo',
|
||||
'text': '&Foo',
|
||||
'checkable': True,
|
||||
'callback': 'on_foo',
|
||||
}]
|
||||
|
||||
self.widget._create_actions()
|
||||
trigger_mock.connect.assert_not_called()
|
||||
toggle_mock.connect.assert_called_once_with(self.widget.on_foo)
|
||||
|
||||
assert len(self.widget.actions()) == 1
|
||||
qaction = self.widget.actions()[0]
|
||||
qaction.text() == '&Foo'
|
||||
qaction.isEnabled() is True
|
||||
assert self.widget.bee_actions['foo'] == qaction
|
||||
|
||||
def test_create_actions_enabled_false(self):
|
||||
self.actions_mock.__iter__.return_value = [{
|
||||
'id': 'foo',
|
||||
|
|
|
|||
Loading…
Reference in a new issue