1 // Copyright (C) 2007-2013 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
23 // SALOME QxGraph : build Supervisor viewer into desktop
25 #include "QxGraph_ViewWindow.h"
26 #include "QxGraph_Def.h"
27 #include "QxGraph_Canvas.h"
28 #include "QxGraph_CanvasView.h"
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ToolButton.h>
41 QxGraph_ViewWindow::QxGraph_ViewWindow( SUIT_Desktop* theDesktop, QxGraph_Viewer* theModel)
42 : SUIT_ViewWindow( theDesktop )
44 printf("Construct QxGraph_ViewWindow\n");
45 myViewModel = theModel;
51 void QxGraph_ViewWindow::initLayout()
56 myToolBar = new QToolBar(this);
57 myToolBar->setCloseMode(QDockWindow::Undocked);
58 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
66 void QxGraph_ViewWindow::initCanvas()
69 myViewModel->setCanvas( new QxGraph_Canvas(resMgr()) );
70 //myViewModel->addCanvas( new QxGraph_Canvas(resMgr()) );
74 Canvas views initialization
76 void QxGraph_ViewWindow::initCanvasViews()
80 for (int i = 0; i < 2; i++)
82 //QxGraph_Canvas* aCanvas = new QxGraph_Canvas(resMgr());
83 //myViewModel->addCanvas( aCanvas );
85 QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
86 //QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( aCanvas, this );
87 myViewModel->addView(aCanvasView);
92 // the first view is shown and is the current
93 myViewModel->getCanvasViews().first()->show();
94 myViewModel->setCurrentView( myViewModel->getCanvasViews().first() );
96 /* test for 1 view -->
97 QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
98 myViewModel->addView(aCanvasView);
99 myViewModel->setCurrentView(aCanvasView);
100 test for 1 view <-- */
102 setCentralWidget( myViewModel->getCurrentView() );
104 /*if ( inherits( "QMainWindow" ) ) {
106 ( ( QMainWindow* )this )->setCentralWidget( myViewModel->getCurrentView() );
110 QBoxLayout* layout = new QVBoxLayout( this );
111 layout->addWidget( myViewModel->getCurrentView() );
117 Creates actions of QxGraph view window
119 void QxGraph_ViewWindow::createActions()
121 if (!myActionsMap.isEmpty()) return;
122 SUIT_ResourceMgr* aResMgr = resMgr();
126 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITALL" ) ),
127 tr( "MNU_FITALL" ), 0, this);
128 aAction->setStatusTip(tr("DSC_FITALL"));
129 connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitAll()));
130 myActionsMap[ FitAllId ] = aAction;
133 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITAREA" ) ),
134 tr( "MNU_FITRECT" ), 0, this);
135 aAction->setStatusTip(tr("DSC_FITRECT"));
136 connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitArea()));
137 myActionsMap[ FitRectId ] = aAction;
140 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_ZOOM" ) ),
141 tr( "MNU_ZOOM_VIEW" ), 0, this);
142 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
143 connect(aAction, SIGNAL(activated()), this, SLOT(onViewZoom()));
144 myActionsMap[ ZoomId ] = aAction;
147 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_PAN" ) ),
148 tr( "MNU_PAN_VIEW" ), 0, this);
149 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
150 connect(aAction, SIGNAL(activated()), this, SLOT(onViewPan()));
151 myActionsMap[ PanId ] = aAction;
154 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_GLOBALPAN" ) ),
155 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
156 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
157 connect(aAction, SIGNAL(activated()), this, SLOT(onViewGlobalPan()));
158 myActionsMap[ GlobalPanId ] = aAction;
161 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_RESET" ) ),
162 tr( "MNU_RESET_VIEW" ), 0, this);
163 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
164 connect(aAction, SIGNAL(activated()), this, SLOT(onViewReset()));
165 myActionsMap[ ResetId ] = aAction;
169 Creates toolbar of QxGraph view window
171 void QxGraph_ViewWindow::createToolBar()
173 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
174 aScaleBtn->AddAction(myActionsMap[FitAllId]);
175 aScaleBtn->AddAction(myActionsMap[FitRectId]);
176 aScaleBtn->AddAction(myActionsMap[ZoomId]);
178 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
179 aPanningBtn->AddAction(myActionsMap[PanId]);
180 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
182 myActionsMap[ResetId]->addTo(myToolBar);
188 QxGraph_ViewWindow::~QxGraph_ViewWindow() {}
191 Reset the active view
193 void QxGraph_ViewWindow::onViewReset()
195 printf( "QxGraph_ViewWindow::onViewReset\n" );
196 if ( myViewModel && myViewModel->getCurrentView() )
197 myViewModel->getCurrentView()->activateReset();
201 Sets a new center of the active view
203 void QxGraph_ViewWindow::onViewGlobalPan()
205 printf( "QxGraph_ViewWindow::onViewGlobalPan\n" );
206 if ( myViewModel && myViewModel->getCurrentView() )
207 myViewModel->getCurrentView()->activateGlobalPanning();
211 Zooms the active view
213 void QxGraph_ViewWindow::onViewZoom()
215 printf( "QxGraph_ViewWindow::onViewZoom\n" );
216 if ( myViewModel && myViewModel->getCurrentView() )
217 myViewModel->getCurrentView()->activateZoom();
221 Moves the active view
223 void QxGraph_ViewWindow::onViewPan()
225 printf( "QxGraph_ViewWindow::onViewPan\n" );
226 if ( myViewModel && myViewModel->getCurrentView() )
227 myViewModel->getCurrentView()->activatePanning();
231 Fits all obejcts within a rectangular area of the active view
233 void QxGraph_ViewWindow::onViewFitArea()
235 printf( "QxGraph_ViewWindow::onViewFitArea\n" );
236 if ( myViewModel && myViewModel->getCurrentView() )
237 myViewModel->getCurrentView()->activateFitRect();
241 Fits all objects in the active view
243 void QxGraph_ViewWindow::onViewFitAll()
245 printf( "QxGraph_ViewWindow::onViewFitAll\n" );
246 if ( myViewModel && myViewModel->getCurrentView() )
247 myViewModel->getCurrentView()->activateFitAll();
251 Set background of the viewport
253 void QxGraph_ViewWindow::setBackgroundColor( const QColor& color )
255 if ( myViewModel && myViewModel->getCurrentView()) {
256 myViewModel->getCurrentView()->canvas()->setBackgroundColor(color);
257 myViewModel->getCurrentView()->setPaletteBackgroundColor(color.light(120));
262 Returns background of the viewport
264 QColor QxGraph_ViewWindow::backgroundColor() const
266 if ( myViewModel && myViewModel->getCurrentView())
267 return myViewModel->getCurrentView()->canvas()->backgroundColor();
272 Custom resize event handler
274 void QxGraph_ViewWindow::resizeEvent( QResizeEvent* theEvent )
276 // QMainWindow::resizeEvent( theEvent );
277 //if ( myView ) myView->resizeView( theEvent );
283 SUIT_ResourceMgr* QxGraph_ViewWindow::resMgr() const
285 return SUIT_Session::session()->resourceMgr();