Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Add zoom in and out shortcut #286

Merged
merged 1 commit into from
Feb 19, 2022
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
17 changes: 15 additions & 2 deletions pyflow/graphics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
BLOCKFILES_PATH = os.path.join(BLOCK_PATH, "blockfiles")

EPS: float = 1e-10 # To check if blocks are of size 0
ZOOM_INCREMENT = 1.2
LOGGER = get_logger(__name__)


Expand Down Expand Up @@ -376,6 +377,16 @@ def setZoom(self, new_zoom: float):
self.scale(zoom_factor, zoom_factor)
self.zoom = new_zoom

def zoomIn(self):
"""Zoom in."""

self.setZoom(self.zoom * ZOOM_INCREMENT)

def zoomOut(self):
"""Zoom out"""

self.setZoom(self.zoom / ZOOM_INCREMENT)

def deleteSelected(self):
"""Delete selected items from the current scene."""
scene = self.scene()
Expand Down Expand Up @@ -510,8 +521,10 @@ def drag_edge(self, event: QMouseEvent, action="press"):
):
# Link a new CodeBlock under the selected block
parent: CodeBlock = item_at_click.block
empty_code_block_path: str = os.path.join(BLOCKFILES_PATH, "empty.pfb")
new_block = self.scene().create_block_from_file(empty_code_block_path, 0, 0)
empty_code_block_path: str = os.path.join(BLOCKFILES_PATH, "empty.pfb")
new_block = self.scene().create_block_from_file(
empty_code_block_path, 0, 0
)
parent.link_and_place(new_block)
scene.history.checkpoint(
"Created a new linked block", set_modified=True
Expand Down
26 changes: 26 additions & 0 deletions pyflow/graphics/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ def createActions(self):
shortcut=" ",
triggered=self.onMoveToItems,
)
self._actZoomIn = QAction(
"Zoom in",
statusTip="Zoom in",
shortcut=QKeySequence.ZoomIn,
triggered=self.onZoomIn,
)
self._actZoomOut = QAction(
"Zoom out",
statusTip="Zoom out",
shortcut=QKeySequence.ZoomOut,
triggered=self.onZoomOut,
)

# Window
self._actClose = QAction(
Expand Down Expand Up @@ -252,6 +264,8 @@ def createMenus(self):
self.thememenu = self.viewmenu.addMenu("Theme")
self.thememenu.aboutToShow.connect(self.updateThemeMenu)
self.viewmenu.addAction(self._actViewItems)
self.viewmenu.addAction(self._actZoomIn)
self.viewmenu.addAction(self._actZoomOut)

self.windowMenu = self.menuBar().addMenu("&Window")
self.updateWindowMenu()
Expand Down Expand Up @@ -543,6 +557,18 @@ def onMoveToItems(self):
if current_window is not None and isinstance(current_window, Widget):
current_window.moveToItems()

def onZoomIn(self):
"""Zoom in, in the current window.."""
current_window = self.activeMdiChild()
if current_window is not None and isinstance(current_window, Widget):
current_window.view.zoomIn()

def onZoomOut(self):
"""Zoom out, in the current window."""
current_window = self.activeMdiChild()
if current_window is not None and isinstance(current_window, Widget):
current_window.view.zoomOut()

def setTheme(self, theme_index):
"""Set the theme of the application."""
theme_manager().selected_theme_index = theme_index