1 // Copyright (C) 2007-2012 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
23 #include "QxGraph_ViewModel.h"
24 #include "QxGraph_ViewWindow.h"
25 #include "QxGraph_Canvas.h"
26 #include "QxGraph_CanvasView.h"
27 #include "QxGraph_Def.h"
28 #include "QxGraph_Prs.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_ViewWindow.h"
32 #include "SUIT_Session.h"
34 #include <qcolordialog.h>
35 #include <qpopupmenu.h>
36 #include <qcanvas.h> // for addRectangleItem(...) method (can be removed in the future)
41 QxGraph_Viewer::QxGraph_Viewer()
46 printf("Construct QxGraph_Viewer\n");
47 //myCanvases.setAutoDelete(true);
48 //myCanvasViews.setAutoDelete(true);
54 QxGraph_Viewer::~QxGraph_Viewer()
56 if ( myCanvas ) delete myCanvas;
57 //if ( !myCanvases.isEmpty() ) myCanvases.clear();
58 if ( !myCanvasViews.isEmpty() ) myCanvasViews.clear();
63 Start initialization of view window
64 \param view - view window to be initialized
66 void QxGraph_Viewer::initView( QxGraph_ViewWindow* view )
73 // test add items into the current canvas view
74 QRect aRect(100,200,200,100);
75 QCanvasItem* aRectItem = aPrs->addRectangleItem(aRect);
79 aPA.putPoints(0, 6, 400,100, 500,70, 600,100, 600,200, 500,230, 400,200);
80 QCanvasItem* aPolyItem = aPrs->addPolygonItem(aPA);
83 QPoint aStart(500,300), aEnd(700,250);
84 QCanvasItem* aLineItem = aPrs->addLineItem(aStart, aEnd);
87 QCanvasItem* aEllipseItem = aPrs->addEllipseItem(200, 100, 30*16, 120*16);
88 aEllipseItem->setX(400);
89 aEllipseItem->setY(400);
90 //delete aEllipseItem;
92 QCanvasItem* aTextItem = aPrs->addTextItem("This is a QCanvasText item");
101 Creates new view window
102 \param theDesktop - main window of application
104 SUIT_ViewWindow* QxGraph_Viewer::createView(SUIT_Desktop* theDesktop)
106 QxGraph_ViewWindow* aRes = new QxGraph_ViewWindow( theDesktop, this );
112 Set view with index theIndex from myCanvasViews as current view
113 \param theIndex - the index of the view in the list
115 void QxGraph_Viewer::setCurrentView(int theIndex)
117 if ( theIndex >= 0 && theIndex < myCanvasViews.count() )
119 myCurrentView = myCanvasViews.at(theIndex);
120 myViewManager->getActiveView()->setCentralWidget(myCurrentView);
125 Builds popup for QxGraph viewer
127 void QxGraph_Viewer::contextMenuPopup(QPopupMenu* thePopup)
129 printf("QxGraph_Viewer::contextMenuPopup\n");
130 thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBgColor() ) );
132 thePopup->insertSeparator();
134 QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
135 if ( aView && !aView->getToolBar()->isVisible() )
136 thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
140 SLOT: called if background color is to be changed changed, passes new color to current canvas view
142 void QxGraph_Viewer::onChangeBgColor()
144 QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
147 QColor aColorActive = aView->backgroundColor();
149 QColor selColor = QColorDialog::getColor( aColorActive, aView);
150 if ( selColor.isValid() )
151 aView->setBackgroundColor(selColor);
155 SLOT: called when popup item "Show toolbar" is activated, shows toolbar of active view window
157 void QxGraph_Viewer::onShowToolbar() {
158 QxGraph_ViewWindow* aView = (QxGraph_ViewWindow*)(myViewManager->getActiveView());
160 aView->getToolBar()->show();