1 // SALOME QxGraph : build Supervisor viewer into desktop
3 // Copyright (C) 2003 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 #include "QxGraph_ViewWindow.h"
24 #include "QxGraph_Def.h"
25 #include "QxGraph_Canvas.h"
26 #include "QxGraph_CanvasView.h"
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_ToolButton.h>
35 //#include <qcolordialog.h>
42 QxGraph_ViewWindow::QxGraph_ViewWindow( SUIT_Desktop* theDesktop, QxGraph_Viewer* theModel)
43 : SUIT_ViewWindow( theDesktop )
45 printf("Construct QxGraph_ViewWindow\n");
46 myViewModel = theModel;
52 void QxGraph_ViewWindow::initLayout()
57 myToolBar = new QToolBar(this);
58 myToolBar->setCloseMode(QDockWindow::Undocked);
59 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
67 void QxGraph_ViewWindow::initCanvas()
70 myViewModel->setCanvas( new QxGraph_Canvas(resMgr()) );
71 //myViewModel->addCanvas( new QxGraph_Canvas(resMgr()) );
75 Canvas views initialization
77 void QxGraph_ViewWindow::initCanvasViews()
81 for (int i = 0; i < 2; i++)
83 //QxGraph_Canvas* aCanvas = new QxGraph_Canvas(resMgr());
84 //myViewModel->addCanvas( aCanvas );
86 QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
87 //QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( aCanvas, this );
88 myViewModel->addView(aCanvasView);
93 // the first view is shown and is the current
94 myViewModel->getCanvasViews().first()->show();
95 myViewModel->setCurrentView( myViewModel->getCanvasViews().first() );
97 /* test for 1 view -->
98 QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
99 myViewModel->addView(aCanvasView);
100 myViewModel->setCurrentView(aCanvasView);
101 test for 1 view <-- */
103 setCentralWidget( myViewModel->getCurrentView() );
105 /*if ( inherits( "QMainWindow" ) ) {
107 ( ( QMainWindow* )this )->setCentralWidget( myViewModel->getCurrentView() );
111 QBoxLayout* layout = new QVBoxLayout( this );
112 layout->addWidget( myViewModel->getCurrentView() );
118 Creates actions of QxGraph view window
120 void QxGraph_ViewWindow::createActions()
122 if (!myActionsMap.isEmpty()) return;
123 SUIT_ResourceMgr* aResMgr = resMgr();
127 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITALL" ) ),
128 tr( "MNU_FITALL" ), 0, this);
129 aAction->setStatusTip(tr("DSC_FITALL"));
130 connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitAll()));
131 myActionsMap[ FitAllId ] = aAction;
134 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITAREA" ) ),
135 tr( "MNU_FITRECT" ), 0, this);
136 aAction->setStatusTip(tr("DSC_FITRECT"));
137 connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitArea()));
138 myActionsMap[ FitRectId ] = aAction;
141 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_ZOOM" ) ),
142 tr( "MNU_ZOOM_VIEW" ), 0, this);
143 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
144 connect(aAction, SIGNAL(activated()), this, SLOT(onViewZoom()));
145 myActionsMap[ ZoomId ] = aAction;
148 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_PAN" ) ),
149 tr( "MNU_PAN_VIEW" ), 0, this);
150 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
151 connect(aAction, SIGNAL(activated()), this, SLOT(onViewPan()));
152 myActionsMap[ PanId ] = aAction;
155 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_GLOBALPAN" ) ),
156 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
157 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
158 connect(aAction, SIGNAL(activated()), this, SLOT(onViewGlobalPan()));
159 myActionsMap[ GlobalPanId ] = aAction;
162 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_RESET" ) ),
163 tr( "MNU_RESET_VIEW" ), 0, this);
164 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
165 connect(aAction, SIGNAL(activated()), this, SLOT(onViewReset()));
166 myActionsMap[ ResetId ] = aAction;
170 Creates toolbar of QxGraph view window
172 void QxGraph_ViewWindow::createToolBar()
174 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
175 aScaleBtn->AddAction(myActionsMap[FitAllId]);
176 aScaleBtn->AddAction(myActionsMap[FitRectId]);
177 aScaleBtn->AddAction(myActionsMap[ZoomId]);
179 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
180 aPanningBtn->AddAction(myActionsMap[PanId]);
181 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
183 myActionsMap[ResetId]->addTo(myToolBar);
189 QxGraph_ViewWindow::~QxGraph_ViewWindow() {}
192 Reset the active view
194 void QxGraph_ViewWindow::onViewReset()
196 printf( "QxGraph_ViewWindow::onViewReset\n" );
197 if ( myViewModel && myViewModel->getCurrentView() )
198 myViewModel->getCurrentView()->activateReset();
202 Sets a new center of the active view
204 void QxGraph_ViewWindow::onViewGlobalPan()
206 printf( "QxGraph_ViewWindow::onViewGlobalPan\n" );
207 if ( myViewModel && myViewModel->getCurrentView() )
208 myViewModel->getCurrentView()->activateGlobalPanning();
212 Zooms the active view
214 void QxGraph_ViewWindow::onViewZoom()
216 printf( "QxGraph_ViewWindow::onViewZoom\n" );
217 if ( myViewModel && myViewModel->getCurrentView() )
218 myViewModel->getCurrentView()->activateZoom();
222 Moves the active view
224 void QxGraph_ViewWindow::onViewPan()
226 printf( "QxGraph_ViewWindow::onViewPan\n" );
227 if ( myViewModel && myViewModel->getCurrentView() )
228 myViewModel->getCurrentView()->activatePanning();
232 Fits all obejcts within a rectangular area of the active view
234 void QxGraph_ViewWindow::onViewFitArea()
236 printf( "QxGraph_ViewWindow::onViewFitArea\n" );
237 if ( myViewModel && myViewModel->getCurrentView() )
238 myViewModel->getCurrentView()->activateFitRect();
242 Fits all objects in the active view
244 void QxGraph_ViewWindow::onViewFitAll()
246 printf( "QxGraph_ViewWindow::onViewFitAll\n" );
247 if ( myViewModel && myViewModel->getCurrentView() )
248 myViewModel->getCurrentView()->activateFitAll();
252 Set background of the viewport
254 void QxGraph_ViewWindow::setBackgroundColor( const QColor& color )
256 if ( myViewModel && myViewModel->getCurrentView()) {
257 myViewModel->getCurrentView()->canvas()->setBackgroundColor(color);
258 myViewModel->getCurrentView()->setPaletteBackgroundColor(color.light(120));
263 Returns background of the viewport
265 QColor QxGraph_ViewWindow::backgroundColor() const
267 if ( myViewModel && myViewModel->getCurrentView())
268 return myViewModel->getCurrentView()->canvas()->backgroundColor();
273 Custom resize event handler
275 void QxGraph_ViewWindow::resizeEvent( QResizeEvent* theEvent )
277 // QMainWindow::resizeEvent( theEvent );
278 //if ( myView ) myView->resizeView( theEvent );
284 SUIT_ResourceMgr* QxGraph_ViewWindow::resMgr() const
286 return SUIT_Session::session()->resourceMgr();