From e70cecef3e012f242dbee080e67e99e8bf4ece2a Mon Sep 17 00:00:00 2001 From: Sverre Briseid Date: Sat, 23 Nov 2024 10:29:52 +0100 Subject: [PATCH] Enabled support for using scrool wheel to zoom. --- viewlib/include/GoTools/viewlib/gvView.h | 2 ++ viewlib/src/gvView.C | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/viewlib/include/GoTools/viewlib/gvView.h b/viewlib/include/GoTools/viewlib/gvView.h index 53ee55ca..41e1e5ae 100644 --- a/viewlib/include/GoTools/viewlib/gvView.h +++ b/viewlib/include/GoTools/viewlib/gvView.h @@ -199,6 +199,8 @@ public slots: /// zoom and rotate the camera. virtual void mouseMoveEvent(QMouseEvent* e); + virtual void wheelEvent(QWheelEvent* e); + virtual bool get3Dpoint(int mousex, int mousey, Vector3D &objpt); void drawOverlay(); diff --git a/viewlib/src/gvView.C b/viewlib/src/gvView.C index de795003..ef5d26d9 100644 --- a/viewlib/src/gvView.C +++ b/viewlib/src/gvView.C @@ -967,6 +967,24 @@ void gvView::mouseMoveEvent(QMouseEvent* e) updateGL(); } + +//=========================================================================== +void gvView::wheelEvent(QWheelEvent* e) +//=========================================================================== +{ + // Zoom the scene with scroll wheel + double dist = 0.0; + camera_.getDistance(dist); + + // Get the delta of the wheel, and adjust the zoom factor + int delta = -e->angleDelta().y(); // y() is typically used for vertical scrolling + double zoomFactor = 1.0 - 0.001 * delta; // Adjust the zoom speed to your preference + + camera_.setDistance(dist * zoomFactor); + + updateGL(); +} + //=========================================================================== void gvView::focusOnBox() //===========================================================================