Skip to content

Commit

Permalink
Merge pull request #145 from Bycelium/bug/zoom-level-stuck
Browse files Browse the repository at this point in the history
🪲 Fix zoom stuck bug
  • Loading branch information
MathisFederico authored Jan 9, 2022
2 parents 0828224 + af83b86 commit 3308e8b
Showing 1 changed file with 9 additions and 4 deletions.
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

0 comments on commit 3308e8b

Please sign in to comment.