Commit c59b46ea authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Minor fixes with zoom out

parent 49d5991c
......@@ -335,9 +335,12 @@ class Signalroute(Connection):
# Arrow always bumps at the screen edge
try:
view = self.scene().views()[0]
#view.update_phantom_rect()
# view_pos is the position of the view relative to the scene
view_pos = view.mapToScene(
view.viewport().geometry()).boundingRect().topLeft()
scene_pos_x = self.mapFromScene(view_pos).x()
#print view_pos.x(), scene_pos_x, view.sceneRect().x()
return QPointF(scene_pos_x, self.start_point.y())
except (IndexError, AttributeError):
# In case there is no view (e.g. Export PNG from cmd line)
......@@ -395,13 +398,17 @@ class Signalroute(Connection):
process.output_signals.append(get_sig(sig))
else:
# input signals of process 'source'
process, = [p for p in CONTEXT.processes
try:
process, = [p for p in CONTEXT.processes
if p.processName.lower() == each['dest'].lower()]
existing = [sig['name'].lower()
existing = [sig['name'].lower()
for sig in process.input_signals]
for sig in sigs:
if sig['name'].lower() not in existing:
process.input_signals.append(get_sig(sig))
for sig in sigs:
if sig['name'].lower() not in existing:
process.input_signals.append(get_sig(sig))
except ValueError:
# No process found
pass
existing = [sig['name'].lower() for sig in CONTEXT.signals]
for each in all_sigs:
if each['name'].lower() not in existing:
......
......@@ -1615,8 +1615,12 @@ class SDL_View(QtGui.QGraphicsView, object):
''' Handle keyboard: Zoom, open/save diagram, etc. '''
if event.matches(QtGui.QKeySequence.ZoomOut):
self.scale(0.8, 0.8)
# Make sure the scene is resized when zooming in/out
self.update_phantom_rect()
elif event.matches(QtGui.QKeySequence.ZoomIn):
self.scale(1.2, 1.2)
# Make sure the scene is resized when zooming in/out
self.update_phantom_rect()
elif event.key() == Qt.Key_Q and event.modifiers() == Qt.ControlModifier:
# Reset zoom with Ctrl-Q
self.resetTransform()
......@@ -1666,6 +1670,20 @@ class SDL_View(QtGui.QGraphicsView, object):
self.setSceneRect(self.scene().sceneRect())
self.viewport().update()
def update_phantom_rect(self):
scene_rect = self.scene().itemsBoundingRect()
view_size = self.size()
scene_rect.setWidth(max(scene_rect.width(), view_size.width()))
scene_rect.setHeight(max(scene_rect.height(), view_size.height()))
if self.phantom_rect and self.phantom_rect in self.scene().items():
self.phantom_rect.setRect(scene_rect)
else:
self.phantom_rect = self.scene().addRect(scene_rect,
pen=QtGui.QPen(QtGui.QColor(0, 0, 0, 0)))
# Hide the rectangle so that it does not collide with the symbols
self.phantom_rect.hide()
self.refresh()
# pylint: disable=C0103
def resizeEvent(self, event):
'''
......@@ -1677,20 +1695,8 @@ class SDL_View(QtGui.QGraphicsView, object):
the user wants to place a symbol at an exact position - in
that case, the automatic centering is not appropriate.
'''
LOG.debug('resizing view')
scene_rect = self.scene().itemsBoundingRect()
view_size = self.size()
scene_rect.setWidth(max(scene_rect.width(), view_size.width()))
scene_rect.setHeight(max(scene_rect.height(), view_size.height()))
if self.phantom_rect and self.phantom_rect in self.scene().items():
#self.scene().removeItem(self.phantom_rect)
# XXX stop with removeItem, it provokes segfault
self.phantom_rect.hide()
self.phantom_rect = self.scene().addRect(scene_rect,
pen=QtGui.QPen(QtGui.QColor(0, 0, 0, 0)))
# Hide the rectangle so that it does not collide with the symbols
self.phantom_rect.hide()
self.refresh()
LOG.debug('[QGraphicsView] ResizeEvent')
self.update_phantom_rect()
super(SDL_View, self).resizeEvent(event)
def about_og(self):
......@@ -1714,6 +1720,8 @@ class SDL_View(QtGui.QGraphicsView, object):
else:
self.scale(1.1, 1.1)
self.setTransformationAnchor(QtGui.QGraphicsView.AnchorViewCenter)
# Make sure the scene is resized when zooming in/out
self.update_phantom_rect()
else:
return super(SDL_View, self).wheelEvent(wheelEvent)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment