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