From: ouv Date: Mon, 20 Dec 2010 13:59:59 +0000 (+0000) Subject: Handling wheel events to control longitudial and lateral scale of the presentation... X-Git-Tag: DIAGRAM_0_1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6dab1f2687c9db6e72f023e694c05ac8f99d7a16;p=modules%2Fgui.git Handling wheel events to control longitudial and lateral scale of the presentation objects. --- diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h index 7998b4d3e..7cb2a18c1 100644 --- a/src/GraphicsView/GraphicsView_Object.h +++ b/src/GraphicsView/GraphicsView_Object.h @@ -61,6 +61,8 @@ public: virtual bool isMovingByXAllowed( double theDX ) { return true; } virtual bool isMovingByYAllowed( double theDY ) { return true; } + virtual bool updateScale( bool theIsScaleUp, bool theIsCtrl ) { return false; } + virtual QRectF getPullingRect() const { return getRect(); } virtual bool portContains( const QPointF& ) { return false; } virtual bool startPulling( const QPointF& ) { return false; } diff --git a/src/GraphicsView/GraphicsView_Scene.cxx b/src/GraphicsView/GraphicsView_Scene.cxx index 2b66a218c..42d50ed4a 100644 --- a/src/GraphicsView/GraphicsView_Scene.cxx +++ b/src/GraphicsView/GraphicsView_Scene.cxx @@ -79,6 +79,21 @@ void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e ) QGraphicsScene::mouseDoubleClickEvent( e ); } +//================================================================ +// Function : wheelEvent +// Purpose : +//================================================================ +void GraphicsView_Scene::wheelEvent( QGraphicsSceneWheelEvent* e ) +{ + emit gsWheelEvent( e ); + + // accept the event to prevent calling QAbstractScrollArea::wheelEvent() + // from QGraphicsView::wheelEvent(), which will change values of scroll-bars + e->accept(); + + //QGraphicsScene::wheelEvent( e ); // don't uncomment +} + //================================================================ // Function : contextMenuEvent // Purpose : diff --git a/src/GraphicsView/GraphicsView_Scene.h b/src/GraphicsView/GraphicsView_Scene.h index d949cdf60..e67cd8bfc 100644 --- a/src/GraphicsView/GraphicsView_Scene.h +++ b/src/GraphicsView/GraphicsView_Scene.h @@ -44,6 +44,7 @@ protected: virtual void mouseMoveEvent( QGraphicsSceneMouseEvent* ); virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* ); virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* ); + virtual void wheelEvent( QGraphicsSceneWheelEvent* ); virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* ); virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* ); diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index c04eabbd8..77df4f75a 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -288,7 +288,7 @@ void GraphicsView_ViewFrame::wheelEvent( QGraphicsSceneWheelEvent* e ) { switch ( e->type() ) { - case QEvent::Wheel: + case QEvent::GraphicsSceneWheel: emit wheeling( e ); break; default: diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index d09ed715a..a7da60b45 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -22,6 +22,7 @@ #include "GraphicsView_Viewer.h" +#include "GraphicsView_Object.h" #include "GraphicsView_Selector.h" #include "GraphicsView_Scene.h" #include "GraphicsView_ViewFrame.h" @@ -258,7 +259,7 @@ void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e ) { switch( e->type() ) { - case QEvent::Wheel: + case QEvent::GraphicsSceneWheel: handleWheel( e ); break; default: break; @@ -308,13 +309,16 @@ void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e ) void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e ) { // selection - if( e->button() == Qt::LeftButton && - !( getActiveViewPort()->currentBlock() & GraphicsView_ViewPort::BS_Selection ) ) + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) { - if ( getSelector() ) + if( e->button() == Qt::LeftButton && + !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) ) { - bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); - getSelector()->select( QRectF(), append ); + if ( getSelector() ) + { + bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); + getSelector()->select( QRectF(), append ); + } } } @@ -378,6 +382,8 @@ void GraphicsView_Viewer::onSelectionCancel() void GraphicsView_Viewer::startOperations( QGraphicsSceneMouseEvent* e ) { GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + if( !aViewPort ) + return; // If the 'immediate selection' mode is enabled, // try to perform selection before invoking context menu @@ -417,6 +423,8 @@ void GraphicsView_Viewer::startOperations( QGraphicsSceneMouseEvent* e ) bool GraphicsView_Viewer::updateOperations( QGraphicsSceneMouseEvent* e ) { GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + if( !aViewPort ) + return false; if( aViewPort->isPulling() ) { @@ -449,6 +457,8 @@ bool GraphicsView_Viewer::updateOperations( QGraphicsSceneMouseEvent* e ) bool GraphicsView_Viewer::finishOperations( QGraphicsSceneMouseEvent* e ) { GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + if( !aViewPort ) + return false; if( aViewPort->isPulling() ) { @@ -474,3 +484,25 @@ bool GraphicsView_Viewer::finishOperations( QGraphicsSceneMouseEvent* e ) return false; } + +//================================================================ +// Function : startOperations +// Purpose : +//================================================================ +void GraphicsView_Viewer::startOperations( QGraphicsSceneWheelEvent* e ) +{ + GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + if( !aViewPort ) + return; + + bool anIsScaleUp = e->delta() > 0; + bool anIsCtrl = e->modifiers() & Qt::ControlModifier; + + bool anIsScaleChanged = false; + for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() ) + if( GraphicsView_Object* anObject = aViewPort->selectedObject() ) + anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged; + + if( anIsScaleChanged ) + emit wheelScaleChanged(); +} diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index f6d70147e..4fb7943cc 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -80,6 +80,7 @@ public: signals: void selectionChanged( GV_SelectionChangeStatus ); + void wheelScaleChanged(); protected: virtual GraphicsView_ViewTransformer* createTransformer( int ); @@ -90,7 +91,7 @@ protected: virtual void startOperations( QGraphicsSceneMouseEvent* ); virtual bool updateOperations( QGraphicsSceneMouseEvent* ); virtual bool finishOperations( QGraphicsSceneMouseEvent* ); - virtual void startOperations( QGraphicsSceneWheelEvent* ) {} + virtual void startOperations( QGraphicsSceneWheelEvent* ); protected slots: virtual void onMouseEvent( QGraphicsSceneMouseEvent* );