1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "QxGraph_ViewModel.h"
23 #include "QxGraph_ViewWindow.h"
24 #include "QxGraph_Canvas.h"
25 #include "QxGraph_CanvasView.h"
26 #include "QxGraph_Def.h"
27 #include "QxGraph_Prs.h"
29 #include "SUIT_Desktop.h"
30 #include "SUIT_ViewWindow.h"
31 #include "SUIT_Session.h"
33 #include <qcolordialog.h>
34 #include <qpopupmenu.h>
35 #include <qcanvas.h> // for addRectangleItem(...) method (can be removed in the future)
40 QxGraph_Viewer::QxGraph_Viewer()
45 printf("Construct QxGraph_Viewer\n");
46 //myCanvases.setAutoDelete(true);
47 //myCanvasViews.setAutoDelete(true);
53 QxGraph_Viewer::~QxGraph_Viewer()
55 if ( myCanvas ) delete myCanvas;
56 //if ( !myCanvases.isEmpty() ) myCanvases.clear();
57 if ( !myCanvasViews.isEmpty() ) myCanvasViews.clear();
62 Start initialization of view window
63 \param view - view window to be initialized
65 void QxGraph_Viewer::initView( QxGraph_ViewWindow* view )
72 // test add items into the current canvas view
73 QRect aRect(100,200,200,100);
74 QCanvasItem* aRectItem = aPrs->addRectangleItem(aRect);
78 aPA.putPoints(0, 6, 400,100, 500,70, 600,100, 600,200, 500,230, 400,200);
79 QCanvasItem* aPolyItem = aPrs->addPolygonItem(aPA);
82 QPoint aStart(500,300), aEnd(700,250);
83 QCanvasItem* aLineItem = aPrs->addLineItem(aStart, aEnd);
86 QCanvasItem* aEllipseItem = aPrs->addEllipseItem(200, 100, 30*16, 120*16);
87 aEllipseItem->setX(400);
88 aEllipseItem->setY(400);
89 //delete aEllipseItem;
91 QCanvasItem* aTextItem = aPrs->addTextItem("This is a QCanvasText item");
100 Creates new view window
101 \param theDesktop - main window of application
103 SUIT_ViewWindow* QxGraph_Viewer::createView(SUIT_Desktop* theDesktop)
105 QxGraph_ViewWindow* aRes = new QxGraph_ViewWindow( theDesktop, this );
111 Set view with index theIndex from myCanvasViews as current view
112 \param theIndex - the index of the view in the list
114 void QxGraph_Viewer::setCurrentView(int theIndex)
116 if ( theIndex >= 0 && theIndex < myCanvasViews.count() )
118 myCurrentView = myCanvasViews.at(theIndex);
119 myViewManager->getActiveView()->setCentralWidget(myCurrentView);
124 Builds popup for QxGraph viewer
126 void QxGraph_Viewer::contextMenuPopup(QPopupMenu* thePopup)
128 printf("QxGraph_Viewer::contextMenuPopup\n");
129 thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBgColor() ) );
131 thePopup->insertSeparator();
133 QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
134 if ( aView && !aView->getToolBar()->isVisible() )
135 thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
139 SLOT: called if background color is to be changed changed, passes new color to current canvas view
141 void QxGraph_Viewer::onChangeBgColor()
143 QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
146 QColor aColorActive = aView->backgroundColor();
148 QColor selColor = QColorDialog::getColor( aColorActive, aView);
149 if ( selColor.isValid() )
150 aView->setBackgroundColor(selColor);
154 SLOT: called when popup item "Show toolbar" is activated, shows toolbar of active view window
156 void QxGraph_Viewer::onShowToolbar() {
157 QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
159 aView->getToolBar()->show();