Salome HOME
Remove dublicate "Canvas Table" menu item from dataflow view popup menu.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_ArrayView.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 //
5 //  File   : SUPERVGUI_ArrayView.cxx
6 //  Author : 
7 //  Module : SUPERV
8
9
10 using namespace std;
11 #include "SUPERVGUI_ArrayView.h"
12 #include "SUPERVGUI_Main.h"
13 #include "SUPERVGUI_CanvasCellNodePrs.h"
14
15 #include <qcolordialog.h>
16
17 #if QT_VERSION >= 0x030005
18 QCursor PanCursor(Qt::SizeAllCursor);
19 #else
20 QCursor PanCursor(SizeAllCursor);
21 #endif
22
23 SUPERVGUI_ArrayView::SUPERVGUI_ArrayView(SUPERVGUI_CanvasArray* theArray, SUPERVGUI_Main* theMain):
24   QCanvasView(theArray, theMain),
25   myMain(theMain)
26 {
27   setName("TableView");
28
29   myIsPanActivated = false;
30
31   myAddStudyItem = 0;
32   myCursor = cursor();
33
34   viewport()->setMouseTracking(true); //widget receives mouse move events 
35                                       //even if no buttons are pressed down
36
37   myPopup = new QPopupMenu(viewport());
38
39   if (myMain->isEditable()) {
40     myPopup->insertItem(tr("MSG_ADD_NODE"), myMain, SLOT(addNode()));
41     myPopup->insertItem(tr("MSG_INS_FILE"), myMain, SLOT(insertFile()));
42     myPopup->insertSeparator();
43   }
44
45   QPopupMenu* aViewPopup = new QPopupMenu(viewport());
46   aViewPopup->insertItem(tr("POP_FULLVIEW"), myMain, SLOT(showCanvas()));
47   aViewPopup->insertItem(tr("POP_CONTROLVIEW"), myMain, SLOT(showContolFlow()));
48   aViewPopup->insertItem(tr("POP_TABLEVIEW"), myMain, SLOT(showCanvasTable()));
49
50   myPopup->insertItem(tr("POP_VIEW"), aViewPopup);
51   myPopup->insertSeparator();
52
53   /*QPopupMenu* aZoomPopup = new QPopupMenu(viewport());
54   aZoomPopup->insertItem("200%", this, SLOT(zoomIn()));
55   aZoomPopup->insertItem("100%", this, SLOT(zoomReset()));
56   aZoomPopup->insertItem("50%", this, SLOT(zoomOut()));
57   aZoomPopup->insertSeparator();
58   aZoomPopup->insertItem("Fit All", this, SLOT(fitAll()));
59
60   myPopup->insertItem("Zoom", aZoomPopup);
61   myPopup->insertSeparator();*/
62
63   myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), this, SLOT(addToStudy()));
64   myPopup->insertItem(tr("MSG_CHANGE_INFO"), myMain, SLOT(changeInformation()));
65   myPopup->insertSeparator();
66
67   myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), myMain, SLOT(copy()));
68   myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), myMain, SLOT(filterNotification()));
69
70   myPopup->insertSeparator();
71   myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
72  
73   hide();
74 }
75  
76
77 SUPERVGUI_ArrayView::~SUPERVGUI_ArrayView()
78 {
79 }
80
81 void SUPERVGUI_ArrayView::ActivatePanning()
82 {
83   cout<<" ===> SUPERVGUI_ArrayView::ActivatePanning()"<<endl;
84   myIsPanActivated = true;
85   viewport()->setMouseTracking(false);
86 }
87
88 void SUPERVGUI_ArrayView::ResetView()
89 {
90   setContentsPos(0,0);
91   QWMatrix m;
92   setWorldMatrix(m);
93 }
94
95 void SUPERVGUI_ArrayView::addToStudy() 
96 {
97   if (myMain->addStudy()) myMain->setAsFromStudy(true);
98 }
99
100 void SUPERVGUI_ArrayView::changeBackground()
101 {
102   QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
103   if ( aColor.isValid() ) {
104     canvas()->setBackgroundColor(aColor);
105     setPaletteBackgroundColor(aColor.light(120));
106   }
107 }
108
109 void SUPERVGUI_ArrayView::contentsMousePressEvent(QMouseEvent* theEvent) {
110   myGlobalPoint = theEvent->globalPos();
111
112   cout<<" ===> myIsPanActivated = "<<myIsPanActivated<<endl;
113   if (((theEvent->button() == Qt::MidButton)
114        &&
115        (theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
116     myIsPanActivated = true;
117     viewport()->setMouseTracking(false); //widget only receives mouse move events when at least one 
118                                          //mouse button is pressed down while the mouse is being moved
119     myCursor = cursor();
120     setCursor(PanCursor);
121     return;
122   } 
123
124   QPoint thePoint = inverseWorldMatrix().map(theEvent->pos());
125   // compute collision rectangle
126   QRect aSel(thePoint.x()-MARGIN, thePoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
127
128   if (theEvent->button() == RightButton) {
129     QCanvasItemList l = canvas()->collisions(aSel);
130     for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
131       if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
132         SUPERVGUI_CanvasCellNodePrs* aNodePrs = (SUPERVGUI_CanvasCellNodePrs*) (*it);
133         QObject* anObj = aNodePrs->getObject(thePoint);
134         if (anObj->inherits("SUPERVGUI_CanvasCellNode")) {
135           myMain->showPopup(((SUPERVGUI_CanvasCellNode*)anObj)->getPopupMenu(viewport()), 
136                             theEvent);
137           return;
138         }
139       }
140     }
141
142     myPopup->setItemEnabled(myAddStudyItem, !myMain->isFromStudy());
143     myMain->showPopup(myPopup, theEvent);
144     return;
145   }
146 }
147
148 void SUPERVGUI_ArrayView::contentsMouseMoveEvent(QMouseEvent* theEvent) {
149   QPoint g = theEvent->globalPos();
150   if (myIsPanActivated) {
151     scrollBy(myGlobalPoint.x() - g.x(),
152              myGlobalPoint.y() - g.y());
153     myGlobalPoint = g;
154     return;
155   }
156
157   // QToolTip for title and label for SUPERVGUI_CanvasCellNode
158   SUPERVGUI_ToolTip* aTT = new SUPERVGUI_ToolTip(this);
159   QPoint aPoint1 = inverseWorldMatrix().map(theEvent->pos());
160   aTT->maybeTip(aPoint1);
161 }
162
163 void SUPERVGUI_ArrayView::contentsMouseReleaseEvent(QMouseEvent* theEvent) {
164   if (myIsPanActivated) {
165     myIsPanActivated = false;
166     viewport()->setMouseTracking(true);
167     setCursor(myCursor);
168   }
169 }
170
171 void SUPERVGUI_ToolTip::maybeTip(const QPoint& theP) {
172   // compute collision rectangle
173   QRect aSel(theP.x()-MARGIN, theP.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
174
175   QCanvasItemList l = ((SUPERVGUI_ArrayView*)parentWidget())->canvas()->collisions(aSel);
176   for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
177     if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
178       SUPERVGUI_CanvasCellNodePrs* aNodePrs = (SUPERVGUI_CanvasCellNodePrs*) (*it);
179       QObject* anObj = aNodePrs->getObject(theP);
180       if (anObj->inherits("SUPERVGUI_CanvasCellNode")) {
181         
182         QRect aTitleRect = aNodePrs->getTitleRect();
183         if (aTitleRect.contains(theP, true)) {
184           tip(aTitleRect, ((SUPERVGUI_CanvasCellNode*)anObj)->getEngine()->Name());
185           return;
186         }
187
188         QRect aLabelRect = aNodePrs->getLabelRect();
189         if (aLabelRect.contains(theP, true)) {
190           tip(aLabelRect, ((SUPERVGUI_CanvasCellNode*)anObj)->getLabelText());
191           return;
192         }
193       }
194     }
195   }
196 }