mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Reset view when no items; ignore pan and zoom when no items
This commit is contained in:
parent
8ee5e1db68
commit
a907343d04
2 changed files with 22 additions and 10 deletions
|
|
@ -79,6 +79,7 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
|
|||
def on_scene_changed(self, region):
|
||||
if not self.scene.items():
|
||||
logger.info('No items in scene')
|
||||
self.setTransform(QtGui.QTransform())
|
||||
self.welcome_overlay.show()
|
||||
else:
|
||||
self.welcome_overlay.hide()
|
||||
|
|
@ -314,6 +315,9 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
|
|||
return self.transform().m11()
|
||||
|
||||
def wheelEvent(self, event):
|
||||
if not self.scene.items():
|
||||
logger.debug('No items in scene; ignore zoom')
|
||||
return
|
||||
factor = 1.2
|
||||
if event.angleDelta().y() > 0:
|
||||
if self.get_zoom_size(max) < 10000000:
|
||||
|
|
@ -344,6 +348,10 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
|
|||
if (event.button() == Qt.MouseButtons.MiddleButton
|
||||
or (event.button() == Qt.MouseButtons.LeftButton
|
||||
and event.modifiers() == Qt.KeyboardModifiers.AltModifier)):
|
||||
if not self.scene.items():
|
||||
logger.debug('No items in scene; ignore pan')
|
||||
return
|
||||
|
||||
self.pan_active = True
|
||||
self.pan_start = event.position()
|
||||
self.setCursor(Qt.CursorShape.ClosedHandCursor)
|
||||
|
|
|
|||
|
|
@ -43,21 +43,25 @@ class BeeGraphicsViewTestCase(BeeTestCase):
|
|||
open_file_mock.assert_called_once_with('test.bee')
|
||||
del view
|
||||
|
||||
@patch('beeref.view.BeeGraphicsView.recalc_scene_rect')
|
||||
@patch('beeref.gui.WelcomeOverlay.hide')
|
||||
def test_on_scene_changed_when_items(self, hide_mock, recalc_mock):
|
||||
def test_on_scene_changed_when_items(self, hide_mock):
|
||||
item = BeePixmapItem(QtGui.QImage())
|
||||
self.view.scene.addItem(item)
|
||||
self.view.on_scene_changed(None)
|
||||
recalc_mock.assert_called_once_with()
|
||||
hide_mock.assert_called_once_with()
|
||||
self.view.scale(2, 2)
|
||||
with patch('beeref.view.BeeGraphicsView.recalc_scene_rect') as r:
|
||||
self.view.on_scene_changed(None)
|
||||
r.assert_called_once_with()
|
||||
hide_mock.assert_called_once_with()
|
||||
assert self.view.get_scale() == 2
|
||||
|
||||
@patch('beeref.view.BeeGraphicsView.recalc_scene_rect')
|
||||
@patch('beeref.gui.WelcomeOverlay.show')
|
||||
def test_on_scene_changed_when_no_items(self, show_mock, recalc_mock):
|
||||
self.view.on_scene_changed(None)
|
||||
recalc_mock.assert_called_once_with()
|
||||
show_mock.assert_called_once_with()
|
||||
def test_on_scene_changed_when_no_items(self, show_mock):
|
||||
self.view.scale(2, 2)
|
||||
with patch('beeref.view.BeeGraphicsView.recalc_scene_rect') as r:
|
||||
self.view.on_scene_changed(None)
|
||||
r.assert_called()
|
||||
show_mock.assert_called_once_with()
|
||||
assert self.view.get_scale() == 1
|
||||
|
||||
def test_get_supported_image_formats_for_reading(self):
|
||||
formats = self.view.get_supported_image_formats(QtGui.QImageReader)
|
||||
|
|
|
|||
Loading…
Reference in a new issue