Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions pyflow/graphics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ def moveToItems(self) -> bool:
True if the event was handled, False otherwise.
"""

# The focusItem has priority for this event
if self.scene().focusItem() is not None:
return False

items = self.scene().items()

# If items are selected, overwride the behvaior
Expand Down Expand Up @@ -193,9 +189,16 @@ def moveToItems(self) -> bool:
required_zoom_x: float = self.width() / (max_x - min_x)
required_zoom_y: float = self.height() / (max_y - min_y)

# Operate the zoom and the translation
self.setZoom(min(required_zoom_x, required_zoom_y))
# Operate the zoom
# If there is only one item, don't make it very big
if len(code_blocks) == 1:
self.setZoom(1)
else:
self.setZoom(min(required_zoom_x, required_zoom_y))

# Operate the translation
self.centerView(center_x, center_y)

return True

def getDistanceToCenter(self, x: float, y: float) -> Tuple[float]:
Expand Down Expand Up @@ -238,6 +241,7 @@ def moveViewOnArrow(self, event: QKeyEvent) -> bool:
selected_item.y() + selected_item.height / 2,
)
self.scene().clearSelection()
self.bring_block_forward(selected_item)

dist_array = []
for block in code_blocks:
Expand Down Expand Up @@ -280,6 +284,7 @@ def oriented_distance(x, y, key):
item_to_navigate = self.scene().itemAt(
block_center_x, block_center_y, self.transform()
)
self.scene().clearSelection()
if isinstance(item_to_navigate.parentItem(), Block):
item_to_navigate.parentItem().setSelected(True)

Expand Down Expand Up @@ -382,6 +387,7 @@ def bring_block_forward(self, block: Block):
):
self.currentSelectedBlock.setZValue(0)
block.setZValue(1)
block.setSelected(True)
self.currentSelectedBlock = block

def drag_scene(self, event: QMouseEvent, action="press"):
Expand Down