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

🪲 Fix zoom stuck bug #145

Merged
merged 2 commits into from
Jan 9, 2022
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
13 changes: 9 additions & 4 deletions pyflow/graphics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from PyQt5.QtWidgets import QGraphicsView, QMenu
from PyQt5.sip import isdeleted


from pyflow.scene import Scene
from pyflow.core.socket import Socket
from pyflow.core.edge import Edge
Expand Down Expand Up @@ -46,7 +45,7 @@ def __init__(
scene: Scene,
parent=None,
zoom_step: float = 1.25,
zoom_min: float = 0.2,
zoom_min: float = 0.05,
zoom_max: float = 5,
):
super().__init__(parent=parent)
Expand Down Expand Up @@ -346,13 +345,19 @@ def wheelEvent(self, event: QWheelEvent):
zoom_factor = 1 / self.zoom_step

new_zoom = self.zoom * zoom_factor
if self.zoom_min < new_zoom < self.zoom_max:
self.setZoom(new_zoom)
self.setZoom(new_zoom)
else:
super().wheelEvent(event)

def setZoom(self, new_zoom: float):
"""Set the zoom to the appropriate level."""

# Constrain the zoom level
if new_zoom > self.zoom_max:
new_zoom = self.zoom_max
if new_zoom < self.zoom_min:
new_zoom = self.zoom_min

zoom_factor = new_zoom / self.zoom
self.scale(zoom_factor, zoom_factor)
self.zoom = new_zoom
Expand Down