Salome HOME
Updated copyright comment
[modules/gui.git] / src / QxScene / QxScene_ViewWindow.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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" ),          // title (language-dependant)
161                                   QString( "QxSceneViewOperations" ), // name (language-independant)
162                                   false );                            // disable floatable toolbar
163   mgr->append( ScaleOpId, myToolBar );
164   mgr->append( MoveOpId, myToolBar );
165   mgr->append( ResetId, myToolBar );
166 }
167
168 /*!
169   \brief Get view window's toolbar.
170   \return toolbar
171 */
172 QToolBar* QxScene_ViewWindow::getToolBar()
173 {
174   DEBTRACE("QxScene_ViewWindow::getToolBar");
175   return toolMgr()->toolBar( myToolBar );
176 }
177
178 /*!
179   Destructor
180 */
181 QxScene_ViewWindow::~QxScene_ViewWindow()
182 {
183   DEBTRACE("destructor QxScene_ViewWindow");
184
185 }
186
187 /*!
188   Reset the active view
189 */
190 void QxScene_ViewWindow::onViewReset()    
191 {
192   DEBTRACE( "QxScene_ViewWindow::onViewReset" );
193 }
194
195 /*!
196   Sets a new center of the active view
197 */
198 void QxScene_ViewWindow::onViewGlobalPan()
199 {
200   DEBTRACE( "QxScene_ViewWindow::onViewGlobalPan" );
201 }
202
203 /*!
204   Zooms the active view
205 */
206 void QxScene_ViewWindow::onViewZoom()
207 {
208   DEBTRACE( "QxScene_ViewWindow::onViewZoom" );
209 }
210
211 /*!
212   Moves the active view
213 */
214 void QxScene_ViewWindow::onViewPan()
215 {
216   DEBTRACE( "QxScene_ViewWindow::onViewPan" );
217 }
218
219 /*!
220   Fits all obejcts within a rectangular area of the active view
221 */
222 void QxScene_ViewWindow::onViewFitArea()
223 {
224   DEBTRACE( "QxScene_ViewWindow::onViewFitArea" );
225 }
226
227 /*!
228   Fits all objects in the active view
229 */
230 void QxScene_ViewWindow::onViewFitAll()
231 {
232   DEBTRACE( "QxScene_ViewWindow::onViewFitAll" );
233 }
234
235 /*!
236     Set background of the viewport
237 */
238 void QxScene_ViewWindow::setBackgroundColor( const QColor& /*color*/ )
239 {
240   DEBTRACE("QxScene_ViewWindow::setBackgroundColor");
241 }
242
243 /*!
244     Returns background of the viewport
245 */
246 QColor QxScene_ViewWindow::backgroundColor() const
247 {
248   DEBTRACE("QxScene_ViewWindow::backgroundColor");
249   QColor col;
250   return col;
251 }
252
253 /*!
254   Custom resize event handler
255 */
256 void QxScene_ViewWindow::resizeEvent( QResizeEvent* /*theEvent*/ )
257 {
258   DEBTRACE("QxScene_ViewWindow::resizeEvent");
259 }
260
261 /*!
262   Get resource manager
263 */
264 SUIT_ResourceMgr* QxScene_ViewWindow::resMgr() const
265
266   DEBTRACE("QxScene_ViewWindow::resMgr");
267   return SUIT_Session::session()->resourceMgr(); 
268 }
269
270 /*!
271  *  emits a signal to ask to close the schema associated to the window.
272  *  A boolean in return indicates if it is OK to close.
273  */
274 bool QxScene_ViewWindow::closeRequested()
275 {
276   DEBTRACE("QxScene_ViewWindow::closeRequested");
277   bool isClosed = true;
278   emit tryClose(isClosed, this);
279   DEBTRACE("isClosed=" << isClosed);
280   return isClosed;
281 }