Back to index

salome-gui  6.5.0
QxGraph_ViewWindow.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME QxGraph : build Supervisor viewer into desktop
00024 //
00025 #include "QxGraph_ViewWindow.h"
00026 #include "QxGraph_Def.h"
00027 #include "QxGraph_Canvas.h"
00028 #include "QxGraph_CanvasView.h"
00029 
00030 #include <SUIT_ResourceMgr.h>
00031 #include <SUIT_Session.h>
00032 #include <SUIT_ToolButton.h>
00033 
00034 //QT Include
00035 #include <qlayout.h>
00036 #include <qcolor.h>
00037 
00041 QxGraph_ViewWindow::QxGraph_ViewWindow( SUIT_Desktop* theDesktop, QxGraph_Viewer* theModel)
00042   : SUIT_ViewWindow( theDesktop )
00043 {
00044   printf("Construct QxGraph_ViewWindow\n");
00045   myViewModel = theModel;
00046 }
00047 
00051 void QxGraph_ViewWindow::initLayout()
00052 {
00053   initCanvas();
00054   initCanvasViews();
00055 
00056   myToolBar = new QToolBar(this);
00057   myToolBar->setCloseMode(QDockWindow::Undocked);
00058   myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
00059   createActions();
00060   createToolBar();
00061 }
00062 
00066 void QxGraph_ViewWindow::initCanvas()
00067 {
00068   if ( myViewModel )
00069     myViewModel->setCanvas( new QxGraph_Canvas(resMgr()) );
00070     //myViewModel->addCanvas( new QxGraph_Canvas(resMgr()) );
00071 }
00072 
00076 void QxGraph_ViewWindow::initCanvasViews()
00077 {
00078   if ( myViewModel )
00079   {
00080     for (int i = 0; i < 2; i++)
00081     {
00082       //QxGraph_Canvas* aCanvas = new QxGraph_Canvas(resMgr());
00083       //myViewModel->addCanvas( aCanvas );
00084 
00085       QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
00086       //QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( aCanvas, this );
00087       myViewModel->addView(aCanvasView);
00088 
00089       aCanvasView->hide();
00090     }
00091       
00092     // the first view is shown and is the current
00093     myViewModel->getCanvasViews().first()->show();
00094     myViewModel->setCurrentView( myViewModel->getCanvasViews().first() );
00095     
00096     /* test for 1 view -->
00097     QxGraph_CanvasView* aCanvasView = new QxGraph_CanvasView( myViewModel->getCanvas(), this );
00098     myViewModel->addView(aCanvasView);
00099     myViewModel->setCurrentView(aCanvasView);
00100     test for 1 view <-- */
00101 
00102     setCentralWidget( myViewModel->getCurrentView() );
00103     
00104     /*if ( inherits( "QMainWindow" ) ) {
00105       printf("== > 1\n");
00106       ( ( QMainWindow* )this )->setCentralWidget( myViewModel->getCurrentView() );
00107       }
00108       else {
00109       printf("== > 2\n");
00110       QBoxLayout* layout = new QVBoxLayout( this );
00111       layout->addWidget( myViewModel->getCurrentView() );
00112       }*/
00113   }
00114 }
00115 
00119 void QxGraph_ViewWindow::createActions()
00120 {
00121   if (!myActionsMap.isEmpty()) return;
00122   SUIT_ResourceMgr* aResMgr = resMgr();
00123   QtxAction* aAction;
00124 
00125   // FitAll
00126   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITALL" ) ),
00127                           tr( "MNU_FITALL" ), 0, this);
00128   aAction->setStatusTip(tr("DSC_FITALL"));
00129   connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitAll()));
00130   myActionsMap[ FitAllId ] = aAction;
00131 
00132   // FitRect
00133   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_FITAREA" ) ),
00134                           tr( "MNU_FITRECT" ), 0, this);
00135   aAction->setStatusTip(tr("DSC_FITRECT"));
00136   connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitArea()));
00137   myActionsMap[ FitRectId ] = aAction;
00138 
00139   // Zoom
00140   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_ZOOM" ) ),
00141                           tr( "MNU_ZOOM_VIEW" ), 0, this);
00142   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
00143   connect(aAction, SIGNAL(activated()), this, SLOT(onViewZoom()));
00144   myActionsMap[ ZoomId ] = aAction;
00145 
00146   // Panning
00147   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_PAN" ) ),
00148                           tr( "MNU_PAN_VIEW" ), 0, this);
00149   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
00150   connect(aAction, SIGNAL(activated()), this, SLOT(onViewPan()));
00151   myActionsMap[ PanId ] = aAction;
00152 
00153   // Global Panning
00154   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_GLOBALPAN" ) ),
00155                           tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
00156   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
00157   connect(aAction, SIGNAL(activated()), this, SLOT(onViewGlobalPan()));
00158   myActionsMap[ GlobalPanId ] = aAction;
00159 
00160   // Reset
00161   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "QxGraph", tr( "ICON_QXGRAPH_RESET" ) ),
00162                           tr( "MNU_RESET_VIEW" ), 0, this);
00163   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
00164   connect(aAction, SIGNAL(activated()), this, SLOT(onViewReset()));
00165   myActionsMap[ ResetId ] = aAction;
00166 }
00167 
00171 void QxGraph_ViewWindow::createToolBar()
00172 {
00173   SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
00174   aScaleBtn->AddAction(myActionsMap[FitAllId]);
00175   aScaleBtn->AddAction(myActionsMap[FitRectId]);
00176   aScaleBtn->AddAction(myActionsMap[ZoomId]);
00177 
00178   SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
00179   aPanningBtn->AddAction(myActionsMap[PanId]);
00180   aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
00181 
00182   myActionsMap[ResetId]->addTo(myToolBar);
00183 }
00184 
00188 QxGraph_ViewWindow::~QxGraph_ViewWindow() {}
00189 
00193 void QxGraph_ViewWindow::onViewReset()    
00194 {
00195   printf( "QxGraph_ViewWindow::onViewReset\n" );
00196   if ( myViewModel && myViewModel->getCurrentView() )
00197     myViewModel->getCurrentView()->activateReset();
00198 }
00199 
00203 void QxGraph_ViewWindow::onViewGlobalPan()
00204 {
00205   printf( "QxGraph_ViewWindow::onViewGlobalPan\n" );
00206   if ( myViewModel && myViewModel->getCurrentView() )
00207     myViewModel->getCurrentView()->activateGlobalPanning();
00208 }
00209 
00213 void QxGraph_ViewWindow::onViewZoom()
00214 {
00215   printf( "QxGraph_ViewWindow::onViewZoom\n" );
00216   if ( myViewModel && myViewModel->getCurrentView() )
00217     myViewModel->getCurrentView()->activateZoom();
00218 }
00219 
00223 void QxGraph_ViewWindow::onViewPan()
00224 {
00225   printf( "QxGraph_ViewWindow::onViewPan\n" );
00226   if ( myViewModel && myViewModel->getCurrentView() )
00227     myViewModel->getCurrentView()->activatePanning();
00228 }
00229 
00233 void QxGraph_ViewWindow::onViewFitArea()
00234 {
00235   printf( "QxGraph_ViewWindow::onViewFitArea\n" );
00236   if ( myViewModel && myViewModel->getCurrentView() )
00237     myViewModel->getCurrentView()->activateFitRect();
00238 }
00239 
00243 void QxGraph_ViewWindow::onViewFitAll()
00244 {
00245   printf( "QxGraph_ViewWindow::onViewFitAll\n" );
00246   if ( myViewModel && myViewModel->getCurrentView() )
00247     myViewModel->getCurrentView()->activateFitAll();
00248 }
00249 
00253 void QxGraph_ViewWindow::setBackgroundColor( const QColor& color )
00254 {
00255   if ( myViewModel && myViewModel->getCurrentView()) {
00256     myViewModel->getCurrentView()->canvas()->setBackgroundColor(color);
00257     myViewModel->getCurrentView()->setPaletteBackgroundColor(color.light(120));
00258   }
00259 }
00260 
00264 QColor QxGraph_ViewWindow::backgroundColor() const
00265 {
00266   if ( myViewModel && myViewModel->getCurrentView())
00267     return myViewModel->getCurrentView()->canvas()->backgroundColor();
00268   return QColor();
00269 }
00270 
00274 void QxGraph_ViewWindow::resizeEvent( QResizeEvent* theEvent )
00275 {
00276   //  QMainWindow::resizeEvent( theEvent );
00277   //if ( myView ) myView->resizeView( theEvent );
00278 }
00279 
00283 SUIT_ResourceMgr* QxGraph_ViewWindow::resMgr() const
00284 { 
00285   return SUIT_Session::session()->resourceMgr(); 
00286 }
00287