Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / SceneDataPortItem.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "SceneDataPortItem.hxx"
20 #include "SceneTextItem.hxx"
21 #include "SceneNodeItem.hxx"
22 #include "Scene.hxx"
23
24 // #include "QtGuiContext.hxx"
25 // #include "Menus.hxx"
26 // #include <QGraphicsSceneHoverEvent>
27 // #include <QPointF>
28
29 // #include <cassert>
30
31 //#define _DEVDEBUG_
32 #include "YacsTrace.hxx"
33
34 using namespace std;
35 using namespace YACS::ENGINE;
36 using namespace YACS::HMI;
37
38
39 SceneDataPortItem::SceneDataPortItem(QGraphicsScene *scene, SceneItem *parent,
40                                      QString label, Subject *subject)
41   : SceneObserverItem(scene, parent, label, subject), ScenePortItem(label)
42 {
43   _width  = _portWidth;
44   _height = _portHeight;
45   setText(label);
46   _brushColor   = QColor(158, 227, 151);
47   _hiBrushColor = QColor(127, 227, 116);
48   _penColor     = QColor( 15, 180,   0);
49   _hiPenColor   = QColor( 11, 128,   0);
50 }
51
52 SceneDataPortItem::~SceneDataPortItem()
53 {
54 }
55
56 void SceneDataPortItem::paint(QPainter *painter,
57                           const QStyleOptionGraphicsItem *option,
58                           QWidget *widget)
59 {
60   //DEBTRACE("ScenePortItem::paint");
61   painter->save();
62   painter->setPen(getPenColor());
63   painter->setBrush(getBrushColor());
64   painter->drawRoundRect(QRectF(0, 0, _width, _height), 33*_height/_width, 33);
65   painter->restore();
66 }
67
68 void SceneDataPortItem::setText(QString label)
69 {
70   if (!_text)
71     _text = new SceneTextItem(_scene,
72                               this,
73                               label);
74   else
75     _text->setPlainText(label);
76 }
77
78 void SceneDataPortItem::update(GuiEvent event, int type, Subject* son)
79 {
80   DEBTRACE("SceneDataPortItem::update "<< eventName(event)<<" "<<type<<" "<<son);
81   switch (event)
82     {
83     case YACS::HMI::RENAME:
84       _text->setPlainText(son->getName().c_str());
85       break;
86     case YACS::HMI::REMOVE:
87       SceneObserverItem::update(event, type, son);
88       break;
89     }
90 }
91
92 SceneNodeItem* SceneDataPortItem::getParent()
93 {
94   if (_parent)
95     return dynamic_cast<SceneNodeItem*>(_parent);
96   else
97     return 0;
98 }
99