1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SALOME QxScene : build Supervisor viewer into desktop
22 #include "QxScene_ViewWindow.h"
23 #include "QxScene_Def.h"
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_Session.h>
27 #include <SUIT_Desktop.h>
29 #include <QtxAction.h>
30 #include <QtxMultiAction.h>
31 #include <QtxActionToolMgr.h>
35 #include <QGraphicsRectItem>
38 #include "DebTrace.hxx"
43 QxScene_ViewWindow::QxScene_ViewWindow( SUIT_Desktop* theDesktop, QxScene_Viewer* theModel)
44 : SUIT_ViewWindow( theDesktop )
46 DEBTRACE("Construct QxScene_ViewWindow");
47 myViewModel = theModel;
55 void QxScene_ViewWindow::initLayout()
57 DEBTRACE("QxScene_ViewWindow::initLayout");
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();
72 Creates actions of QxScene view window
74 void QxScene_ViewWindow::createActions()
76 DEBTRACE("QxScene_ViewWindow::createActions");
77 QtxActionToolMgr* mgr = toolMgr();
79 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
81 // 2. Scaling operations
84 aAction = new QtxAction( tr( "MNU_FITALL" ),
85 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_FITALL" ) ),
88 aAction->setStatusTip( tr( "DSC_FITALL" ) );
89 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitAll() ) );
90 mgr->registerAction( aAction, FitAllId );
93 aAction = new QtxAction( tr( "MNU_FITRECT" ),
94 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_FITAREA" ) ),
97 aAction->setStatusTip( tr( "DSC_FITRECT" ) );
98 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitArea() ) );
99 mgr->registerAction( aAction, FitRectId );
102 aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
103 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_ZOOM" ) ),
104 tr( "MNU_ZOOM_VIEW" ),
106 aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
107 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewZoom() ) );
108 mgr->registerAction( aAction, ZoomId );
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 );
117 // 3. Moving operations
120 aAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
121 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_PAN" ) ),
122 tr( "MNU_PAN_VIEW" ),
124 aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
125 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewPan() ) );
126 mgr->registerAction( aAction, PanId );
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" ),
133 aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
134 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewGlobalPan() ) );
135 mgr->registerAction( aAction, GlobalPanId );
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 );
144 aAction = new QtxAction( tr( "MNU_RESET_VIEW" ),
145 aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_RESET" ) ),
146 tr( "MNU_RESET_VIEW" ),
148 aAction->setStatusTip( tr( "DSC_RESET_VIEW" ) );
149 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewReset() ) );
150 mgr->registerAction( aAction, ResetId );
154 Creates toolbar of QxScene view window
156 void QxScene_ViewWindow::createToolBar()
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 );
167 \brief Get view window's toolbar.
170 QToolBar* QxScene_ViewWindow::getToolBar()
172 DEBTRACE("QxScene_ViewWindow::getToolBar");
173 return toolMgr()->toolBar( myToolBar );
179 QxScene_ViewWindow::~QxScene_ViewWindow()
181 DEBTRACE("destructor QxScene_ViewWindow");
186 Reset the active view
188 void QxScene_ViewWindow::onViewReset()
190 DEBTRACE( "QxScene_ViewWindow::onViewReset" );
194 Sets a new center of the active view
196 void QxScene_ViewWindow::onViewGlobalPan()
198 DEBTRACE( "QxScene_ViewWindow::onViewGlobalPan" );
202 Zooms the active view
204 void QxScene_ViewWindow::onViewZoom()
206 DEBTRACE( "QxScene_ViewWindow::onViewZoom" );
210 Moves the active view
212 void QxScene_ViewWindow::onViewPan()
214 DEBTRACE( "QxScene_ViewWindow::onViewPan" );
218 Fits all obejcts within a rectangular area of the active view
220 void QxScene_ViewWindow::onViewFitArea()
222 DEBTRACE( "QxScene_ViewWindow::onViewFitArea" );
226 Fits all objects in the active view
228 void QxScene_ViewWindow::onViewFitAll()
230 DEBTRACE( "QxScene_ViewWindow::onViewFitAll" );
234 Set background of the viewport
236 void QxScene_ViewWindow::setBackgroundColor( const QColor& color )
238 DEBTRACE("QxScene_ViewWindow::setBackgroundColor");
242 Returns background of the viewport
244 QColor QxScene_ViewWindow::backgroundColor() const
246 DEBTRACE("QxScene_ViewWindow::backgroundColor");
252 Custom resize event handler
254 void QxScene_ViewWindow::resizeEvent( QResizeEvent* theEvent )
256 DEBTRACE("QxScene_ViewWindow::resizeEvent");
262 SUIT_ResourceMgr* QxScene_ViewWindow::resMgr() const
264 DEBTRACE("QxScene_ViewWindow::resMgr");
265 return SUIT_Session::session()->resourceMgr();
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.
272 bool QxScene_ViewWindow::closeRequested()
274 DEBTRACE("QxScene_ViewWindow::closeRequested");
275 bool isClosed = true;
276 emit tryClose(isClosed, this);
277 DEBTRACE("isClosed=" << isClosed);