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 QxGraph : build Supervisor viewer into desktop
24 #include "QxGraph_ViewWindow.h"
25 #include "QxGraph_Def.h"
26 #include "QxGraph_Canvas.h"
27 #include "QxGraph_CanvasView.h"
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ToolButton.h>
36 //#include <qcolordialog.h>
43 QxGraph_ViewWindow::QxGraph_ViewWindow( SUIT_Desktop* theDesktop, QxGraph_Viewer* theModel)
44 : SUIT_ViewWindow( theDesktop )
46 printf("Construct QxGraph_ViewWindow\n");
47 myViewModel = theModel;
53 void QxGraph_ViewWindow::initLayout()
58 myToolBar = new QToolBar(this);
59 myToolBar->setCloseMode(QDockWindow::Undocked);
60 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
68 void QxGraph_ViewWindow::initCanvas()
71 myViewModel->setCanvas( new QxGraph_Canvas(resMgr()) );
72 //myViewModel->addCanvas( new QxGraph_Canvas(resMgr()) );
76 Canvas views initialization
78 void QxGraph_ViewWindow::initCanvasViews()
82 for (int i = 0; i < 2; i++)
84 //QxGraph_Canvas* aCanvas = new QxGraph_Canvas(resMgr());
85 //myViewModel->addCanvas( aCanvas );
87 QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
88 //QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( aCanvas, this );
89 myViewModel->addView(aCanvasView);
94 // the first view is shown and is the current
95 myViewModel->getCanvasViews().first()->show();
96 myViewModel->setCurrentView( myViewModel->getCanvasViews().first() );
98 /* test for 1 view -->
99 QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
100 myViewModel->addView(aCanvasView);
101 myViewModel->setCurrentView(aCanvasView);
102 test for 1 view <-- */
104 setCentralWidget( myViewModel->getCurrentView() );
106 /*if ( inherits( "QMainWindow" ) ) {
108 ( ( QMainWindow* )this )->setCentralWidget( myViewModel->getCurrentView() );
112 QBoxLayout* layout = new QVBoxLayout( this );
113 layout->addWidget( myViewModel->getCurrentView() );
119 Creates actions of QxGraph view window
121 void QxGraph_ViewWindow::createActions()
123 if (!myActionsMap.isEmpty()) return;
124 SUIT_ResourceMgr* aResMgr = resMgr();
128 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITALL" ) ),
129 tr( "MNU_FITALL" ), 0, this);
130 aAction->setStatusTip(tr("DSC_FITALL"));
131 connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitAll()));
132 myActionsMap[ FitAllId ] = aAction;
135 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITAREA" ) ),
136 tr( "MNU_FITRECT" ), 0, this);
137 aAction->setStatusTip(tr("DSC_FITRECT"));
138 connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitArea()));
139 myActionsMap[ FitRectId ] = aAction;
142 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_ZOOM" ) ),
143 tr( "MNU_ZOOM_VIEW" ), 0, this);
144 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
145 connect(aAction, SIGNAL(activated()), this, SLOT(onViewZoom()));
146 myActionsMap[ ZoomId ] = aAction;
149 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_PAN" ) ),
150 tr( "MNU_PAN_VIEW" ), 0, this);
151 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
152 connect(aAction, SIGNAL(activated()), this, SLOT(onViewPan()));
153 myActionsMap[ PanId ] = aAction;
156 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_GLOBALPAN" ) ),
157 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
158 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
159 connect(aAction, SIGNAL(activated()), this, SLOT(onViewGlobalPan()));
160 myActionsMap[ GlobalPanId ] = aAction;
163 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_RESET" ) ),
164 tr( "MNU_RESET_VIEW" ), 0, this);
165 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
166 connect(aAction, SIGNAL(activated()), this, SLOT(onViewReset()));
167 myActionsMap[ ResetId ] = aAction;
171 Creates toolbar of QxGraph view window
173 void QxGraph_ViewWindow::createToolBar()
175 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
176 aScaleBtn->AddAction(myActionsMap[FitAllId]);
177 aScaleBtn->AddAction(myActionsMap[FitRectId]);
178 aScaleBtn->AddAction(myActionsMap[ZoomId]);
180 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
181 aPanningBtn->AddAction(myActionsMap[PanId]);
182 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
184 myActionsMap[ResetId]->addTo(myToolBar);
190 QxGraph_ViewWindow::~QxGraph_ViewWindow() {}
193 Reset the active view
195 void QxGraph_ViewWindow::onViewReset()
197 printf( "QxGraph_ViewWindow::onViewReset\n" );
198 if ( myViewModel && myViewModel->getCurrentView() )
199 myViewModel->getCurrentView()->activateReset();
203 Sets a new center of the active view
205 void QxGraph_ViewWindow::onViewGlobalPan()
207 printf( "QxGraph_ViewWindow::onViewGlobalPan\n" );
208 if ( myViewModel && myViewModel->getCurrentView() )
209 myViewModel->getCurrentView()->activateGlobalPanning();
213 Zooms the active view
215 void QxGraph_ViewWindow::onViewZoom()
217 printf( "QxGraph_ViewWindow::onViewZoom\n" );
218 if ( myViewModel && myViewModel->getCurrentView() )
219 myViewModel->getCurrentView()->activateZoom();
223 Moves the active view
225 void QxGraph_ViewWindow::onViewPan()
227 printf( "QxGraph_ViewWindow::onViewPan\n" );
228 if ( myViewModel && myViewModel->getCurrentView() )
229 myViewModel->getCurrentView()->activatePanning();
233 Fits all obejcts within a rectangular area of the active view
235 void QxGraph_ViewWindow::onViewFitArea()
237 printf( "QxGraph_ViewWindow::onViewFitArea\n" );
238 if ( myViewModel && myViewModel->getCurrentView() )
239 myViewModel->getCurrentView()->activateFitRect();
243 Fits all objects in the active view
245 void QxGraph_ViewWindow::onViewFitAll()
247 printf( "QxGraph_ViewWindow::onViewFitAll\n" );
248 if ( myViewModel && myViewModel->getCurrentView() )
249 myViewModel->getCurrentView()->activateFitAll();
253 Set background of the viewport
255 void QxGraph_ViewWindow::setBackgroundColor( const QColor& color )
257 if ( myViewModel && myViewModel->getCurrentView()) {
258 myViewModel->getCurrentView()->canvas()->setBackgroundColor(color);
259 myViewModel->getCurrentView()->setPaletteBackgroundColor(color.light(120));
264 Returns background of the viewport
266 QColor QxGraph_ViewWindow::backgroundColor() const
268 if ( myViewModel && myViewModel->getCurrentView())
269 return myViewModel->getCurrentView()->canvas()->backgroundColor();
274 Custom resize event handler
276 void QxGraph_ViewWindow::resizeEvent( QResizeEvent* theEvent )
278 // QMainWindow::resizeEvent( theEvent );
279 //if ( myView ) myView->resizeView( theEvent );
285 SUIT_ResourceMgr* QxGraph_ViewWindow::resMgr() const
287 return SUIT_Session::session()->resourceMgr();