]> SALOME platform Git repositories - modules/gui.git/blob - src/QxGraph/QxGraph_ViewWindow.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/gui.git] / src / QxGraph / QxGraph_ViewWindow.cxx
1 //  SALOME QxGraph : build Supervisor viewer into desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "QxGraph_ViewWindow.h"
24 #include "QxGraph_Def.h"
25 #include "QxGraph_Canvas.h"
26 #include "QxGraph_CanvasView.h"
27
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_ToolButton.h>
31
32 //QT Include
33 #include <qlayout.h>
34 #include <qcolor.h>
35 //#include <qcolordialog.h>
36
37 using namespace std;
38
39 /*!
40     Constructor
41 */
42 QxGraph_ViewWindow::QxGraph_ViewWindow( SUIT_Desktop* theDesktop, QxGraph_Viewer* theModel)
43   : SUIT_ViewWindow( theDesktop )
44 {
45   printf("Construct QxGraph_ViewWindow\n");
46   myViewModel = theModel;
47 }
48
49 /*!
50   Initialization
51 */
52 void QxGraph_ViewWindow::initLayout()
53 {
54   initCanvas();
55   initCanvasViews();
56
57   myToolBar = new QToolBar(this);
58   myToolBar->setCloseMode(QDockWindow::Undocked);
59   myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
60   createActions();
61   createToolBar();
62 }
63
64 /*!
65   Canvas initialization
66 */
67 void QxGraph_ViewWindow::initCanvas()
68 {
69   if ( myViewModel )
70     myViewModel->setCanvas( new QxGraph_Canvas(resMgr()) );
71     //myViewModel->addCanvas( new QxGraph_Canvas(resMgr()) );
72 }
73
74 /*!
75   Canvas views initialization
76 */
77 void QxGraph_ViewWindow::initCanvasViews()
78 {
79   if ( myViewModel )
80   {
81     for (int i = 0; i < 2; i++)
82     {
83       //QxGraph_Canvas* aCanvas = new QxGraph_Canvas(resMgr());
84       //myViewModel->addCanvas( aCanvas );
85
86       QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
87       //QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( aCanvas, this );
88       myViewModel->addView(aCanvasView);
89
90       aCanvasView->hide();
91     }
92       
93     // the first view is shown and is the current
94     myViewModel->getCanvasViews().first()->show();
95     myViewModel->setCurrentView( myViewModel->getCanvasViews().first() );
96     
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 <-- */
102
103     setCentralWidget( myViewModel->getCurrentView() );
104     
105     /*if ( inherits( "QMainWindow" ) ) {
106       printf("== > 1\n");
107       ( ( QMainWindow* )this )->setCentralWidget( myViewModel->getCurrentView() );
108       }
109       else {
110       printf("== > 2\n");
111       QBoxLayout* layout = new QVBoxLayout( this );
112       layout->addWidget( myViewModel->getCurrentView() );
113       }*/
114   }
115 }
116
117 /*!
118   Creates actions of QxGraph view window
119 */
120 void QxGraph_ViewWindow::createActions()
121 {
122   if (!myActionsMap.isEmpty()) return;
123   SUIT_ResourceMgr* aResMgr = resMgr();
124   QtxAction* aAction;
125
126   // FitAll
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;
132
133   // FitRect
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;
139
140   // Zoom
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;
146
147   // Panning
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;
153
154   // Global Panning
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;
160
161   // Reset
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;
167 }
168
169 /*!
170   Creates toolbar of QxGraph view window
171 */
172 void QxGraph_ViewWindow::createToolBar()
173 {
174   SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
175   aScaleBtn->AddAction(myActionsMap[FitAllId]);
176   aScaleBtn->AddAction(myActionsMap[FitRectId]);
177   aScaleBtn->AddAction(myActionsMap[ZoomId]);
178
179   SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
180   aPanningBtn->AddAction(myActionsMap[PanId]);
181   aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
182
183   myActionsMap[ResetId]->addTo(myToolBar);
184 }
185
186 /*!
187   Destructor
188 */
189 QxGraph_ViewWindow::~QxGraph_ViewWindow() {}
190
191 /*!
192   Reset the active view
193 */
194 void QxGraph_ViewWindow::onViewReset()    
195 {
196   printf( "QxGraph_ViewWindow::onViewReset\n" );
197   if ( myViewModel && myViewModel->getCurrentView() )
198     myViewModel->getCurrentView()->activateReset();
199 }
200
201 /*!
202   Sets a new center of the active view
203 */
204 void QxGraph_ViewWindow::onViewGlobalPan()
205 {
206   printf( "QxGraph_ViewWindow::onViewGlobalPan\n" );
207   if ( myViewModel && myViewModel->getCurrentView() )
208     myViewModel->getCurrentView()->activateGlobalPanning();
209 }
210
211 /*!
212   Zooms the active view
213 */
214 void QxGraph_ViewWindow::onViewZoom()
215 {
216   printf( "QxGraph_ViewWindow::onViewZoom\n" );
217   if ( myViewModel && myViewModel->getCurrentView() )
218     myViewModel->getCurrentView()->activateZoom();
219 }
220
221 /*!
222   Moves the active view
223 */
224 void QxGraph_ViewWindow::onViewPan()
225 {
226   printf( "QxGraph_ViewWindow::onViewPan\n" );
227   if ( myViewModel && myViewModel->getCurrentView() )
228     myViewModel->getCurrentView()->activatePanning();
229 }
230
231 /*!
232   Fits all obejcts within a rectangular area of the active view
233 */
234 void QxGraph_ViewWindow::onViewFitArea()
235 {
236   printf( "QxGraph_ViewWindow::onViewFitArea\n" );
237   if ( myViewModel && myViewModel->getCurrentView() )
238     myViewModel->getCurrentView()->activateFitRect();
239 }
240
241 /*!
242   Fits all objects in the active view
243 */
244 void QxGraph_ViewWindow::onViewFitAll()
245 {
246   printf( "QxGraph_ViewWindow::onViewFitAll\n" );
247   if ( myViewModel && myViewModel->getCurrentView() )
248     myViewModel->getCurrentView()->activateFitAll();
249 }
250
251 /*!
252     Set background of the viewport
253 */
254 void QxGraph_ViewWindow::setBackgroundColor( const QColor& color )
255 {
256   if ( myViewModel && myViewModel->getCurrentView()) {
257     myViewModel->getCurrentView()->canvas()->setBackgroundColor(color);
258     myViewModel->getCurrentView()->setPaletteBackgroundColor(color.light(120));
259   }
260 }
261
262 /*!
263     Returns background of the viewport
264 */
265 QColor QxGraph_ViewWindow::backgroundColor() const
266 {
267   if ( myViewModel && myViewModel->getCurrentView())
268     return myViewModel->getCurrentView()->canvas()->backgroundColor();
269   return QColor();
270 }
271
272 /*!
273   Custom resize event handler
274 */
275 void QxGraph_ViewWindow::resizeEvent( QResizeEvent* theEvent )
276 {
277   //  QMainWindow::resizeEvent( theEvent );
278   //if ( myView ) myView->resizeView( theEvent );
279 }
280
281 /*!
282   Get resource manager
283 */
284 SUIT_ResourceMgr* QxGraph_ViewWindow::resMgr() const
285
286   return SUIT_Session::session()->resourceMgr(); 
287 }
288