1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE
5 // File : SUPERVGUI_ArrayView.cxx
10 #include "SUPERVGUI_ArrayView.h"
11 #include "SUPERVGUI_Main.h"
12 #include "SUPERVGUI_CanvasCellNodePrs.h"
13 #include "SUPERVGUI_CanvasLink.h"
14 #include "SUPERVGUI_CanvasPort.h"
16 #include <qcolordialog.h>
18 #if QT_VERSION >= 0x030005
19 QCursor PanCursor(Qt::SizeAllCursor);
21 QCursor PanCursor(SizeAllCursor);
24 SUPERVGUI_ArrayView::SUPERVGUI_ArrayView(SUPERVGUI_CanvasArray* theArray, SUPERVGUI_Main* theMain):
25 QCanvasView(theArray, theMain),
30 myIsPanActivated = false;
35 viewport()->setMouseTracking(true); //widget receives mouse move events
36 //even if no buttons are pressed down
38 myPopup = new QPopupMenu(viewport());
40 if (myMain->isEditable()) {
41 myPopup->insertItem(tr("MSG_ADD_NODE"), myMain, SLOT(addNode()));
42 myPopup->insertItem(tr("MSG_INS_FILE"), myMain, SLOT(insertFile()));
43 myPopup->insertSeparator();
46 QPopupMenu* aViewPopup = new QPopupMenu(viewport());
47 aViewPopup->insertItem(tr("POP_FULLVIEW"), myMain, SLOT(showCanvas()));
48 aViewPopup->insertItem(tr("POP_CONTROLVIEW"), myMain, SLOT(showContolFlow()));
49 aViewPopup->insertItem(tr("POP_TABLEVIEW"), myMain, SLOT(showCanvasTable()));
51 myPopup->insertItem(tr("POP_VIEW"), aViewPopup);
52 myPopup->insertSeparator();
54 /*QPopupMenu* aZoomPopup = new QPopupMenu(viewport());
55 aZoomPopup->insertItem("200%", this, SLOT(zoomIn()));
56 aZoomPopup->insertItem("100%", this, SLOT(zoomReset()));
57 aZoomPopup->insertItem("50%", this, SLOT(zoomOut()));
58 aZoomPopup->insertSeparator();
59 aZoomPopup->insertItem("Fit All", this, SLOT(fitAll()));
61 myPopup->insertItem("Zoom", aZoomPopup);
62 myPopup->insertSeparator();*/
64 myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), myMain, SLOT(addDataflowToStudy()));
65 myPopup->insertItem(tr("MSG_CHANGE_INFO"), myMain, SLOT(changeInformation()));
66 myPopup->insertSeparator();
68 myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), myMain, SLOT(copy()));
69 myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), myMain, SLOT(filterNotification()));
71 myPopup->insertSeparator();
72 myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
74 SUPERVGraph_ViewFrame* anActiveVF = (SUPERVGraph_ViewFrame*)myMain->parent();
76 myPopup->insertSeparator();
77 myShowToolBarItem = myPopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), myMain, SLOT( onShowToolbar() ) );
84 SUPERVGUI_ArrayView::~SUPERVGUI_ArrayView()
88 void SUPERVGUI_ArrayView::ActivatePanning()
90 myIsPanActivated = true;
91 viewport()->setMouseTracking(false);
94 void SUPERVGUI_ArrayView::ResetView()
101 void SUPERVGUI_ArrayView::changeBackground()
103 QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
104 if ( aColor.isValid() ) {
105 // change background color for array view
106 canvas()->setBackgroundColor(aColor);
107 setPaletteBackgroundColor(aColor.light(120));
108 // change background color for canvas view
109 getMain()->getCanvasView()->canvas()->setBackgroundColor(aColor);
110 getMain()->getCanvasView()->setPaletteBackgroundColor(aColor.light(120));
112 // mkr : IPAL10825 -->
113 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
115 MESSAGE("NULL Supervision module!");
118 aSupMod->setIVFBackgroundColor(aColor);
123 void SUPERVGUI_ArrayView::resizeEvent( QResizeEvent* e) {
124 QCanvasView::resizeEvent( e );
125 canvas()->resize( e->size().width() > canvas()->width() ? e->size().width() : canvas()->width(),
126 e->size().height() > canvas()->height() ? e->size().height() : canvas()->height() );
129 void SUPERVGUI_ArrayView::contentsMousePressEvent(QMouseEvent* theEvent) {
130 myGlobalPoint = theEvent->globalPos();
132 if (((theEvent->button() == Qt::MidButton)
134 (theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
135 myIsPanActivated = true;
136 viewport()->setMouseTracking(false); //widget only receives mouse move events when at least one
137 //mouse button is pressed down while the mouse is being moved
139 setCursor(PanCursor);
143 QPoint thePoint = inverseWorldMatrix().map(theEvent->pos());
144 // compute collision rectangle
145 QRect aSel(thePoint.x()-MARGIN, thePoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
147 if (theEvent->button() == RightButton) {
148 QCanvasItemList l = canvas()->collisions(aSel);
149 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
150 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
151 SUPERVGUI_CanvasCellNodePrs* aNodePrs = (SUPERVGUI_CanvasCellNodePrs*) (*it);
152 QObject* anObj = aNodePrs->getObject(thePoint);
153 if (anObj->inherits("SUPERVGUI_CanvasCellNode")) {
154 myMain->showPopup(((SUPERVGUI_CanvasCellNode*)anObj)->getPopupMenu(viewport()),
161 myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy());
162 myPopup->setItemEnabled(myShowToolBarItem, !((SUPERVGraph_ViewFrame*)myMain->parent())->getToolBar()->isVisible());
163 myMain->showPopup(myPopup, theEvent);
168 void SUPERVGUI_ArrayView::contentsMouseMoveEvent(QMouseEvent* theEvent) {
169 QPoint g = theEvent->globalPos();
170 if (myIsPanActivated) {
171 scrollBy(myGlobalPoint.x() - g.x(),
172 myGlobalPoint.y() - g.y());
177 // QToolTip for title and label for SUPERVGUI_CanvasCellNode
178 SUPERVGUI_ToolTip* aTT = new SUPERVGUI_ToolTip(this);
179 QPoint aPoint1 = inverseWorldMatrix().map(theEvent->pos());
180 aTT->maybeTip(aPoint1);
183 void SUPERVGUI_ArrayView::contentsMouseReleaseEvent(QMouseEvent* theEvent) {
184 if (myIsPanActivated) {
185 myIsPanActivated = false;
186 viewport()->setMouseTracking(true);
191 void SUPERVGUI_ToolTip::maybeTip(const QPoint& theP) {
192 // compute collision rectangle
193 QRect aSel(theP.x()-MARGIN, theP.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
195 QCanvasItemList l = ((QCanvasView*)parentWidget())->canvas()->collisions(aSel);
196 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
198 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
199 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
200 QObject* anObj = aNodePrs->getObject(theP);
201 if (anObj->inherits("SUPERVGUI_CanvasNode")) {
203 QRect aTitleRect = aNodePrs->getTitleRect();
204 QRect aLabelRect = aNodePrs->getLabelRect();
205 QRect aStatusRect = aNodePrs->getStatusRect();
207 if (aTitleRect.bottom()+1 == aLabelRect.top() &&
208 aLabelRect.bottom()+1 == aStatusRect.top()) {
209 QRect aTipRect(aTitleRect.left(), aTitleRect.top(), aTitleRect.width(),
210 aTitleRect.height() + aLabelRect.height() + aStatusRect.height());
211 tip(aTipRect, ((SUPERVGUI_CanvasNode*)anObj)->getToolTipText());
215 if (aTitleRect.contains(theP, true)) {
216 tip(aTitleRect, ((SUPERVGUI_CanvasNode*)anObj)->getToolTipText());
220 if (aLabelRect.contains(theP, true)) {
221 tip(aLabelRect, ((SUPERVGUI_CanvasNode*)anObj)->getToolTipText());
225 if (aStatusRect.contains(theP, true)) {
226 tip(aStatusRect, ((SUPERVGUI_CanvasNode*)anObj)->getToolTipText());
231 // tooltip for nodes' port
232 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
233 SUPERVGUI_CanvasPort* aPort = (SUPERVGUI_CanvasPort*)anObj;
234 tip(aPort->getPrs()->getPortRect(),
235 aPort->getEngine()->Type() + QString(" ") + aPort->getPrs()->getText());
239 // tootip for links' point
240 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
241 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
242 if (aPrs->getLink()->getMain()->getViewType() == CANVAS)
243 tip(aSel, aPrs->getLink()->getToolTipText());
246 // tooltip for links' edge
247 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
248 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
249 if (aPrs->getLink()->getMain()->getViewType() == CANVAS)
250 tip(aSel, aPrs->getLink()->getToolTipText());