]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_ArrayView.cxx
Salome HOME
9b15978c01617f84f502ac871733650b3209bd6d
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_ArrayView.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  SUPERV SUPERVGUI : GUI for Supervisor component
21 //
22 //  File   : SUPERVGUI_ArrayView.cxx
23 //  Author : 
24 //  Module : SUPERV
25
26 #include "SUPERVGUI.h"
27 #include "SUPERVGUI_ArrayView.h"
28 #include "SUPERVGUI_Main.h"
29 #include "SUPERVGUI_CanvasCellNodePrs.h"
30 #include "SUPERVGUI_CanvasLink.h"
31 #include "SUPERVGUI_CanvasPort.h"
32
33 #include <qcolordialog.h>
34
35 #if QT_VERSION >= 0x030005
36 QCursor PanCursor(Qt::SizeAllCursor);
37 #else
38 QCursor PanCursor(SizeAllCursor);
39 #endif
40
41 SUPERVGUI_ArrayView::SUPERVGUI_ArrayView(SUPERVGUI_CanvasArray* theArray, SUPERVGUI_Main* theMain):
42   QCanvasView(theArray, theMain),
43   myMain(theMain)
44 {
45   setName("TableView");
46
47   myIsPanActivated = false;
48
49   myAddStudyItem = 0;
50   myCursor = cursor();
51
52   viewport()->setMouseTracking(true); //widget receives mouse move events 
53                                       //even if no buttons are pressed down
54
55   myPopup = new QPopupMenu(viewport());
56
57   if (myMain->isEditable()) {
58     myPopup->insertItem(tr("MSG_ADD_NODE"), myMain, SLOT(addNode()));
59     myPopup->insertItem(tr("MSG_INS_FILE"), myMain, SLOT(insertFile()));
60     myPopup->insertSeparator();
61   }
62
63   QPopupMenu* aViewPopup = new QPopupMenu(viewport());
64   aViewPopup->insertItem(tr("POP_FULLVIEW"), myMain, SLOT(showCanvas()));
65   aViewPopup->insertItem(tr("POP_CONTROLVIEW"), myMain, SLOT(showContolFlow()));
66   aViewPopup->insertItem(tr("POP_TABLEVIEW"), myMain, SLOT(showCanvasTable()));
67
68   myPopup->insertItem(tr("POP_VIEW"), aViewPopup);
69   myPopup->insertSeparator();
70
71   /*QPopupMenu* aZoomPopup = new QPopupMenu(viewport());
72   aZoomPopup->insertItem("200%", this, SLOT(zoomIn()));
73   aZoomPopup->insertItem("100%", this, SLOT(zoomReset()));
74   aZoomPopup->insertItem("50%", this, SLOT(zoomOut()));
75   aZoomPopup->insertSeparator();
76   aZoomPopup->insertItem("Fit All", this, SLOT(fitAll()));
77
78   myPopup->insertItem("Zoom", aZoomPopup);
79   myPopup->insertSeparator();*/
80
81   myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), myMain, SLOT(addDataflowToStudy()));
82   myPopup->insertItem(tr("MSG_CHANGE_INFO"), myMain, SLOT(changeInformation()));
83   myPopup->insertSeparator();
84
85   myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), myMain, SLOT(copy()));
86   myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), myMain, SLOT(filterNotification()));
87
88   myPopup->insertSeparator();
89   myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
90
91   SUPERVGraph_ViewFrame* anActiveVF = (SUPERVGraph_ViewFrame*)myMain->parent();
92   if ( anActiveVF ) {
93     myPopup->insertSeparator();
94     myShowToolBarItem = myPopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), myMain, SLOT( onShowToolbar() ) );
95   }
96
97   hide();
98 }
99  
100
101 SUPERVGUI_ArrayView::~SUPERVGUI_ArrayView()
102 {
103 }
104
105 void SUPERVGUI_ArrayView::ActivatePanning()
106 {
107   myIsPanActivated = true;
108   viewport()->setMouseTracking(false);
109 }
110
111 void SUPERVGUI_ArrayView::ResetView()
112 {
113   setContentsPos(0,0);
114   QWMatrix m;
115   setWorldMatrix(m);
116 }
117
118 void SUPERVGUI_ArrayView::changeBackground()
119 {
120   QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
121   if ( aColor.isValid() ) {
122     // change background color for array view
123     canvas()->setBackgroundColor(aColor);
124     setPaletteBackgroundColor(aColor.light(120));
125     // change background color for canvas view
126     getMain()->getCanvasView()->canvas()->setBackgroundColor(aColor);
127     getMain()->getCanvasView()->setPaletteBackgroundColor(aColor.light(120));
128
129     // mkr : IPAL10825 -->
130     SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
131     if ( !aSupMod ) {
132       MESSAGE("NULL Supervision module!");
133       return;
134     }
135     aSupMod->setIVFBackgroundColor(aColor);
136     // <--
137   }
138 }
139
140 void SUPERVGUI_ArrayView::resizeEvent( QResizeEvent* e) {
141   QCanvasView::resizeEvent( e );
142   canvas()->resize( e->size().width() > canvas()->width() ? e->size().width() : canvas()->width(), 
143                     e->size().height() > canvas()->height() ? e->size().height() : canvas()->height() );
144 }
145
146 void SUPERVGUI_ArrayView::contentsMousePressEvent(QMouseEvent* theEvent) {
147   myGlobalPoint = theEvent->globalPos();
148
149   if (((theEvent->button() == Qt::MidButton)
150        &&
151        (theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
152     myIsPanActivated = true;
153     viewport()->setMouseTracking(false); //widget only receives mouse move events when at least one 
154                                          //mouse button is pressed down while the mouse is being moved
155     myCursor = cursor();
156     setCursor(PanCursor);
157     return;
158   } 
159
160   QPoint thePoint = inverseWorldMatrix().map(theEvent->pos());
161   // compute collision rectangle
162   QRect aSel(thePoint.x()-MARGIN, thePoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
163
164   if (theEvent->button() == RightButton) {
165     QCanvasItemList l = canvas()->collisions(aSel);
166     for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
167       if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
168         SUPERVGUI_CanvasCellNodePrs* aNodePrs = (SUPERVGUI_CanvasCellNodePrs*) (*it);
169         QObject* anObj = aNodePrs->getObject(thePoint);
170         if (anObj->inherits("SUPERVGUI_CanvasCellNode")) {
171           myMain->showPopup(((SUPERVGUI_CanvasCellNode*)anObj)->getPopupMenu(viewport()), 
172                             theEvent);
173           return;
174         }
175       }
176     }
177
178     myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy());
179     myPopup->setItemEnabled(myShowToolBarItem, !((SUPERVGraph_ViewFrame*)myMain->parent())->getToolBar()->isVisible());
180     myMain->showPopup(myPopup, theEvent);
181     return;
182   }
183 }
184
185 void SUPERVGUI_ArrayView::contentsMouseMoveEvent(QMouseEvent* theEvent) {
186   QPoint g = theEvent->globalPos();
187   if (myIsPanActivated) {
188     scrollBy(myGlobalPoint.x() - g.x(),
189              myGlobalPoint.y() - g.y());
190     myGlobalPoint = g;
191     return;
192   }
193
194   // QToolTip for title and label for SUPERVGUI_CanvasCellNode
195   SUPERVGUI_ToolTip* aTT = new SUPERVGUI_ToolTip(this);
196   QPoint aPoint1 = inverseWorldMatrix().map(theEvent->pos());
197   aTT->maybeTip(aPoint1);
198 }
199
200 void SUPERVGUI_ArrayView::contentsMouseReleaseEvent(QMouseEvent* theEvent) {
201   if (myIsPanActivated) {
202     myIsPanActivated = false;
203     viewport()->setMouseTracking(true);
204     setCursor(myCursor);
205   }
206 }
207
208 void SUPERVGUI_ToolTip::maybeTip(const QPoint& theP) {
209   // compute collision rectangle
210   QRect aSel(theP.x()-MARGIN, theP.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
211
212   QCanvasItemList l = ((QCanvasView*)parentWidget())->canvas()->collisions(aSel);
213   for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
214     // tooltip for node
215     if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
216       SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
217       QObject* anObj = aNodePrs->getObject(theP);
218       if (anObj->inherits("SUPERVGUI_CanvasNode")) {
219         
220         QRect aTitleRect = aNodePrs->getTitleRect();
221         QRect aLabelRect = aNodePrs->getLabelRect();
222         QRect aStatusRect = aNodePrs->getStatusRect();
223
224         if (aTitleRect.bottom()+1 == aLabelRect.top() &&
225             aLabelRect.bottom()+1 == aStatusRect.top()) {
226           QRect aTipRect(aTitleRect.left(), aTitleRect.top(), aTitleRect.width(),
227                          aTitleRect.height() + aLabelRect.height() + aStatusRect.height());
228           tip(aTipRect, ((SUPERVGUI_CanvasNode*)anObj)->getToolTipText());
229           return;
230         }
231
232         if (aTitleRect.contains(theP, true)) {
233           tip(aTitleRect, ((SUPERVGUI_CanvasNode*)anObj)->getToolTipText());
234           return;
235         }
236
237         if (aLabelRect.contains(theP, true)) {
238           tip(aLabelRect, ((SUPERVGUI_CanvasNode*)anObj)->getToolTipText());
239           return;
240         }
241
242         if (aStatusRect.contains(theP, true)) {
243           tip(aStatusRect, ((SUPERVGUI_CanvasNode*)anObj)->getToolTipText());
244           return;
245         }
246         
247       }
248       // tooltip for nodes' port
249       if (anObj->inherits("SUPERVGUI_CanvasPort")) {
250         SUPERVGUI_CanvasPort* aPort = (SUPERVGUI_CanvasPort*)anObj;
251         tip(aPort->getPrs()->getPortRect(), 
252             aPort->getEngine()->Type() + QString(" ") + aPort->getPrs()->getText());
253         return;
254       }
255     }
256     // tootip for links' point
257     if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
258         SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
259         if (aPrs->getLink()->getMain()->getViewType() == CANVAS)
260           tip(aSel, aPrs->getLink()->getToolTipText());
261         return;
262     }
263     // tooltip for links' edge
264     if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
265         SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
266         if (aPrs->getLink()->getMain()->getViewType() == CANVAS)
267           tip(aSel, aPrs->getLink()->getToolTipText());
268         return;
269     }
270   }
271 }