1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE
5 // File : SUPERVGUI_ArrayView.cxx
11 #include "SUPERVGUI_ArrayView.h"
12 #include "SUPERVGUI_Main.h"
13 #include "SUPERVGUI_CanvasCellNodePrs.h"
15 #include <qcolordialog.h>
17 #if QT_VERSION >= 0x030005
18 QCursor PanCursor(Qt::SizeAllCursor);
20 QCursor PanCursor(SizeAllCursor);
23 SUPERVGUI_ArrayView::SUPERVGUI_ArrayView(SUPERVGUI_CanvasArray* theArray, SUPERVGUI_Main* theMain):
24 QCanvasView(theArray, theMain),
29 myIsPanActivated = false;
34 viewport()->setMouseTracking(true); //widget receives mouse move events
35 //even if no buttons are pressed down
37 myPopup = new QPopupMenu(viewport());
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();
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()));
50 myPopup->insertItem(tr("POP_VIEW"), aViewPopup);
51 myPopup->insertSeparator();
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()));
60 myPopup->insertItem("Zoom", aZoomPopup);
61 myPopup->insertSeparator();*/
63 myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), myMain, SLOT(addDataflowToStudy()));
64 myPopup->insertItem(tr("MSG_CHANGE_INFO"), myMain, SLOT(changeInformation()));
65 myPopup->insertSeparator();
67 myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), myMain, SLOT(copy()));
68 myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), myMain, SLOT(filterNotification()));
70 myPopup->insertSeparator();
71 myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
73 SUPERVGraph_ViewFrame* anActiveVF = (SUPERVGraph_ViewFrame*)myMain->parent();
75 myPopup->insertSeparator();
76 myShowToolBarItem = myPopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), myMain, SLOT( onShowToolbar() ) );
83 SUPERVGUI_ArrayView::~SUPERVGUI_ArrayView()
87 void SUPERVGUI_ArrayView::ActivatePanning()
89 myIsPanActivated = true;
90 viewport()->setMouseTracking(false);
93 void SUPERVGUI_ArrayView::ResetView()
100 void SUPERVGUI_ArrayView::changeBackground()
102 QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
103 if ( aColor.isValid() ) {
104 // change background color for array view
105 canvas()->setBackgroundColor(aColor);
106 setPaletteBackgroundColor(aColor.light(120));
107 // change background color for canvas view
108 getMain()->getCanvasView()->canvas()->setBackgroundColor(aColor);
109 getMain()->getCanvasView()->setPaletteBackgroundColor(aColor.light(120));
113 void SUPERVGUI_ArrayView::resizeEvent( QResizeEvent* e) {
114 QCanvasView::resizeEvent( e );
115 canvas()->resize( e->size().width() > canvas()->width() ? e->size().width() : canvas()->width(),
116 e->size().height() > canvas()->height() ? e->size().height() : canvas()->height() );
119 void SUPERVGUI_ArrayView::contentsMousePressEvent(QMouseEvent* theEvent) {
120 myGlobalPoint = theEvent->globalPos();
122 if (((theEvent->button() == Qt::MidButton)
124 (theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
125 myIsPanActivated = true;
126 viewport()->setMouseTracking(false); //widget only receives mouse move events when at least one
127 //mouse button is pressed down while the mouse is being moved
129 setCursor(PanCursor);
133 QPoint thePoint = inverseWorldMatrix().map(theEvent->pos());
134 // compute collision rectangle
135 QRect aSel(thePoint.x()-MARGIN, thePoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
137 if (theEvent->button() == RightButton) {
138 QCanvasItemList l = canvas()->collisions(aSel);
139 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
140 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
141 SUPERVGUI_CanvasCellNodePrs* aNodePrs = (SUPERVGUI_CanvasCellNodePrs*) (*it);
142 QObject* anObj = aNodePrs->getObject(thePoint);
143 if (anObj->inherits("SUPERVGUI_CanvasCellNode")) {
144 myMain->showPopup(((SUPERVGUI_CanvasCellNode*)anObj)->getPopupMenu(viewport()),
151 myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy());
152 myPopup->setItemEnabled(myShowToolBarItem, !((SUPERVGraph_ViewFrame*)myMain->parent())->getToolBar()->isVisible());
153 myMain->showPopup(myPopup, theEvent);
158 void SUPERVGUI_ArrayView::contentsMouseMoveEvent(QMouseEvent* theEvent) {
159 QPoint g = theEvent->globalPos();
160 if (myIsPanActivated) {
161 scrollBy(myGlobalPoint.x() - g.x(),
162 myGlobalPoint.y() - g.y());
167 // QToolTip for title and label for SUPERVGUI_CanvasCellNode
168 SUPERVGUI_ToolTip* aTT = new SUPERVGUI_ToolTip(this);
169 QPoint aPoint1 = inverseWorldMatrix().map(theEvent->pos());
170 aTT->maybeTip(aPoint1);
173 void SUPERVGUI_ArrayView::contentsMouseReleaseEvent(QMouseEvent* theEvent) {
174 if (myIsPanActivated) {
175 myIsPanActivated = false;
176 viewport()->setMouseTracking(true);
181 void SUPERVGUI_ToolTip::maybeTip(const QPoint& theP) {
182 // compute collision rectangle
183 QRect aSel(theP.x()-MARGIN, theP.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
185 QCanvasItemList l = ((SUPERVGUI_ArrayView*)parentWidget())->canvas()->collisions(aSel);
186 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
187 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
188 SUPERVGUI_CanvasCellNodePrs* aNodePrs = (SUPERVGUI_CanvasCellNodePrs*) (*it);
189 QObject* anObj = aNodePrs->getObject(theP);
190 if (anObj->inherits("SUPERVGUI_CanvasCellNode")) {
192 QRect aTitleRect = aNodePrs->getTitleRect();
193 if (aTitleRect.contains(theP, true)) {
194 tip(aTitleRect, ((SUPERVGUI_CanvasCellNode*)anObj)->getEngine()->Name());
198 QRect aLabelRect = aNodePrs->getLabelRect();
199 if (aLabelRect.contains(theP, true)) {
200 tip(aLabelRect, ((SUPERVGUI_CanvasCellNode*)anObj)->getLabelText());