Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 12 additions & 10 deletions opencodeblocks/graphics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,25 @@ def centerView(self, x: float, y: float):
hsb.setValue(x * self.zoom - self.width() / 2)
vsb.setValue(y * self.zoom - self.height() / 2)

def moveToGlobalView(self) -> bool:
"""
OCBView reaction to the space bar being pressed.
Returns True if the event was handled.
def moveToItems(self) -> bool:
"""Ajust zoom and position to make selected items visible.

If no item is selected, make the whole graph visible instead.

Returns:
True if the event was handled, False otherwise.
"""

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

items = self.scene().items()

# If items are selected, overwride the behvaior
if len(self.scene().selectedItems()) > 0:
items = self.scene().selectedItems()

code_blocks: List[OCBBlock] = [i for i in items if isinstance(i, OCBBlock)]

if len(code_blocks) == 0:
Expand Down Expand Up @@ -263,10 +269,6 @@ def keyPressEvent(self, event: QKeyEvent):
if self.moveViewOnArrow(event):
return

if key_id == Qt.Key.Key_Space:
if self.moveToGlobalView():
return

super().keyPressEvent(event)

def retreiveBlockTypes(self) -> List[Tuple[str]]:
Expand Down
9 changes: 6 additions & 3 deletions opencodeblocks/graphics/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def load(self, filepath: str):
self.scene.load(filepath)
self.savepath = filepath

def moveToGlobalView(self):
"""Center the view to see the hole graph"""
self.view.moveToGlobalView()
def moveToItems(self):
"""
Ajust zoom and position to make the whole graph visible.
If items are selected, then make all the selected items visible instead
"""
self.view.moveToItems()
Loading