Back to index

salome-gui  6.5.0
QxGraph_ViewModel.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 #include "QxGraph_ViewModel.h"
00024 #include "QxGraph_ViewWindow.h"
00025 #include "QxGraph_Canvas.h"
00026 #include "QxGraph_CanvasView.h"
00027 #include "QxGraph_Def.h"
00028 #include "QxGraph_Prs.h"
00029 
00030 #include "SUIT_Desktop.h"
00031 #include "SUIT_ViewWindow.h"
00032 #include "SUIT_Session.h"
00033 
00034 #include <qcolordialog.h>
00035 #include <qpopupmenu.h>
00036 #include <qcanvas.h> // for addRectangleItem(...) method (can be removed in the future)
00037 
00041 QxGraph_Viewer::QxGraph_Viewer()
00042   :SUIT_ViewModel(),
00043    myCanvas(0),
00044    myCurrentView(0)
00045 {
00046   printf("Construct QxGraph_Viewer\n");
00047   //myCanvases.setAutoDelete(true);
00048   //myCanvasViews.setAutoDelete(true);
00049 }
00050 
00054 QxGraph_Viewer::~QxGraph_Viewer() 
00055 {
00056   if ( myCanvas ) delete myCanvas;
00057   //if ( !myCanvases.isEmpty() ) myCanvases.clear();
00058   if ( !myCanvasViews.isEmpty() ) myCanvasViews.clear();
00059   myCurrentView = 0;
00060 }
00061 
00066 void QxGraph_Viewer::initView( QxGraph_ViewWindow* view )
00067 {
00068   if ( view )
00069   {
00070     view->initLayout();
00071     
00072     /*
00073     // test add items into the current canvas view
00074     QRect aRect(100,200,200,100);
00075     QCanvasItem* aRectItem = aPrs->addRectangleItem(aRect);
00076     //delete aRectItem;
00077 
00078     QPointArray aPA(6);
00079     aPA.putPoints(0, 6, 400,100, 500,70, 600,100, 600,200, 500,230, 400,200);
00080     QCanvasItem* aPolyItem = aPrs->addPolygonItem(aPA);
00081     //delete aPolyItem;
00082 
00083     QPoint aStart(500,300), aEnd(700,250);
00084     QCanvasItem* aLineItem = aPrs->addLineItem(aStart, aEnd);
00085     //delete aLineItem;
00086 
00087     QCanvasItem* aEllipseItem = aPrs->addEllipseItem(200, 100, 30*16, 120*16);
00088     aEllipseItem->setX(400);
00089     aEllipseItem->setY(400);
00090     //delete aEllipseItem;
00091 
00092     QCanvasItem* aTextItem = aPrs->addTextItem("This is a QCanvasText item");
00093     aTextItem->setX(100);
00094     aTextItem->setY(500);
00095     //delete aTextItem;
00096     */
00097   }
00098 }
00099 
00104 SUIT_ViewWindow* QxGraph_Viewer::createView(SUIT_Desktop* theDesktop)
00105 {
00106   QxGraph_ViewWindow* aRes = new QxGraph_ViewWindow( theDesktop, this );
00107   initView( aRes );
00108   return aRes;
00109 }
00110 
00115 void QxGraph_Viewer::setCurrentView(int theIndex)
00116 {
00117   if ( theIndex >= 0 && theIndex < myCanvasViews.count() )
00118   {
00119     myCurrentView = myCanvasViews.at(theIndex);
00120     myViewManager->getActiveView()->setCentralWidget(myCurrentView);
00121   }
00122 }
00123 
00127 void QxGraph_Viewer::contextMenuPopup(QPopupMenu* thePopup)
00128 {
00129   printf("QxGraph_Viewer::contextMenuPopup\n");
00130   thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBgColor() ) );
00131 
00132   thePopup->insertSeparator();
00133 
00134   QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
00135   if ( aView && !aView->getToolBar()->isVisible() )
00136     thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
00137 }
00138 
00142 void QxGraph_Viewer::onChangeBgColor()
00143 {
00144   QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
00145   if( !aView )
00146     return;
00147   QColor aColorActive = aView->backgroundColor();
00148 
00149   QColor selColor = QColorDialog::getColor( aColorActive, aView);
00150   if ( selColor.isValid() )
00151     aView->setBackgroundColor(selColor);
00152 }
00153 
00157 void QxGraph_Viewer::onShowToolbar() {
00158   QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
00159   if ( aView )
00160     aView->getToolBar()->show();    
00161 }