1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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" ), // 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 );
169 \brief Get view window's toolbar.
172 QToolBar* QxScene_ViewWindow::getToolBar()
174 DEBTRACE("QxScene_ViewWindow::getToolBar");
175 return toolMgr()->toolBar( myToolBar );
181 QxScene_ViewWindow::~QxScene_ViewWindow()
183 DEBTRACE("destructor QxScene_ViewWindow");
188 Reset the active view
190 void QxScene_ViewWindow::onViewReset()
192 DEBTRACE( "QxScene_ViewWindow::onViewReset" );
196 Sets a new center of the active view
198 void QxScene_ViewWindow::onViewGlobalPan()
200 DEBTRACE( "QxScene_ViewWindow::onViewGlobalPan" );
204 Zooms the active view
206 void QxScene_ViewWindow::onViewZoom()
208 DEBTRACE( "QxScene_ViewWindow::onViewZoom" );
212 Moves the active view
214 void QxScene_ViewWindow::onViewPan()
216 DEBTRACE( "QxScene_ViewWindow::onViewPan" );
220 Fits all obejcts within a rectangular area of the active view
222 void QxScene_ViewWindow::onViewFitArea()
224 DEBTRACE( "QxScene_ViewWindow::onViewFitArea" );
228 Fits all objects in the active view
230 void QxScene_ViewWindow::onViewFitAll()
232 DEBTRACE( "QxScene_ViewWindow::onViewFitAll" );
236 Set background of the viewport
238 void QxScene_ViewWindow::setBackgroundColor( const QColor& color )
240 DEBTRACE("QxScene_ViewWindow::setBackgroundColor");
244 Returns background of the viewport
246 QColor QxScene_ViewWindow::backgroundColor() const
248 DEBTRACE("QxScene_ViewWindow::backgroundColor");
254 Custom resize event handler
256 void QxScene_ViewWindow::resizeEvent( QResizeEvent* theEvent )
258 DEBTRACE("QxScene_ViewWindow::resizeEvent");
264 SUIT_ResourceMgr* QxScene_ViewWindow::resMgr() const
266 DEBTRACE("QxScene_ViewWindow::resMgr");
267 return SUIT_Session::session()->resourceMgr();
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.
274 bool QxScene_ViewWindow::closeRequested()
276 DEBTRACE("QxScene_ViewWindow::closeRequested");
277 bool isClosed = true;
278 emit tryClose(isClosed, this);
279 DEBTRACE("isClosed=" << isClosed);