1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME QxScene : build Supervisor viewer into desktop
24 #include "QxScene_ViewWindow.h"
25 #include "QxScene_Def.h"
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_Session.h>
29 #include <SUIT_Desktop.h>
31 #include <QtxAction.h>
32 #include <QtxMultiAction.h>
33 #include <QtxActionToolMgr.h>
37 #include <QGraphicsRectItem>
40 #include "DebTrace.hxx"
47 QxScene_ViewWindow::QxScene_ViewWindow( SUIT_Desktop* theDesktop, QxScene_Viewer* theModel)
48 : SUIT_ViewWindow( theDesktop )
50 DEBTRACE("Construct QxScene_ViewWindow");
51 myViewModel = theModel;
59 void QxScene_ViewWindow::initLayout()
61 DEBTRACE("QxScene_ViewWindow::initLayout");
67 // _scene = new QGraphicsScene();
68 // _sceneView = new QGraphicsView(this);
69 // setCentralWidget(_sceneView);
70 // _sceneView->setScene(_scene);
71 // QGraphicsRectItem *rect = _scene->addRect(QRectF(0, 0, 100, 100));
72 // _sceneView->show();
76 Creates actions of QxScene view window
78 void QxScene_ViewWindow::createActions()
80 DEBTRACE("QxScene_ViewWindow::createActions");
81 QtxActionToolMgr* mgr = toolMgr();
83 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
85 // 2. Scaling operations
88 aAction = new QtxAction( tr( "MNU_FITALL" ),
89 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_FITALL" ) ),
92 aAction->setStatusTip( tr( "DSC_FITALL" ) );
93 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitAll() ) );
94 mgr->registerAction( aAction, FitAllId );
97 aAction = new QtxAction( tr( "MNU_FITRECT" ),
98 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_FITAREA" ) ),
101 aAction->setStatusTip( tr( "DSC_FITRECT" ) );
102 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitArea() ) );
103 mgr->registerAction( aAction, FitRectId );
106 aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
107 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_ZOOM" ) ),
108 tr( "MNU_ZOOM_VIEW" ),
110 aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
111 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewZoom() ) );
112 mgr->registerAction( aAction, ZoomId );
114 // 2.4. Create multi-action for scaling operations
115 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
116 aScaleAction->insertAction( mgr->action( FitAllId ) );
117 aScaleAction->insertAction( mgr->action( FitRectId ) );
118 aScaleAction->insertAction( mgr->action( ZoomId ) );
119 mgr->registerAction( aScaleAction, ScaleOpId );
121 // 3. Moving operations
124 aAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
125 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_PAN" ) ),
126 tr( "MNU_PAN_VIEW" ),
128 aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
129 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewPan() ) );
130 mgr->registerAction( aAction, PanId );
132 // 3.2. Global Panning
133 aAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
134 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_GLOBALPAN" ) ),
135 tr( "MNU_GLOBALPAN_VIEW" ),
137 aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
138 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewGlobalPan() ) );
139 mgr->registerAction( aAction, GlobalPanId );
141 // 3.3. Create multi-action for moving operations
142 QtxMultiAction* aPanAction = new QtxMultiAction( this );
143 aPanAction->insertAction( mgr->action( PanId ) );
144 aPanAction->insertAction( mgr->action( GlobalPanId ) );
145 mgr->registerAction( aPanAction, MoveOpId );
148 aAction = new QtxAction( tr( "MNU_RESET_VIEW" ),
149 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_RESET" ) ),
150 tr( "MNU_RESET_VIEW" ),
152 aAction->setStatusTip( tr( "DSC_RESET_VIEW" ) );
153 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewReset() ) );
154 mgr->registerAction( aAction, ResetId );
158 Creates toolbar of QxScene view window
160 void QxScene_ViewWindow::createToolBar()
162 DEBTRACE("QxScene_ViewWindow::createToolBar");
163 QtxActionToolMgr* mgr = toolMgr();
164 myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ) );
165 mgr->append( ScaleOpId, myToolBar );
166 mgr->append( MoveOpId, myToolBar );
167 mgr->append( ResetId, myToolBar );
171 \brief Get view window's toolbar.
174 QToolBar* QxScene_ViewWindow::getToolBar()
176 DEBTRACE("QxScene_ViewWindow::getToolBar");
177 return toolMgr()->toolBar( myToolBar );
183 QxScene_ViewWindow::~QxScene_ViewWindow()
185 DEBTRACE("destructor QxScene_ViewWindow");
190 Reset the active view
192 void QxScene_ViewWindow::onViewReset()
194 DEBTRACE( "QxScene_ViewWindow::onViewReset" );
198 Sets a new center of the active view
200 void QxScene_ViewWindow::onViewGlobalPan()
202 DEBTRACE( "QxScene_ViewWindow::onViewGlobalPan" );
206 Zooms the active view
208 void QxScene_ViewWindow::onViewZoom()
210 DEBTRACE( "QxScene_ViewWindow::onViewZoom" );
214 Moves the active view
216 void QxScene_ViewWindow::onViewPan()
218 DEBTRACE( "QxScene_ViewWindow::onViewPan" );
222 Fits all obejcts within a rectangular area of the active view
224 void QxScene_ViewWindow::onViewFitArea()
226 DEBTRACE( "QxScene_ViewWindow::onViewFitArea" );
230 Fits all objects in the active view
232 void QxScene_ViewWindow::onViewFitAll()
234 DEBTRACE( "QxScene_ViewWindow::onViewFitAll" );
238 Set background of the viewport
240 void QxScene_ViewWindow::setBackgroundColor( const QColor& color )
242 DEBTRACE("QxScene_ViewWindow::setBackgroundColor");
246 Returns background of the viewport
248 QColor QxScene_ViewWindow::backgroundColor() const
250 DEBTRACE("QxScene_ViewWindow::backgroundColor");
256 Custom resize event handler
258 void QxScene_ViewWindow::resizeEvent( QResizeEvent* theEvent )
260 DEBTRACE("QxScene_ViewWindow::resizeEvent");
266 SUIT_ResourceMgr* QxScene_ViewWindow::resMgr() const
268 DEBTRACE("QxScene_ViewWindow::resMgr");
269 return SUIT_Session::session()->resourceMgr();
273 * emits a signal to ask to close the schema associated to the window.
274 * A boolean in return indicates if it is OK to close.
276 bool QxScene_ViewWindow::closeRequested()
278 DEBTRACE("QxScene_ViewWindow::closeRequested");
279 bool isClosed = false;
280 emit tryClose(isClosed, this);
281 DEBTRACE("isClosed=" << isClosed);