From a06d8109f51799edd7bf0da0d95fb3923dde48b0 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 21 Nov 2017 09:44:20 +0300 Subject: [PATCH] refs #1424: custom graphics viewer by request of CEA --- src/GraphicsView/GraphicsView_ViewFrame.cxx | 40 +++++++++++-------- src/GraphicsView/GraphicsView_ViewFrame.h | 8 ++-- src/GraphicsView/GraphicsView_ViewManager.cxx | 6 ++- src/GraphicsView/GraphicsView_ViewManager.h | 3 +- src/GraphicsView/GraphicsView_Viewer.cxx | 7 +++- src/GraphicsView/GraphicsView_Viewer.h | 1 + 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index eebb6c8fb..342778427 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -49,7 +49,7 @@ //======================================================================= GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Viewer* vw, QWidget* w ) : SUIT_ViewWindow( d ), - myViewer( vw ) + myViewer( vw ), myToolBarId( -1 ) { QFrame* aFrame = new QFrame( this ); setCentralWidget( aFrame ); @@ -65,9 +65,6 @@ GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Vi aLayout->addWidget( myViewPort ); - createActions(); - myToolBarId = createToolBar(); - connect( myViewPort, SIGNAL( vpKeyEvent( QKeyEvent* ) ), this, SLOT( keyEvent( QKeyEvent* ) ) ); connect( myViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ), @@ -176,17 +173,19 @@ int GraphicsView_ViewFrame::createToolBar() false ); // disable floatable toolbar toolMgr()->append( DumpId, tid ); - myScaleAction = new QtxMultiAction( this ); - myScaleAction->insertAction( toolMgr()->action( FitAllId ) ); - myScaleAction->insertAction( toolMgr()->action( FitRectId ) ); - myScaleAction->insertAction( toolMgr()->action( FitSelectId ) ); - myScaleAction->insertAction( toolMgr()->action( ZoomId ) ); - toolMgr()->append( myScaleAction, tid ); + QtxMultiAction* aScaleAction = new QtxMultiAction( this ); + aScaleAction->insertAction( toolMgr()->action( FitAllId ) ); + aScaleAction->insertAction( toolMgr()->action( FitRectId ) ); + aScaleAction->insertAction( toolMgr()->action( FitSelectId ) ); + aScaleAction->insertAction( toolMgr()->action( ZoomId ) ); + toolMgr()->append( aScaleAction, tid ); + myScaleAction = aScaleAction; - myPanAction = new QtxMultiAction( this ); - myPanAction->insertAction( toolMgr()->action( PanId ) ); - myPanAction->insertAction( toolMgr()->action( GlobalPanId ) ); - toolMgr()->append( myPanAction, tid ); + QtxMultiAction* aPanAction = new QtxMultiAction( this ); + aPanAction->insertAction( toolMgr()->action( PanId ) ); + aPanAction->insertAction( toolMgr()->action( GlobalPanId ) ); + toolMgr()->append( aPanAction, tid ); + myPanAction = aPanAction; toolMgr()->append( toolMgr()->action( ResetId ), tid ); @@ -270,14 +269,15 @@ void GraphicsView_ViewFrame::setVisualParameters( const QString& theParameters ) //================================================================ void GraphicsView_ViewFrame::expandToolBarActions() { - QList anExpandableActions; + QList anExpandableActions; anExpandableActions.append( myScaleAction ); anExpandableActions.append( myPanAction ); - QListIterator anIter( anExpandableActions ); + QListIterator anIter( anExpandableActions ); while( anIter.hasNext() ) { - if( QtxMultiAction* aMultiAction = anIter.next() ) + QtxMultiAction* aMultiAction = dynamic_cast( anIter.next() ); + if( aMultiAction ) { QList aLocalActions = aMultiAction->actions(); QListIterator aLocalIter( aLocalActions ); @@ -436,6 +436,12 @@ void GraphicsView_ViewFrame::contextMenuEvent( QGraphicsSceneContextMenuEvent* e */ void GraphicsView_ViewFrame::showEvent( QShowEvent* theEvent ) { + if( myToolBarId < 0 ) + { + createActions(); + myToolBarId = createToolBar(); + } + emit Show( theEvent ); } diff --git a/src/GraphicsView/GraphicsView_ViewFrame.h b/src/GraphicsView/GraphicsView_ViewFrame.h index 5969e2dbd..9e2408b7b 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.h +++ b/src/GraphicsView/GraphicsView_ViewFrame.h @@ -28,7 +28,7 @@ class QGraphicsSceneContextMenuEvent; class QGraphicsSceneMouseEvent; class QGraphicsSceneWheelEvent; -class QtxMultiAction; +class QAction; class SUIT_Desktop; @@ -48,7 +48,7 @@ public: public: GraphicsView_ViewFrame( SUIT_Desktop*, GraphicsView_Viewer*, QWidget* w = NULL ); - ~GraphicsView_ViewFrame(); + virtual ~GraphicsView_ViewFrame(); GraphicsView_Viewer* getViewer() const { return myViewer; } GraphicsView_ViewPort* getViewPort() const { return myViewPort; } @@ -104,8 +104,8 @@ private: GraphicsView_ViewPort* myViewPort; int myToolBarId; - QtxMultiAction* myScaleAction; - QtxMultiAction* myPanAction; + QAction* myScaleAction; + QAction* myPanAction; }; #endif diff --git a/src/GraphicsView/GraphicsView_ViewManager.cxx b/src/GraphicsView/GraphicsView_ViewManager.cxx index 4b32e1cc5..562cfb8d0 100644 --- a/src/GraphicsView/GraphicsView_ViewManager.cxx +++ b/src/GraphicsView/GraphicsView_ViewManager.cxx @@ -25,8 +25,10 @@ // Purpose : Constructor //======================================================================= GraphicsView_ViewManager::GraphicsView_ViewManager( SUIT_Study* theStudy, - SUIT_Desktop* theDesktop ) -: SUIT_ViewManager( theStudy, theDesktop, new GraphicsView_Viewer( "GraphicsView" ) ) + SUIT_Desktop* theDesktop, + SUIT_ViewModel* theModel ) +: SUIT_ViewManager( theStudy, theDesktop, + theModel ? theModel : new GraphicsView_Viewer( "GraphicsView" ) ) { setTitle( tr( "GRAPHICS_VIEW_TITLE" ) ); } diff --git a/src/GraphicsView/GraphicsView_ViewManager.h b/src/GraphicsView/GraphicsView_ViewManager.h index 0b7e93b57..64f926b00 100644 --- a/src/GraphicsView/GraphicsView_ViewManager.h +++ b/src/GraphicsView/GraphicsView_ViewManager.h @@ -36,7 +36,8 @@ class GRAPHICSVIEW_API GraphicsView_ViewManager : public SUIT_ViewManager public: GraphicsView_ViewManager( SUIT_Study* theStudy, - SUIT_Desktop* theDesktop ); + SUIT_Desktop* theDesktop, + SUIT_ViewModel* theModel = 0 ); virtual ~GraphicsView_ViewManager(); GraphicsView_Viewer* getViewer(); diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index ddb9b18ee..9b51d0019 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -66,13 +66,18 @@ GraphicsView_Viewer::~GraphicsView_Viewer() delete mySelector; } +GraphicsView_ViewFrame* GraphicsView_Viewer::createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget ) +{ + return new GraphicsView_ViewFrame( theDesktop, this, theWidget ); +} + //================================================================ // Function : createView // Purpose : //================================================================ SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop ) { - GraphicsView_ViewFrame* aViewFrame = new GraphicsView_ViewFrame( theDesktop, this, myWidget ); + GraphicsView_ViewFrame* aViewFrame = createViewFrame( theDesktop, myWidget ); connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ), this, SLOT( onKeyEvent( QKeyEvent* ) ) ); diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index 5ca25eccc..5423eb5e4 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -81,6 +81,7 @@ signals: protected: virtual GraphicsView_ViewTransformer* createTransformer( int ); + virtual GraphicsView_ViewFrame* createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget ); virtual void onTransformationStarted(); virtual void onTransformationFinished(); -- 2.39.2