From fc81102714b298bd8cf042153f5d2b85c683f2ea Mon Sep 17 00:00:00 2001 From: mpa Date: Wed, 11 Jun 2014 11:06:57 +0400 Subject: [PATCH] add zoom action when wheel is spinning --- src/DependencyTree/DependencyTree_View.cxx | 18 ++++++++++++++++++ src/DependencyTree/DependencyTree_View.h | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/DependencyTree/DependencyTree_View.cxx b/src/DependencyTree/DependencyTree_View.cxx index 24d9abae3..884446e6e 100644 --- a/src/DependencyTree/DependencyTree_View.cxx +++ b/src/DependencyTree/DependencyTree_View.cxx @@ -36,6 +36,7 @@ // Qt includes #include #include +#include DependencyTree_View::DependencyTree_View( QWidget* theParent ) :GraphicsView_ViewPort( theParent ), @@ -156,6 +157,23 @@ void DependencyTree_View::mouseMoveEvent( QMouseEvent *event ) } } +//================================================================================= +// function : wheelEvent() +// purpose : add zoom action when wheel is spinning +//================================================================================= +void DependencyTree_View::wheelEvent( QWheelEvent* event ) +{ + int inc = 10; // zoom coefficient + double cx = width() / 2; + double cy = height() / 2; + if( event->delta() > 0 ) + zoom( cx, cy, cx + inc, cy + inc ); + else + zoom( cx, cy, cx - inc, cy - inc ); + + QGraphicsView::wheelEvent( event ); +} + //================================================================================= // function : getViewName() // purpose : return the name of current view diff --git a/src/DependencyTree/DependencyTree_View.h b/src/DependencyTree/DependencyTree_View.h index 29d16bae5..6c606d401 100644 --- a/src/DependencyTree/DependencyTree_View.h +++ b/src/DependencyTree/DependencyTree_View.h @@ -54,7 +54,8 @@ public: void init( GraphicsView_ViewFrame* ); void updateModel( bool = true, bool = true ); - void mouseMoveEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent* event); + void wheelEvent( QWheelEvent* event ); QString getViewName() const; int getStudyId() const; -- 2.39.2