Version: 8.3.0
SceneInPortItem.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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, or (at your option) any later version.
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 
20 #include "SceneInPortItem.hxx"
21 #include "SceneOutPortItem.hxx"
22 #include "SceneNodeItem.hxx"
23 #include "ItemMimeData.hxx"
24 #include "Menus.hxx"
25 #include "Message.hxx"
26 #include "QtGuiContext.hxx"
27 
28 #include <QGraphicsSceneDragDropEvent>
29 
30 #include "Resource.hxx"
31 
32 //#define _DEVDEBUG_
33 #include "YacsTrace.hxx"
34 
35 using namespace std;
36 using namespace YACS::ENGINE;
37 using namespace YACS::HMI;
38 
39 
40 SceneInPortItem::SceneInPortItem(QGraphicsScene *scene, SceneItem *parent,
41  QString label, Subject *subject)
42  : SceneDataPortItem(scene, parent, label, subject)
43 {
44  _dragOver = false;
45  setAcceptDrops(true);
46 }
47 
49 {
50  if (SceneNodeItem* parent = getParent())
51  parent->removeInPortFromList(this);
52 }
53 
54 void SceneInPortItem::popupMenu(QWidget *caller, const QPoint &globalPos)
55 {
56  InPortMenu m;
57  m.popupMenu(caller, globalPos);
58 }
59 
60 void SceneInPortItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
61 {
62  bool accepted = false;
63  const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
64  if (myData && myData->hasFormat("yacs/subjectOutPort"))
65  {
66  Subject *sub = myData->getSubject();
67  if (sub && (dynamic_cast<SubjectOutputPort*>(sub) ||
68  dynamic_cast<SubjectOutputDataStreamPort*>(sub)))
69  {
70  event->setAccepted(true);
71  _dragOver = true;
72  QGraphicsItem::update();
73  return;
74  }
75  }
76  event->setAccepted(accepted);
77 }
78 
79 void SceneInPortItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
80 {
81  Q_UNUSED(event);
82  _dragOver = false;
83  QGraphicsItem::update();
84 }
85 
86 void SceneInPortItem::dropEvent(QGraphicsSceneDragDropEvent *event)
87 {
88  Q_UNUSED(event);
89  _dragOver = false;
90  QGraphicsItem::update();
91 
92  const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
93  if (!myData) return;
94  if(!myData->hasFormat("yacs/subjectOutPort")) return;
95  Subject *sub = myData->getSubject();
96  if (!sub) return;
98  if (!item) return;
99  SceneOutPortItem* outItem = dynamic_cast<SceneOutPortItem*>(item);
100  if (!outItem) return;
101 
102  Subject *subFrom = outItem->getSubject();
103  Subject *subTo = this->getSubject();
104  SubjectDataPort* from = dynamic_cast<SubjectDataPort*>(subFrom);
105  SubjectDataPort* to = dynamic_cast<SubjectDataPort*>(subTo);
106  if (from && to)
107  if (!SubjectDataPort::tryCreateLink(from, to,myData->getControl()))
108  Message mess;
109 }
110 
112 {
113  if (_dragOver)
114  return Resource::dragOver;
115  if (isSelected())
116  return _hiPenColor;
117  else
118  return _penColor;
119 }
120 
122 {
123  if (_dragOver)
124  return _hiBrushColor;
125 
126  QColor color;
127  color = _brushColor;
128  if (isSelected())
129  color = _hiBrushColor;
130  if (_emphasized)
132  if (_hover)
133  color = hoverColor(color);
134  return color;
135 }