]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
refs #1424: custom graphics viewer by request of CEA
authorasl <asl@opencascade.com>
Tue, 21 Nov 2017 06:44:20 +0000 (09:44 +0300)
committerasl <asl@opencascade.com>
Tue, 21 Nov 2017 06:44:20 +0000 (09:44 +0300)
src/GraphicsView/GraphicsView_ViewFrame.cxx
src/GraphicsView/GraphicsView_ViewFrame.h
src/GraphicsView/GraphicsView_ViewManager.cxx
src/GraphicsView/GraphicsView_ViewManager.h
src/GraphicsView/GraphicsView_Viewer.cxx
src/GraphicsView/GraphicsView_Viewer.h

index eebb6c8fb87ed43bd9056b44754ff9ba811d96f2..342778427e68c2b27892fd012ad0b0b7a8479e57 100644 (file)
@@ -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<QtxMultiAction*> anExpandableActions;
+  QList<QAction*> anExpandableActions;
   anExpandableActions.append( myScaleAction );
   anExpandableActions.append( myPanAction );
 
-  QListIterator<QtxMultiAction*> anIter( anExpandableActions );
+  QListIterator<QAction*> anIter( anExpandableActions );
   while( anIter.hasNext() )
   {
-    if( QtxMultiAction* aMultiAction = anIter.next() )
+    QtxMultiAction* aMultiAction = dynamic_cast<QtxMultiAction*>( anIter.next() );
+    if( aMultiAction )
     {
       QList<QAction*> aLocalActions = aMultiAction->actions();
       QListIterator<QAction*> 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 );
 }
 
index 5969e2dbd3020d734d35accdd69d7cdb658a4fa2..9e2408b7b84eca994a7d3b78bef2cb9dc03fe225 100644 (file)
@@ -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
index 4b32e1cc5118c9e87477794471c367ac857c12b6..562cfb8d0730a55effd0c555ee7ce59c11490ee9 100644 (file)
 // 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" ) );
 }
index 0b7e93b57111c3217a77dc12dc83fa8619b7598a..64f926b0067efb80cdce65ae0e795f78a40df686 100644 (file)
@@ -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();
index ddb9b18ee76eb74250d1793f2bfc1c5766c09611..9b51d00190055ac75bd399b2dea08ca93250fc07 100644 (file)
@@ -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* ) ) );
index 5ca25ecccca2d86c7b1c4d8110a3b524262d882c..5423eb5e43b1b263f63a5a1a4aaaf43d56ebcd68 100644 (file)
@@ -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();