Salome HOME
Synchronize adm files
[modules/gui.git] / src / QxScene / QxScene_ViewWindow.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SALOME QxScene : build Supervisor viewer into desktop
21 //
22 #include "QxScene_ViewWindow.h"
23 #include "QxScene_Def.h"
24
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_Session.h>
27 #include <SUIT_Desktop.h>
28
29 #include <QtxAction.h>
30 #include <QtxMultiAction.h>
31 #include <QtxActionToolMgr.h>
32
33 //QT Include
34 #include <QToolBar>
35 #include <QGraphicsRectItem>
36
37 //#define _DEVDEBUG_
38 #include "DebTrace.hxx"
39
40 /*!
41     Constructor
42 */
43 QxScene_ViewWindow::QxScene_ViewWindow( SUIT_Desktop* theDesktop, QxScene_Viewer* theModel)
44   : SUIT_ViewWindow( theDesktop )
45 {
46   DEBTRACE("Construct QxScene_ViewWindow");
47   myViewModel = theModel;
48   _scene = 0;
49   _sceneView = 0;
50 }
51
52 /*!
53   Initialization
54 */
55 void QxScene_ViewWindow::initLayout()
56 {
57   DEBTRACE("QxScene_ViewWindow::initLayout");
58   createActions();
59   createToolBar();
60   
61   // --- QGraphics test
62
63 //   _scene = new QGraphicsScene();
64 //   _sceneView = new QGraphicsView(this);
65 //   setCentralWidget(_sceneView);
66 //   _sceneView->setScene(_scene);
67 //   QGraphicsRectItem *rect = _scene->addRect(QRectF(0, 0, 100, 100));
68 //   _sceneView->show();
69 }
70
71 /*!
72   Creates actions of QxScene view window
73 */
74 void QxScene_ViewWindow::createActions()
75 {
76   DEBTRACE("QxScene_ViewWindow::createActions");
77   QtxActionToolMgr* mgr = toolMgr();
78   QtxAction* aAction;
79   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
80
81   // 2. Scaling operations
82
83   // 2.1. Fit All
84   aAction = new QtxAction( tr( "MNU_FITALL" ),
85                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_FITALL" ) ),
86                            tr( "MNU_FITALL" ),
87                            0, this);
88   aAction->setStatusTip( tr( "DSC_FITALL" ) );
89   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitAll() ) );
90   mgr->registerAction( aAction, FitAllId );
91
92   // 2.2. Fit Rect
93   aAction = new QtxAction( tr( "MNU_FITRECT" ),
94                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_FITAREA" ) ),
95                            tr( "MNU_FITRECT" ),
96                            0, this);
97   aAction->setStatusTip( tr( "DSC_FITRECT" ) );
98   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitArea() ) );
99   mgr->registerAction( aAction, FitRectId );
100
101   // 2.3. Zoom
102   aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
103                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_ZOOM" ) ),
104                            tr( "MNU_ZOOM_VIEW" ),
105                            0, this);
106   aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
107   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewZoom() ) );
108   mgr->registerAction( aAction, ZoomId );
109
110   // 2.4. Create multi-action for scaling operations
111   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
112   aScaleAction->insertAction( mgr->action( FitAllId  ) );
113   aScaleAction->insertAction( mgr->action( FitRectId ) );
114   aScaleAction->insertAction( mgr->action( ZoomId    ) );
115   mgr->registerAction( aScaleAction, ScaleOpId );
116
117   // 3. Moving operations
118
119   // 3.1. Panning
120   aAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
121                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_PAN" ) ),
122                            tr( "MNU_PAN_VIEW" ), 
123                            0, this);
124   aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
125   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewPan() ) );
126   mgr->registerAction( aAction, PanId );
127
128   // 3.2. Global Panning
129   aAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
130                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_GLOBALPAN" ) ),
131                            tr( "MNU_GLOBALPAN_VIEW" ),
132                            0, this);
133   aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
134   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewGlobalPan() ) );
135   mgr->registerAction( aAction, GlobalPanId );
136
137   // 3.3. Create multi-action for moving operations
138   QtxMultiAction* aPanAction = new QtxMultiAction( this );
139   aPanAction->insertAction( mgr->action( PanId ) );
140   aPanAction->insertAction( mgr->action( GlobalPanId ) );
141   mgr->registerAction( aPanAction, MoveOpId );
142
143   // reset
144   aAction = new QtxAction( tr( "MNU_RESET_VIEW" ),
145                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_RESET" ) ),
146                            tr( "MNU_RESET_VIEW" ), 
147                            0, this);
148   aAction->setStatusTip( tr( "DSC_RESET_VIEW" ) );
149   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewReset() ) );
150   mgr->registerAction( aAction, ResetId );
151 }
152
153 /*!
154   Creates toolbar of QxScene view window
155 */
156 void QxScene_ViewWindow::createToolBar()
157 {
158   DEBTRACE("QxScene_ViewWindow::createToolBar");
159   QtxActionToolMgr* mgr = toolMgr();
160   myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ), false );
161   mgr->append( ScaleOpId, myToolBar );
162   mgr->append( MoveOpId, myToolBar );
163   mgr->append( ResetId, myToolBar );
164 }
165
166 /*!
167   \brief Get view window's toolbar.
168   \return toolbar
169 */
170 QToolBar* QxScene_ViewWindow::getToolBar()
171 {
172   DEBTRACE("QxScene_ViewWindow::getToolBar");
173   return toolMgr()->toolBar( myToolBar );
174 }
175
176 /*!
177   Destructor
178 */
179 QxScene_ViewWindow::~QxScene_ViewWindow()
180 {
181   DEBTRACE("destructor QxScene_ViewWindow");
182
183 }
184
185 /*!
186   Reset the active view
187 */
188 void QxScene_ViewWindow::onViewReset()    
189 {
190   DEBTRACE( "QxScene_ViewWindow::onViewReset" );
191 }
192
193 /*!
194   Sets a new center of the active view
195 */
196 void QxScene_ViewWindow::onViewGlobalPan()
197 {
198   DEBTRACE( "QxScene_ViewWindow::onViewGlobalPan" );
199 }
200
201 /*!
202   Zooms the active view
203 */
204 void QxScene_ViewWindow::onViewZoom()
205 {
206   DEBTRACE( "QxScene_ViewWindow::onViewZoom" );
207 }
208
209 /*!
210   Moves the active view
211 */
212 void QxScene_ViewWindow::onViewPan()
213 {
214   DEBTRACE( "QxScene_ViewWindow::onViewPan" );
215 }
216
217 /*!
218   Fits all obejcts within a rectangular area of the active view
219 */
220 void QxScene_ViewWindow::onViewFitArea()
221 {
222   DEBTRACE( "QxScene_ViewWindow::onViewFitArea" );
223 }
224
225 /*!
226   Fits all objects in the active view
227 */
228 void QxScene_ViewWindow::onViewFitAll()
229 {
230   DEBTRACE( "QxScene_ViewWindow::onViewFitAll" );
231 }
232
233 /*!
234     Set background of the viewport
235 */
236 void QxScene_ViewWindow::setBackgroundColor( const QColor& color )
237 {
238   DEBTRACE("QxScene_ViewWindow::setBackgroundColor");
239 }
240
241 /*!
242     Returns background of the viewport
243 */
244 QColor QxScene_ViewWindow::backgroundColor() const
245 {
246   DEBTRACE("QxScene_ViewWindow::backgroundColor");
247   QColor col;
248   return col;
249 }
250
251 /*!
252   Custom resize event handler
253 */
254 void QxScene_ViewWindow::resizeEvent( QResizeEvent* theEvent )
255 {
256   DEBTRACE("QxScene_ViewWindow::resizeEvent");
257 }
258
259 /*!
260   Get resource manager
261 */
262 SUIT_ResourceMgr* QxScene_ViewWindow::resMgr() const
263
264   DEBTRACE("QxScene_ViewWindow::resMgr");
265   return SUIT_Session::session()->resourceMgr(); 
266 }
267
268 /*!
269  *  emits a signal to ask to close the schema associated to the window.
270  *  A boolean in return indicates if it is OK to close.
271  */
272 bool QxScene_ViewWindow::closeRequested()
273 {
274   DEBTRACE("QxScene_ViewWindow::closeRequested");
275   bool isClosed = true;
276   emit tryClose(isClosed, this);
277   DEBTRACE("isClosed=" << isClosed);
278   return isClosed;
279 }