1 // Copyright (C) 2006-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SceneInPortItem.hxx"
21 #include "SceneOutPortItem.hxx"
22 #include "SceneNodeItem.hxx"
23 #include "ItemMimeData.hxx"
25 #include "Message.hxx"
26 #include "QtGuiContext.hxx"
28 #include <QGraphicsSceneDragDropEvent>
30 #include "Resource.hxx"
33 #include "YacsTrace.hxx"
36 using namespace YACS::ENGINE;
37 using namespace YACS::HMI;
40 SceneInPortItem::SceneInPortItem(QGraphicsScene *scene, SceneItem *parent,
41 QString label, Subject *subject)
42 : SceneDataPortItem(scene, parent, label, subject)
48 SceneInPortItem::~SceneInPortItem()
50 if (SceneNodeItem* parent = getParent())
51 parent->removeInPortFromList(this);
54 void SceneInPortItem::popupMenu(QWidget *caller, const QPoint &globalPos)
57 m.popupMenu(caller, globalPos);
60 void SceneInPortItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
62 bool accepted = false;
63 const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
64 if (myData && myData->hasFormat("yacs/subjectOutPort"))
66 Subject *sub = myData->getSubject();
67 if (sub && (dynamic_cast<SubjectOutputPort*>(sub) ||
68 dynamic_cast<SubjectOutputDataStreamPort*>(sub)))
70 event->setAccepted(true);
72 QGraphicsItem::update();
76 event->setAccepted(accepted);
79 void SceneInPortItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
83 QGraphicsItem::update();
86 void SceneInPortItem::dropEvent(QGraphicsSceneDragDropEvent *event)
90 QGraphicsItem::update();
92 const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
94 if(!myData->hasFormat("yacs/subjectOutPort")) return;
95 Subject *sub = myData->getSubject();
97 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
99 SceneOutPortItem* outItem = dynamic_cast<SceneOutPortItem*>(item);
100 if (!outItem) return;
102 Subject *subFrom = outItem->getSubject();
103 Subject *subTo = this->getSubject();
104 SubjectDataPort* from = dynamic_cast<SubjectDataPort*>(subFrom);
105 SubjectDataPort* to = dynamic_cast<SubjectDataPort*>(subTo);
107 if (!SubjectDataPort::tryCreateLink(from, to,myData->getControl()))
111 QColor SceneInPortItem::getPenColor()
114 return Resource::dragOver;
121 QColor SceneInPortItem::getBrushColor()
124 return _hiBrushColor;
129 color = _hiBrushColor;
131 color = Resource::emphasizeBrushColor;
133 color = hoverColor(color);