1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SUPERVGUI_View.cxx
8 // Author : Vitaly SMETANNIKOV
12 #include "SUPERVGUI_View.h"
13 #include "SUPERVGUI_Main.h"
14 #include "QAD_Config.h"
15 #include <qcolordialog.h>
18 #if QT_VERSION >= 0x030005
19 QCursor panCursor(Qt::SizeAllCursor);
21 QCursor panCursor(SizeAllCursor);
24 SUPERVGUI_View::SUPERVGUI_View(SUPERVGUI_Main* theMain):
25 QScrollView(theMain, 0, Qt::WRepaintNoErase),
28 myIsPanActivated = false;
38 // myLastMinVisX = horizontalScrollBar()->value(); //viewport()->x();
39 // myLastMinVisY = verticalScrollBar()->value(); //viewport()->y();
41 myPopup = new QPopupMenu(viewport());
43 if (main->isEditable()) {
44 myPopup->insertItem(tr("MSG_ADD_NODE"), main, SLOT(addNode()));
45 myPopup->insertItem(tr("MSG_INS_FILE"), main, SLOT(insertFile()));
46 myPopup->insertSeparator();
49 myViewPopup = new QPopupMenu(viewport());
50 // myViewPopup->insertItem(tr("POP_FULLVIEW"), main, SLOT(showFullGraph()));
51 myViewPopup->insertItem(tr("POP_FULLVIEW"), main, SLOT(showCanvas()));
52 myViewPopup->insertItem(tr("POP_CONTROLVIEW"), main, SLOT(showContolFlow()));
53 myViewPopup->insertItem(tr("POP_TABLEVIEW"), main, SLOT(showTable()));
54 // myViewPopup->insertItem("Previous Full View", main, SLOT(showFullGraph()));
55 // myViewPopup->insertItem(tr("POP_CANVASVIEW"), main, SLOT(showCanvas()));
57 myPopup->insertItem(tr("POP_VIEW"), myViewPopup);
58 myPopup->insertSeparator();
60 myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), this, SLOT(addToStudy()));
61 myPopup->insertItem(tr("MSG_CHANGE_INFO"), main, SLOT(changeInformation()));
62 myPopup->insertSeparator();
64 myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), main, SLOT(copy()));
65 myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), main, SLOT(filterNotification()));
67 myPopup->insertSeparator();
68 myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
70 QString aRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
71 QString aGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
72 QString aBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
74 if( (!aRed.isEmpty()) && (!aGreen.isEmpty()) && (!aBlue.isEmpty()) ) {
75 QColor aColor(aRed.toInt(), aGreen.toInt(), aBlue.toInt());
76 setPaletteBackgroundColor(QColor(aRed.toInt(), aGreen.toInt(), aBlue.toInt()));
78 setPaletteBackgroundColor(MAIN_COLOR);
82 SUPERVGUI_View::~SUPERVGUI_View()
86 bool SUPERVGUI_View::isHavingStreamPort()
88 SUPERV::ListOfNodes* aNodesList = main->getDataflow()->Nodes();
91 for ( int i = 0 ; i < (int) aNodesList->CNodes.length() ; i++ ) {
92 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->CNodes)[i]->StreamPorts() );
93 if ((int) aStrPortsList.length() > 0) {
99 for ( int i = 0 ; i < (int) aNodesList->FNodes.length() ; i++ ) {
100 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->FNodes)[i]->StreamPorts() );
101 if ((int) aStrPortsList.length() > 0) {
107 for ( int i = 0 ; i < (int) aNodesList->INodes.length() ; i++ ) {
108 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->INodes)[i]->StreamPorts() );
109 if ((int) aStrPortsList.length() > 0) {
115 for ( int i = 0 ; i < (int) aNodesList->GNodes.length() ; i++ ) {
116 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->GNodes)[i]->StreamPorts() );
117 if ((int) aStrPortsList.length() > 0) {
123 for ( int i = 0 ; i < (int) aNodesList->LNodes.length() ; i++ ) {
124 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->LNodes)[i]->StreamPorts() );
125 if ((int) aStrPortsList.length() > 0) {
131 for ( int i = 0 ; i < (int) aNodesList->SNodes.length() ; i++ ) {
132 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->SNodes)[i]->StreamPorts() );
133 if ((int) aStrPortsList.length() > 0) {
141 void SUPERVGUI_View::addDSPopupItem()
143 if (myDSItemID == -1) {
144 //Popupmenu items for user specification of parameters, if there are any DataStream ports in the graph
145 if (isHavingStreamPort()) {
146 myPopup->insertSeparator();
147 myDSItemID = myPopup->insertItem(tr("MSG_SET_GRAPHPARAMS"), main, SLOT(changeDSGraphParameters()));
152 void SUPERVGUI_View::viewportMousePressEvent(QMouseEvent* theEvent)
155 myLastX = theEvent->globalX();
156 myLastY = theEvent->globalY();
158 if (((theEvent->button() == Qt::MidButton)&&(theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
160 setCursor(panCursor);
163 QScrollView::viewportMousePressEvent(theEvent);
166 void SUPERVGUI_View::viewportMouseMoveEvent(QMouseEvent* theEvent)
168 if (myIsDragging && ((theEvent->state() == (Qt::ControlButton|Qt::MidButton)) || myIsPanActivated)) {
169 myDx = theEvent->globalX() - myLastX;
170 myDy = theEvent->globalY() - myLastY;
172 myLastX = theEvent->globalX();
173 myLastY = theEvent->globalY();
175 scrollBy(-myDx, -myDy);
178 QScrollView::viewportMouseMoveEvent(theEvent);
183 void SUPERVGUI_View::viewportMouseReleaseEvent(QMouseEvent* theEvent)
187 myIsDragging = false;
188 myIsPanActivated = false;
190 QScrollView::viewportMouseReleaseEvent(theEvent);
194 void SUPERVGUI_View::ActivatePanning()
196 myIsPanActivated = true;
200 void SUPERVGUI_View::ResetView()
206 void SUPERVGUI_View::setAsFromStudy(bool theToStudy) {
207 if (myAddStudyItem != 0) {
208 myPopup->setItemEnabled(myAddStudyItem, !theToStudy);
212 void SUPERVGUI_View::addToStudy() {
213 if (main->addStudy()) main->setAsFromStudy(true);
216 void SUPERVGUI_View::setPaletteBackgroundColor(const QColor& color) {
217 viewport()->setPaletteBackgroundColor(color);
218 QScrollView::setPaletteBackgroundColor(color.light());
222 void SUPERVGUI_View::ResizeGraph ( QWidget * theChild, int theX, int theY ) {
224 int aGraphWidth = contentsWidth();
225 int aGraphHeight = contentsHeight();
226 if (theX > (contentsWidth() - theChild->width())) {
228 myDx = theChild->width();
229 aGraphWidth = theX + theChild->width();
231 if (theY > (contentsHeight() - theChild->height())) {
233 myDy = theChild->height();
234 aGraphHeight = theY + theChild->height();
237 setMaximumWidth(aGraphWidth);
238 setMaximumHeight(aGraphHeight);
240 resizeContents(aGraphWidth, aGraphHeight);
243 int SUPERVGUI_View::getLastX() {
247 int SUPERVGUI_View::getLastY() {
250 void SUPERVGUI_View::changeBackground()
252 QColor selColor = QColorDialog::getColor(viewport()->paletteBackgroundColor(), this );
253 if ( selColor.isValid() ) {
254 setPaletteBackgroundColor( selColor );