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