]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_View.cxx
Salome HOME
SALOME PAL V1_4_1
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_View.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SUPERVGUI_View.cxx
8 //  Author : Vitaly SMETANNIKOV
9 //  Module : SUPERV
10
11 using namespace std;
12 #include "SUPERVGUI_View.h"
13 #include "SUPERVGUI_Main.h"
14 #include "QAD_Config.h"
15 #include <qcolordialog.h>
16
17
18 #if QT_VERSION >= 0x030005
19 QCursor panCursor(Qt::SizeAllCursor);
20 #else
21 QCursor panCursor(SizeAllCursor);
22 #endif
23
24 SUPERVGUI_View::SUPERVGUI_View(SUPERVGUI_Main* theMain):
25   QScrollView(theMain, 0, Qt::WRepaintNoErase),
26   main(theMain)
27 {
28   myIsPanActivated = false;
29   myAddStudyItem = 0;
30   myDx = 0;
31   myDx = 0;
32   myLastX = 0;
33   myLastY = 0;
34   myIsDragging = false;
35   myCursor = cursor();
36
37 //  myLastMinVisX = horizontalScrollBar()->value(); //viewport()->x();
38 //  myLastMinVisY = verticalScrollBar()->value();   //viewport()->y();
39
40   myPopup = new QPopupMenu(viewport());
41
42   if (main->isEditable()) {
43     myPopup->insertItem(tr("MSG_ADD_NODE"), main, SLOT(addNode()));
44     myPopup->insertItem(tr("MSG_INS_FILE"), main, SLOT(insertFile()));
45     myPopup->insertSeparator();
46   }
47
48   myViewPopup = new QPopupMenu(viewport());
49   myViewPopup->insertItem(tr("POP_FULLVIEW"), main, SLOT(showFullGraph()));
50   myViewPopup->insertItem(tr("POP_CONTROLVIEW"), main, SLOT(showContolFlow()));
51   myViewPopup->insertItem(tr("POP_TABLEVIEW"), main, SLOT(showTable()));
52
53   myPopup->insertItem(tr("POP_VIEW"), myViewPopup);
54   myPopup->insertSeparator();
55
56   myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), this, SLOT(addToStudy()));
57   myPopup->insertItem(tr("MSG_CHANGE_INFO"), main, SLOT(changeInformation()));
58   myPopup->insertSeparator();
59
60   myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), main, SLOT(copy()));
61   myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), main, SLOT(filterNotification()));
62
63   myPopup->insertSeparator();
64   myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
65
66   QString aRed   = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
67   QString aGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
68   QString aBlue  = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
69   
70   if( (!aRed.isEmpty()) && (!aGreen.isEmpty()) && (!aBlue.isEmpty()) ) {
71     QColor aColor(aRed.toInt(), aGreen.toInt(), aBlue.toInt());
72     setPaletteBackgroundColor(QColor(aRed.toInt(), aGreen.toInt(), aBlue.toInt()));
73   } else
74     setPaletteBackgroundColor(MAIN_COLOR);
75 }
76  
77
78 SUPERVGUI_View::~SUPERVGUI_View()
79 {
80 }
81
82 void SUPERVGUI_View::viewportMousePressEvent(QMouseEvent* theEvent) 
83 {
84   myIsDragging = true;
85   myLastX = theEvent->globalX();
86   myLastY = theEvent->globalY();
87
88   if (((theEvent->button() == Qt::MidButton)&&(theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
89     myCursor = cursor();
90     setCursor(panCursor);
91     return;
92   } 
93   QScrollView::viewportMousePressEvent(theEvent);
94 }
95
96 void SUPERVGUI_View::viewportMouseMoveEvent(QMouseEvent* theEvent) 
97 {
98   if (myIsDragging && ((theEvent->state() == (Qt::ControlButton|Qt::MidButton)) || myIsPanActivated)) {
99     myDx = theEvent->globalX() - myLastX;
100     myDy = theEvent->globalY() - myLastY;
101     
102     myLastX = theEvent->globalX();
103     myLastY = theEvent->globalY();
104
105     scrollBy(-myDx, -myDy);
106     return;
107   }
108   QScrollView::viewportMouseMoveEvent(theEvent);
109 }
110
111
112
113 void SUPERVGUI_View::viewportMouseReleaseEvent(QMouseEvent* theEvent) 
114 {
115   myDx = 0;
116   myDx = 0;
117   myIsDragging = false;
118   myIsPanActivated = false;
119   setCursor(myCursor);
120   QScrollView::viewportMouseReleaseEvent(theEvent);
121 }
122
123
124 void SUPERVGUI_View::ActivatePanning()
125 {
126   myIsPanActivated = true;
127 }
128
129
130 void SUPERVGUI_View::ResetView()
131 {
132   setContentsPos(0,0);
133 }
134
135
136 void SUPERVGUI_View::setAsFromStudy(bool theToStudy) {
137   if (myAddStudyItem != 0) {
138     myPopup->setItemEnabled(myAddStudyItem, !theToStudy);
139   }
140 }
141
142 void SUPERVGUI_View::addToStudy() {
143   if (main->addStudy()) main->setAsFromStudy(true);
144 }
145
146 void SUPERVGUI_View::setPaletteBackgroundColor(const QColor& color) { 
147   viewport()->setPaletteBackgroundColor(color);
148   QScrollView::setPaletteBackgroundColor(color.light()); 
149   repaintContents();
150 }
151
152 void SUPERVGUI_View::ResizeGraph ( QWidget * theChild, int theX, int theY ) {
153
154   int aGraphWidth = contentsWidth();
155   int aGraphHeight = contentsHeight();
156   if (theX > (contentsWidth() - theChild->width())) {
157     myLastX = theX;
158     myDx = theChild->width();
159     aGraphWidth = theX + theChild->width();
160   }
161   if (theY > (contentsHeight() - theChild->height())) {
162     myLastY = theY;
163     myDy = theChild->height();
164     aGraphHeight = theY + theChild->height();
165   }
166
167   setMaximumWidth(aGraphWidth);
168   setMaximumHeight(aGraphHeight);  
169
170   resizeContents(aGraphWidth, aGraphHeight);
171 }
172
173 int SUPERVGUI_View::getLastX() {
174   return myLastX;
175 }
176
177 int SUPERVGUI_View::getLastY() {
178   return myLastY;
179 }
180 void SUPERVGUI_View::changeBackground()
181 {
182   QColor selColor = QColorDialog::getColor(viewport()->paletteBackgroundColor(), this );
183   if ( selColor.isValid() ) {
184     setPaletteBackgroundColor( selColor );
185   }
186 }