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;
37 // myLastMinVisX = horizontalScrollBar()->value(); //viewport()->x();
38 // myLastMinVisY = verticalScrollBar()->value(); //viewport()->y();
40 myPopup = new QPopupMenu(viewport());
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();
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()));
53 myPopup->insertItem(tr("POP_VIEW"), myViewPopup);
54 myPopup->insertSeparator();
56 myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), this, SLOT(addToStudy()));
57 myPopup->insertItem(tr("MSG_CHANGE_INFO"), main, SLOT(changeInformation()));
58 myPopup->insertSeparator();
60 myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), main, SLOT(copy()));
61 myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), main, SLOT(filterNotification()));
63 myPopup->insertSeparator();
64 myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
66 QString aRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
67 QString aGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
68 QString aBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
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()));
74 setPaletteBackgroundColor(MAIN_COLOR);
78 SUPERVGUI_View::~SUPERVGUI_View()
82 void SUPERVGUI_View::viewportMousePressEvent(QMouseEvent* theEvent)
85 myLastX = theEvent->globalX();
86 myLastY = theEvent->globalY();
88 if (((theEvent->button() == Qt::MidButton)&&(theEvent->state() == Qt::ControlButton)) || myIsPanActivated) {
93 QScrollView::viewportMousePressEvent(theEvent);
96 void SUPERVGUI_View::viewportMouseMoveEvent(QMouseEvent* theEvent)
98 if (myIsDragging && ((theEvent->state() == (Qt::ControlButton|Qt::MidButton)) || myIsPanActivated)) {
99 myDx = theEvent->globalX() - myLastX;
100 myDy = theEvent->globalY() - myLastY;
102 myLastX = theEvent->globalX();
103 myLastY = theEvent->globalY();
105 scrollBy(-myDx, -myDy);
108 QScrollView::viewportMouseMoveEvent(theEvent);
113 void SUPERVGUI_View::viewportMouseReleaseEvent(QMouseEvent* theEvent)
117 myIsDragging = false;
118 myIsPanActivated = false;
120 QScrollView::viewportMouseReleaseEvent(theEvent);
124 void SUPERVGUI_View::ActivatePanning()
126 myIsPanActivated = true;
130 void SUPERVGUI_View::ResetView()
136 void SUPERVGUI_View::setAsFromStudy(bool theToStudy) {
137 if (myAddStudyItem != 0) {
138 myPopup->setItemEnabled(myAddStudyItem, !theToStudy);
142 void SUPERVGUI_View::addToStudy() {
143 if (main->addStudy()) main->setAsFromStudy(true);
146 void SUPERVGUI_View::setPaletteBackgroundColor(const QColor& color) {
147 viewport()->setPaletteBackgroundColor(color);
148 QScrollView::setPaletteBackgroundColor(color.light());
152 void SUPERVGUI_View::ResizeGraph ( QWidget * theChild, int theX, int theY ) {
154 int aGraphWidth = contentsWidth();
155 int aGraphHeight = contentsHeight();
156 if (theX > (contentsWidth() - theChild->width())) {
158 myDx = theChild->width();
159 aGraphWidth = theX + theChild->width();
161 if (theY > (contentsHeight() - theChild->height())) {
163 myDy = theChild->height();
164 aGraphHeight = theY + theChild->height();
167 setMaximumWidth(aGraphWidth);
168 setMaximumHeight(aGraphHeight);
170 resizeContents(aGraphWidth, aGraphHeight);
173 int SUPERVGUI_View::getLastX() {
177 int SUPERVGUI_View::getLastY() {
180 void SUPERVGUI_View::changeBackground()
182 QColor selColor = QColorDialog::getColor(viewport()->paletteBackgroundColor(), this );
183 if ( selColor.isValid() ) {
184 setPaletteBackgroundColor( selColor );