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_CONTROLVIEW"), main, SLOT(showContolFlow()));
52 myViewPopup->insertItem(tr("POP_TABLEVIEW"), main, SLOT(showTable()));
54 myPopup->insertItem(tr("POP_VIEW"), myViewPopup);
55 myPopup->insertSeparator();
57 myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), this, SLOT(addToStudy()));
58 myPopup->insertItem(tr("MSG_CHANGE_INFO"), main, SLOT(changeInformation()));
59 myPopup->insertSeparator();
61 myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), main, SLOT(copy()));
62 myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), main, SLOT(filterNotification()));
64 myPopup->insertSeparator();
65 myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
67 QString aRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
68 QString aGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
69 QString aBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
71 if( (!aRed.isEmpty()) && (!aGreen.isEmpty()) && (!aBlue.isEmpty()) ) {
72 QColor aColor(aRed.toInt(), aGreen.toInt(), aBlue.toInt());
73 setPaletteBackgroundColor(QColor(aRed.toInt(), aGreen.toInt(), aBlue.toInt()));
75 setPaletteBackgroundColor(MAIN_COLOR);
79 SUPERVGUI_View::~SUPERVGUI_View()
83 bool SUPERVGUI_View::isHavingStreamPort()
85 SUPERV::ListOfNodes* aNodesList = main->getDataflow()->Nodes();
88 for ( int i = 0 ; i < (int) aNodesList->CNodes.length() ; i++ ) {
89 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->CNodes)[i]->StreamPorts() );
90 if ((int) aStrPortsList.length() > 0) {
96 for ( int i = 0 ; i < (int) aNodesList->FNodes.length() ; i++ ) {
97 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->FNodes)[i]->StreamPorts() );
98 if ((int) aStrPortsList.length() > 0) {
104 for ( int i = 0 ; i < (int) aNodesList->INodes.length() ; i++ ) {
105 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->INodes)[i]->StreamPorts() );
106 if ((int) aStrPortsList.length() > 0) {
112 for ( int i = 0 ; i < (int) aNodesList->GNodes.length() ; i++ ) {
113 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->GNodes)[i]->StreamPorts() );
114 if ((int) aStrPortsList.length() > 0) {
120 for ( int i = 0 ; i < (int) aNodesList->LNodes.length() ; i++ ) {
121 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->LNodes)[i]->StreamPorts() );
122 if ((int) aStrPortsList.length() > 0) {
128 for ( int i = 0 ; i < (int) aNodesList->SNodes.length() ; i++ ) {
129 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->SNodes)[i]->StreamPorts() );
130 if ((int) aStrPortsList.length() > 0) {
138 void SUPERVGUI_View::addDSPopupItem()
140 if (myDSItemID == -1) {
141 //Popupmenu items for user specification of parameters, if there are any DataStream ports in the graph
142 if (isHavingStreamPort()) {
143 myPopup->insertSeparator();
144 myDSItemID = myPopup->insertItem(tr("MSG_SET_GRAPHPARAMS"), main, SLOT(changeDSGraphParameters()));
149 void SUPERVGUI_View::viewportMousePressEvent(QMouseEvent* theEvent)
152 myLastX = theEvent->globalX();
153 myLastY = theEvent->globalY();
155 if (((theEvent->button() == Qt::MidButton)&&(theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
157 setCursor(panCursor);
160 QScrollView::viewportMousePressEvent(theEvent);
163 void SUPERVGUI_View::viewportMouseMoveEvent(QMouseEvent* theEvent)
165 if (myIsDragging && ((theEvent->state() == (Qt::ControlButton|Qt::MidButton)) || myIsPanActivated)) {
166 myDx = theEvent->globalX() - myLastX;
167 myDy = theEvent->globalY() - myLastY;
169 myLastX = theEvent->globalX();
170 myLastY = theEvent->globalY();
172 scrollBy(-myDx, -myDy);
175 QScrollView::viewportMouseMoveEvent(theEvent);
180 void SUPERVGUI_View::viewportMouseReleaseEvent(QMouseEvent* theEvent)
184 myIsDragging = false;
185 myIsPanActivated = false;
187 QScrollView::viewportMouseReleaseEvent(theEvent);
191 void SUPERVGUI_View::ActivatePanning()
193 myIsPanActivated = true;
197 void SUPERVGUI_View::ResetView()
203 void SUPERVGUI_View::setAsFromStudy(bool theToStudy) {
204 if (myAddStudyItem != 0) {
205 myPopup->setItemEnabled(myAddStudyItem, !theToStudy);
209 void SUPERVGUI_View::addToStudy() {
210 if (main->addStudy()) main->setAsFromStudy(true);
213 void SUPERVGUI_View::setPaletteBackgroundColor(const QColor& color) {
214 viewport()->setPaletteBackgroundColor(color);
215 QScrollView::setPaletteBackgroundColor(color.light());
219 void SUPERVGUI_View::ResizeGraph ( QWidget * theChild, int theX, int theY ) {
221 int aGraphWidth = contentsWidth();
222 int aGraphHeight = contentsHeight();
223 if (theX > (contentsWidth() - theChild->width())) {
225 myDx = theChild->width();
226 aGraphWidth = theX + theChild->width();
228 if (theY > (contentsHeight() - theChild->height())) {
230 myDy = theChild->height();
231 aGraphHeight = theY + theChild->height();
234 setMaximumWidth(aGraphWidth);
235 setMaximumHeight(aGraphHeight);
237 resizeContents(aGraphWidth, aGraphHeight);
240 int SUPERVGUI_View::getLastX() {
244 int SUPERVGUI_View::getLastY() {
247 void SUPERVGUI_View::changeBackground()
249 QColor selColor = QColorDialog::getColor(viewport()->paletteBackgroundColor(), this );
250 if ( selColor.isValid() ) {
251 setPaletteBackgroundColor( selColor );