]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_ComputeNode.cxx
Salome HOME
NRI : First integration.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_ComputeNode.cxx
1 using namespace std;
2 //  File      : SUPERVGUI_ComputeNode.cxx
3 //  Created   : 09 / 01 / 2003
4 //  Author    : Vitaly SMETANNIKOV
5 //  Project   : SALOME 
6 //  Module    : SUPERVGUI
7 //  Copyright : Open CASCADE 
8
9
10 #include "SUPERVGUI_ComputeNode.h"
11 #include "SUPERVGUI_Main.h"
12 #include <qapplication.h>
13 #include <qtooltip.h>
14
15
16 SUPERVGUI_ComputeNode::SUPERVGUI_ComputeNode(QWidget* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode)
17 :SUPERVGUI_GraphNode(theParent, theMain, theNode)
18 {
19   setLineWidth(2);
20   setFrameStyle(QFrame::Panel | QFrame::Raised);
21
22   QGridLayout* aGridLayout = new QGridLayout(this, 0, 2, 3, 1);
23
24   myTitle->setPaletteBackgroundColor(QColor(63, 213, 255));
25   myTitle->reparent(this, pos());
26   aGridLayout->addMultiCellWidget(myTitle, 0, 0, 0, 1);
27
28   QString aComment(theNode->Comment());
29   if (aComment.isNull() || aComment.isEmpty()) {
30     if (getNodeType() == SUPERV::FactoryNode)
31       aComment = QString(myNode->Service()->ServiceName) + QString(tr("COMMENT_FROM"))
32         + QString(getFactoryNode()->GetComponentName());
33     else 
34       //aComment = tr("COMMENT_PYTHON");
35       aComment = tr("COMMENT_CNODE");
36     theNode->SetComment(aComment.latin1());
37   }
38
39   myServiceBox = new QVBox(this, "service");
40   myComment = new SUPERVGUI_Label(myServiceBox, LABEL_WIDTH, LABEL_HEIGHT, aComment, QLabel::AlignLeft);
41   connect(myComment, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
42   QToolTip::add(myComment, myComment->text());
43   aGridLayout->addMultiCellWidget(myServiceBox, 1, 1, 0, 1);
44
45   myStatus->reparent(this, pos());
46   myTime->reparent(this, pos());
47   aGridLayout->addWidget(myStatus, 2, 0);
48   aGridLayout->addWidget(myTime, 2, 1);
49
50   myPortsBox->reparent(this, pos());
51
52   aGridLayout->addMultiCellWidget(myPortsBox, 3, 3, 0, 1);
53   adjustSize();
54
55   myShowPopup = new QPopupMenu(this);
56   myServiceItem = myShowPopup->insertItem(tr("POP_SHOWTITLES"), this, SLOT(switchService()));
57   myPortsItem = myShowPopup->insertItem(tr("POP_SHOWPORTS"), this, SLOT(switchPorts()));
58   
59   myPopup->insertSeparator();
60   myPopup->insertItem(tr("POP_SHOW"), myShowPopup);
61   myShowPopup->setItemChecked(myServiceItem, true);
62   myShowPopup->setItemChecked(myPortsItem, true);
63   
64   show();
65 }
66
67
68 SUPERVGUI_ComputeNode::~SUPERVGUI_ComputeNode() {
69   QToolTip::remove(myComment);
70 }
71
72
73 void SUPERVGUI_ComputeNode::sync()
74 {
75   Trace("SUPERVGUI_Node::sync");
76   setName(myNode->Name());
77   myTitle->setText(name());
78   
79   myComment->setText(myNode->Comment());
80
81   bool editing = myMain->getDataflow()->IsEditing();
82   myPopup->setItemEnabled(myKillItem, !editing);
83   if (myMain->isEditable()) {
84     myPopup->setItemEnabled(myRenameItem, editing);
85     myPopup->setItemEnabled(myDeleteItem, editing);
86   }
87   SUPERVGUI_GraphNode::sync();
88 }
89
90
91
92 /**
93  * Hides services info and ports
94  */
95 void SUPERVGUI_ComputeNode::hideAll() {
96   myServiceBox->hide();
97   myShowPopup->setItemChecked(myServiceItem, false);
98   myPortsBox->hide();
99   myShowPopup->setItemChecked(myPortsItem, false);
100
101   updateShape();
102 }
103
104
105 /**
106  * Shows services info and ports
107  */
108 void SUPERVGUI_ComputeNode::showAll() {
109   myServiceBox->show();
110   myShowPopup->setItemChecked(myServiceItem, true);
111   myPortsBox->show();
112   myShowPopup->setItemChecked(myPortsItem, true);
113
114   updateShape();
115 }
116
117
118 /**
119  * Switches visibility of Service names in the node
120  */
121 void SUPERVGUI_ComputeNode::switchService() {
122   bool aIsVisible = myServiceBox->isVisible();
123   if (aIsVisible) myServiceBox->hide();
124   else myServiceBox->show();
125   updateShape();
126   myShowPopup->setItemChecked(myServiceItem, !aIsVisible);
127 }
128
129
130 /**
131  * Switches visibility of Ports in the node
132  */
133 void SUPERVGUI_ComputeNode::switchPorts() {
134   bool aIsVisible = myPortsBox->isVisible();
135   if (aIsVisible) myPortsBox->hide();
136   else myPortsBox->show();
137   updateShape();
138   myShowPopup->setItemChecked(myPortsItem, !aIsVisible);
139 }
140
141
142 void SUPERVGUI_ComputeNode::updateShape() {
143   qApp->processEvents();
144   adjustSize();
145 }