]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_ArrayView.cxx
Salome HOME
63d7ac2e0e91829293ded06e10803a99ebd93795
[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"), myMain, SLOT(addDataflowToStudy()));
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   myIsPanActivated = true;
84   viewport()->setMouseTracking(false);
85 }
86
87 void SUPERVGUI_ArrayView::ResetView()
88 {
89   setContentsPos(0,0);
90   QWMatrix m;
91   setWorldMatrix(m);
92 }
93
94 void SUPERVGUI_ArrayView::changeBackground()
95 {
96   QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
97   if ( aColor.isValid() ) {
98     // change background color for array view
99     canvas()->setBackgroundColor(aColor);
100     setPaletteBackgroundColor(aColor.light(120));
101     // change background color for canvas view
102     getMain()->getCanvasView()->canvas()->setBackgroundColor(aColor);
103     getMain()->getCanvasView()->setPaletteBackgroundColor(aColor.light(120));
104   }
105 }
106
107 void SUPERVGUI_ArrayView::contentsMousePressEvent(QMouseEvent* theEvent) {
108   myGlobalPoint = theEvent->globalPos();
109
110   if (((theEvent->button() == Qt::MidButton)
111        &&
112        (theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
113     myIsPanActivated = true;
114     viewport()->setMouseTracking(false); //widget only receives mouse move events when at least one 
115                                          //mouse button is pressed down while the mouse is being moved
116     myCursor = cursor();
117     setCursor(PanCursor);
118     return;
119   } 
120
121   QPoint thePoint = inverseWorldMatrix().map(theEvent->pos());
122   // compute collision rectangle
123   QRect aSel(thePoint.x()-MARGIN, thePoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
124
125   if (theEvent->button() == RightButton) {
126     QCanvasItemList l = canvas()->collisions(aSel);
127     for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
128       if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
129         SUPERVGUI_CanvasCellNodePrs* aNodePrs = (SUPERVGUI_CanvasCellNodePrs*) (*it);
130         QObject* anObj = aNodePrs->getObject(thePoint);
131         if (anObj->inherits("SUPERVGUI_CanvasCellNode")) {
132           myMain->showPopup(((SUPERVGUI_CanvasCellNode*)anObj)->getPopupMenu(viewport()), 
133                             theEvent);
134           return;
135         }
136       }
137     }
138
139     myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy());
140     myMain->showPopup(myPopup, theEvent);
141     return;
142   }
143 }
144
145 void SUPERVGUI_ArrayView::contentsMouseMoveEvent(QMouseEvent* theEvent) {
146   QPoint g = theEvent->globalPos();
147   if (myIsPanActivated) {
148     scrollBy(myGlobalPoint.x() - g.x(),
149              myGlobalPoint.y() - g.y());
150     myGlobalPoint = g;
151     return;
152   }
153
154   // QToolTip for title and label for SUPERVGUI_CanvasCellNode
155   SUPERVGUI_ToolTip* aTT = new SUPERVGUI_ToolTip(this);
156   QPoint aPoint1 = inverseWorldMatrix().map(theEvent->pos());
157   aTT->maybeTip(aPoint1);
158 }
159
160 void SUPERVGUI_ArrayView::contentsMouseReleaseEvent(QMouseEvent* theEvent) {
161   if (myIsPanActivated) {
162     myIsPanActivated = false;
163     viewport()->setMouseTracking(true);
164     setCursor(myCursor);
165   }
166 }
167
168 void SUPERVGUI_ToolTip::maybeTip(const QPoint& theP) {
169   // compute collision rectangle
170   QRect aSel(theP.x()-MARGIN, theP.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
171
172   QCanvasItemList l = ((SUPERVGUI_ArrayView*)parentWidget())->canvas()->collisions(aSel);
173   for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
174     if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
175       SUPERVGUI_CanvasCellNodePrs* aNodePrs = (SUPERVGUI_CanvasCellNodePrs*) (*it);
176       QObject* anObj = aNodePrs->getObject(theP);
177       if (anObj->inherits("SUPERVGUI_CanvasCellNode")) {
178         
179         QRect aTitleRect = aNodePrs->getTitleRect();
180         if (aTitleRect.contains(theP, true)) {
181           tip(aTitleRect, ((SUPERVGUI_CanvasCellNode*)anObj)->getEngine()->Name());
182           return;
183         }
184
185         QRect aLabelRect = aNodePrs->getLabelRect();
186         if (aLabelRect.contains(theP, true)) {
187           tip(aLabelRect, ((SUPERVGUI_CanvasCellNode*)anObj)->getLabelText());
188           return;
189         }
190       }
191     }
192   }
193 }