1 // Plot2d_ViewWindow.cxx: implementation of the Plot2d_ViewWindow class.
3 //////////////////////////////////////////////////////////////////////
4 #include "Plot2d_ViewWindow.h"
5 #include "Plot2d_ViewFrame.h"
7 #include "SUIT_ViewManager.h"
8 #include "SUIT_ResourceMgr.h"
9 #include "SUIT_Session.h"
10 #include "SUIT_ToolButton.h"
11 #include "SUIT_Desktop.h"
13 #include "QtxAction.h"
15 #include <qstatusbar.h>
17 #include <qapplication.h>
18 #include <qpopupmenu.h>
20 //////////////////////////////////////////////////////////////////////
21 // Construction/Destruction
22 //////////////////////////////////////////////////////////////////////
24 Plot2d_ViewWindow::Plot2d_ViewWindow(SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel)
25 : SUIT_ViewWindow(theDesktop)
29 myViewFrame = new Plot2d_ViewFrame(this, "plotView");
30 setCentralWidget(myViewFrame);
32 myToolBar = new QToolBar(this);
33 myToolBar->setCloseMode(QDockWindow::Undocked);
34 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
38 connect(myViewFrame, SIGNAL(vpModeHorChanged()), this, SLOT(onChangeHorMode()));
39 connect(myViewFrame, SIGNAL(vpModeVerChanged()), this, SLOT(onChangeVerMode()));
40 connect(myViewFrame, SIGNAL(vpCurveChanged()), this, SLOT(onChangeCurveMode()));
41 connect(myViewFrame, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
42 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
46 Plot2d_ViewWindow::~Plot2d_ViewWindow()
50 //****************************************************************
51 void Plot2d_ViewWindow::putInfo(QString theMsg)
53 QStatusBar* aStatusBar = myDesktop->statusBar();
54 aStatusBar->message(theMsg/*, 3000*/);
57 //****************************************************************
58 void Plot2d_ViewWindow::contextMenuPopup( QPopupMenu* thePopup )
61 QPopupMenu* scalingPopup = new QPopupMenu( thePopup );
62 myActionsMap[ PModeXLinearId ]->addTo( scalingPopup );
63 myActionsMap[ PModeXLogarithmicId ]->addTo( scalingPopup );
65 scalingPopup->insertSeparator();
66 myActionsMap[ PModeYLinearId ]->addTo( scalingPopup );
67 myActionsMap[ PModeYLogarithmicId ]->addTo( scalingPopup );
68 thePopup->insertItem( tr( "SCALING_POPUP" ), scalingPopup );
71 thePopup->insertItem(tr("TOT_PLOT2D_FITDATA"), myViewFrame, SLOT(onFitData()));
73 QPopupMenu* curTypePopup = new QPopupMenu( thePopup );
74 myActionsMap[ CurvPointsId ]->addTo( curTypePopup );
75 myActionsMap[ CurvLinesId ]->addTo( curTypePopup );
76 myActionsMap[ CurvSplinesId ]->addTo( curTypePopup );
77 thePopup->insertItem( tr( "CURVE_TYPE_POPUP" ), curTypePopup );
80 myActionsMap[ LegendId ]->addTo(thePopup);
82 myActionsMap[ CurvSettingsId ]->addTo(thePopup);
85 //****************************************************************
86 bool Plot2d_ViewWindow::eventFilter(QObject* watched, QEvent* e)
88 if (watched == myViewFrame) {
89 int aType = e->type();
91 case QEvent::MouseButtonPress:
92 emit mousePressed(this, (QMouseEvent*) e);
95 case QEvent::MouseButtonRelease:
96 emit mouseReleased(this, (QMouseEvent*) e);
99 case QEvent::MouseMove:
100 emit mouseMoving(this, (QMouseEvent*) e);
107 return SUIT_ViewWindow::eventFilter(watched, e);
110 //****************************************************************
111 void Plot2d_ViewWindow::createActions()
113 if ( !myActionsMap.isEmpty() )
117 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
120 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ),
121 tr( "MNU_DUMP_VIEW" ), 0, this);
122 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
123 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
124 myActionsMap[ DumpId ] = aAction;
127 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ),
128 tr( "MNU_FITALL" ), 0, this);
129 aAction->setStatusTip(tr("DSC_FITALL"));
130 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
131 myActionsMap[ FitAllId ] = aAction;
134 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ),
135 tr( "MNU_FITRECT" ), 0, this);
136 aAction->setStatusTip(tr("DSC_FITRECT"));
137 connect(aAction, SIGNAL(activated()), this, SLOT(onFitRect()));
138 myActionsMap[ FitRectId ] = aAction;
141 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ),
142 tr( "MNU_ZOOM_VIEW" ), 0, this);
143 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
144 connect(aAction, SIGNAL(activated()), this, SLOT(onZoom()));
145 myActionsMap[ ZoomId ] = aAction;
148 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ),
149 tr( "MNU_PAN_VIEW" ), 0, this);
150 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
151 connect(aAction, SIGNAL(activated()), this, SLOT(onPanning()));
152 myActionsMap[ PanId ] = aAction;
155 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ),
156 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
157 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
158 connect(aAction, SIGNAL(activated()), this, SLOT(onGlobalPanning()));
159 myActionsMap[ GlobalPanId ] = aAction;
161 // Curve type - points
162 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_POINTS"),
163 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_POINTS")),
164 tr("MEN_PLOT2D_CURVES_POINTS"), 0, this);
165 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_POINTS"));
166 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
167 aAction->setToggleAction(true);
168 myActionsMap[ CurvPointsId ] = aAction;
170 // Curve type - lines
171 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_LINES"),
172 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_LINES")),
173 tr("MEN_PLOT2D_CURVES_LINES"), 0, this);
174 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_LINES"));
175 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
176 aAction->setToggleAction(true);
177 myActionsMap[ CurvLinesId ] = aAction;
179 // Curve type - splines
180 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_SPLINES"),
181 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_SPLINES")),
182 tr("MEN_PLOT2D_CURVES_SPLINES"), 0, this);
183 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_SPLINES"));
184 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
185 aAction->setToggleAction(true);
186 myActionsMap[ CurvSplinesId ] = aAction;
188 // Mode for X (linear or logarithmic)
189 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"),
190 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")),
191 tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this);
192 aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR"));
193 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
194 myActionsMap[ HorId ] = aAction;
196 // Mode for Y (linear or logarithmic)
197 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"),
198 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")),
199 tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this);
200 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER"));
201 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
202 myActionsMap[ VerId ] = aAction;
205 aAction = new QtxAction(tr("TOT_PLOT2D_SHOW_LEGEND"),
206 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SHOW_LEGEND")),
207 tr("MEN_PLOT2D_SHOW_LEGEND"), 0, this);
208 aAction->setStatusTip(tr("PRP_PLOT2D_SHOW_LEGEND"));
209 connect(aAction, SIGNAL(activated()), this, SLOT(onLegend()));
210 aAction->setToggleAction(true);
211 myActionsMap[ LegendId ] = aAction;
214 aAction = new QtxAction(tr( "TOT_PLOT2D_SETTINGS"),
215 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SETTINGS")),
216 tr("MEN_PLOT2D_SETTINGS"), 0, this);
217 aAction->setStatusTip(tr( "PRP_PLOT2D_SETTINGS"));
218 connect(aAction, SIGNAL(activated()), myViewFrame, SLOT(onSettings()));
219 myActionsMap[ CurvSettingsId ] = aAction;
222 aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
223 tr( "MNU_CLONE_VIEW" ), 0, this);
224 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
225 connect(aAction, SIGNAL(activated()), this, SIGNAL(cloneView()));
226 myActionsMap[ CloneId ] = aAction;
229 /* Linear/logarithmic mode */
231 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"),
232 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")),
233 tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this);
234 aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR"));
235 aAction->setToggleAction(true);
236 myActionsMap[PModeXLinearId] = aAction;
237 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
239 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_HOR"),
240 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_HOR")),
241 tr("MEN_PLOT2D_MODE_LOGARITHMIC_HOR"), 0, this);
242 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_HOR"));
243 aAction->setToggleAction(true);
244 myActionsMap[PModeXLogarithmicId] = aAction;
245 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
248 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"),
249 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")),
250 tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this);
251 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER"));
252 aAction->setToggleAction(true);
253 myActionsMap[PModeYLinearId] = aAction;
254 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
256 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_VER"),
257 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_VER")),
258 tr("MEN_PLOT2D_MODE_LOGARITHMIC_VER" ), 0, this);
259 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_VER"));
260 aAction->setToggleAction(true);
261 myActionsMap[PModeYLogarithmicId] = aAction;
262 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
266 //****************************************************************
267 void Plot2d_ViewWindow::createToolBar()
269 myActionsMap[DumpId]->addTo(myToolBar);
271 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
272 aScaleBtn->AddAction(myActionsMap[FitAllId]);
273 aScaleBtn->AddAction(myActionsMap[FitRectId]);
274 aScaleBtn->AddAction(myActionsMap[ZoomId]);
276 SUIT_ToolButton* aPanBtn = new SUIT_ToolButton(myToolBar);
277 aPanBtn->AddAction(myActionsMap[PanId]);
278 aPanBtn->AddAction(myActionsMap[GlobalPanId]);
280 myCurveBtn = new SUIT_ToolButton(myToolBar);
281 myCurveBtn->AddAction(myActionsMap[CurvPointsId]);
282 myCurveBtn->AddAction(myActionsMap[CurvLinesId]);
283 myCurveBtn->AddAction(myActionsMap[CurvSplinesId]);
284 myActionsMap[CurvLinesId]->setOn(true);
287 myActionsMap[HorId]->addTo(myToolBar);
289 myActionsMap[VerId]->addTo(myToolBar);
292 myActionsMap[LegendId]->addTo(myToolBar);
293 myActionsMap[CurvSettingsId]->addTo(myToolBar);
294 myActionsMap[CloneId]->addTo(myToolBar);
295 onChangeLegendMode();
298 //****************************************************************
299 void Plot2d_ViewWindow::onChangeHorMode()
301 bool aLinear = myViewFrame->isModeHorLinear();
302 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
304 myActionsMap[PModeXLinearId]->setOn( aLinear );
305 myActionsMap[PModeXLogarithmicId]->setOn( !aLinear );
307 QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" :
308 "ICON_PLOT2D_MODE_LINEAR_HOR" ) );
309 myActionsMap[HorId]->setIconSet( pix );
310 myActionsMap[HorId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" :
311 "TOT_PLOT2D_MODE_LINEAR_HOR" ) );
312 myActionsMap[HorId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" :
313 "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
315 myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
318 //****************************************************************
319 void Plot2d_ViewWindow::onChangeVerMode()
321 bool aLinear = myViewFrame->isModeVerLinear();
322 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
324 myActionsMap[PModeYLinearId]->setOn( aLinear );
325 myActionsMap[PModeYLogarithmicId]->setOn( !aLinear );
327 QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_VER" :
328 "ICON_PLOT2D_MODE_LINEAR_VER" ) );
329 myActionsMap[VerId]->setIconSet( pix );
330 myActionsMap[VerId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_VER" :
331 "TOT_PLOT2D_MODE_LINEAR_VER" ) );
332 myActionsMap[VerId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_VER" :
333 "PRP_PLOT2D_MODE_LINEAR_VER" ) );
335 myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
338 //****************************************************************
339 void Plot2d_ViewWindow::onChangeCurveMode()
341 myCurveBtn->SetItem(myViewFrame->getCurveType());
344 //****************************************************************
345 void Plot2d_ViewWindow::onChangeLegendMode()
347 myActionsMap[ LegendId ]->setOn(myViewFrame->isLegendShow());
350 //****************************************************************
351 void Plot2d_ViewWindow::onFitAll()
353 myViewFrame->onViewFitAll();
356 //****************************************************************
357 void Plot2d_ViewWindow::onFitRect()
359 myViewFrame->onViewFitArea();
362 //****************************************************************
363 void Plot2d_ViewWindow::onZoom()
365 myViewFrame->onViewZoom();
368 //****************************************************************
369 void Plot2d_ViewWindow::onPanning()
371 myViewFrame->onViewPan();
374 //****************************************************************
375 void Plot2d_ViewWindow::onGlobalPanning()
377 myViewFrame->onViewGlobalPan();
380 //****************************************************************
381 void Plot2d_ViewWindow::onViewHorMode()
383 if (myViewFrame->isModeHorLinear())
384 myViewFrame->setHorScaleMode(1);
386 myViewFrame->setHorScaleMode(0);
389 //****************************************************************
390 void Plot2d_ViewWindow::onViewVerMode()
392 if (myViewFrame->isModeVerLinear())
393 myViewFrame->setVerScaleMode(1);
395 myViewFrame->setVerScaleMode(0);
398 //****************************************************************
399 void Plot2d_ViewWindow::onLegend()
401 myViewFrame->showLegend(!myViewFrame->isLegendShow());
402 onChangeLegendMode();
405 //****************************************************************
406 void Plot2d_ViewWindow::onCurves()
408 QtxAction* aSender = (QtxAction*) sender();
409 if(aSender == myActionsMap[CurvPointsId]) {
410 myActionsMap[CurvPointsId]->setOn(true);
411 myActionsMap[CurvLinesId]->setOn(false);
412 myActionsMap[CurvSplinesId]->setOn(false);
413 myViewFrame->setCurveType(0);
415 else if(aSender == myActionsMap[CurvLinesId]) {
416 myActionsMap[CurvLinesId]->setOn(true);
417 myActionsMap[CurvPointsId]->setOn(false);
418 myActionsMap[CurvSplinesId]->setOn(false);
419 myViewFrame->setCurveType(1);
421 else if(aSender == myActionsMap[CurvSplinesId]) {
422 myActionsMap[CurvSplinesId]->setOn( true );
423 myActionsMap[CurvPointsId]->setOn( false );
424 myActionsMap[CurvLinesId]->setOn( false );
425 myViewFrame->setCurveType(2);
429 //****************************************************************
430 void Plot2d_ViewWindow::onDumpView()
432 qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ), TRUE ) );
433 SUIT_ViewWindow::onDumpView();
436 //****************************************************************
437 QImage Plot2d_ViewWindow::dumpView()
439 QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
440 return px.convertToImage();