From 167d2b6ee52255f804a0f37b254210b04b8ce0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20H=C3=A9riveaux?= Date: Thu, 25 Jul 2024 10:03:27 +0200 Subject: [PATCH 1/2] Don't zoom at cursor when following stage --- laserstudio/widgets/viewer.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/laserstudio/widgets/viewer.py b/laserstudio/widgets/viewer.py index c758574..8404d6b 100644 --- a/laserstudio/widgets/viewer.py +++ b/laserstudio/widgets/viewer.py @@ -298,27 +298,27 @@ def wheelEvent(self, event: Optional[QWheelEvent]): """ if event is None: return - # We want to zoom relative to the current cursor position, not relative - # to the center of the widget. This involves some math... - # p is the pointed position in the scene, and we want to keep p at the - # same screen position after changing the zoom. If c1 and c2 are the - # camera positions before and after the zoom changes, - # z1 and z2 the zoom levels, then we want: - # z1 * (p - c1) = z2 * (p - c2) - # which gives: - # c2 = c1 * (z1/z2) + p * (1 - z1/z2) - # we can use zr = z2/z1, the zoom factor to apply. - - # The pointed position - p = self.mapToScene(event.position().toPoint()) - + # Get current position and zoom factor of camera + pos, zoom = self.cam_pos_zoom # The zoom factor to apply zr = 2 ** (event.angleDelta().y() / (8 * 120)) - # Get current position and zoom factor of camera - pos, zoom = self.cam_pos_zoom + if not self._follow_stage_sight: + # We want to zoom relative to the current cursor position, not relative + # to the center of the widget. This involves some math... + # p is the pointed position in the scene, and we want to keep p at the + # same screen position after changing the zoom. If c1 and c2 are the + # camera positions before and after the zoom changes, + # z1 and z2 the zoom levels, then we want: + # z1 * (p - c1) = z2 * (p - c2) + # which gives: + # c2 = c1 * (z1/z2) + p * (1 - z1/z2) + # we can use zr = z2/z1, the zoom factor to apply. + + # The pointed position + p = self.mapToScene(event.position().toPoint()) + pos = (pos / zr) + (p * (1 - (1 / zr))) - pos = (pos / zr) + (p * (1 - (1 / zr))) zoom *= zr # Update the position and zoom factors From 40b6ab48aa389bff04f2f98edb530f5b5f467854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20H=C3=A9riveaux?= Date: Thu, 25 Jul 2024 10:28:45 +0200 Subject: [PATCH 2/2] Disable pan when camera tracking is on --- laserstudio/widgets/viewer.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/laserstudio/widgets/viewer.py b/laserstudio/widgets/viewer.py index 8404d6b..2437834 100644 --- a/laserstudio/widgets/viewer.py +++ b/laserstudio/widgets/viewer.py @@ -347,18 +347,19 @@ def mousePressEvent(self, event: Optional[QMouseEvent]): # The event is a press of the right button if event.button() == Qt.MouseButton.RightButton: - # Scroll gesture mode - self.setDragMode(Viewer.DragMode.ScrollHandDrag) - # Transform as left press button event, - # to make the scroll by dragging actually effective. - event = QMouseEvent( - event.type(), - event.position(), - Qt.MouseButton.LeftButton, - event.buttons(), - event.modifiers(), - event.pointingDevice(), - ) + if not self._follow_stage_sight: + # Scroll gesture mode + self.setDragMode(Viewer.DragMode.ScrollHandDrag) + # Transform as left press button event, + # to make the scroll by dragging actually effective. + event = QMouseEvent( + event.type(), + event.position(), + Qt.MouseButton.LeftButton, + event.buttons(), + event.modifiers(), + event.pointingDevice(), + ) super().mousePressEvent(event)