graphicsportitem.h
1 /*
2  name: tools/editor/graphicsportitem.h
3 
4  This file is part of ARCS - Augmented Reality Component System
5  (version 2-current), written by Jean-Yves Didier
6  for IBISC Laboratory (http://www.ibisc.univ-evry.fr)
7 
8  Copyright (C) 2013 Université d'Evry-Val d'Essonne
9 
10  This program is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Please send bugreports with examples or suggestions to
25  jean-yves.didier__at__ibisc.univ-evry.fr
26 */
27 
28 
29 #ifndef __GRAPHICSPORTITEM_H__
30 #define __GRAPHICSPORTITEM_H__
31 
32 #include <QGraphicsPathItem>
33 #include <QGraphicsSimpleTextItem>
34 #include <QGraphicsRectItem>
35 #include <QList>
36 #include <QPen>
37 
38 class QGraphicsRectItem;
39 class GraphicsLinkItem;
40 
41 
42 class GraphicsPortItem : public QGraphicsPathItem {
43 public:
44  GraphicsPortItem(QGraphicsItem* parent);
46 
47  enum PortType
48  {
49  Slot,
50  Signal
51  };
52 
53  enum { Type = UserType + 2 };
54  int type() const
55  {
56  return Type;
57  }
58 
59 
60  void setType(PortType pt) { operationType = pt; updateView(); }
61  PortType getType() { return operationType; }
62  void setName(QString s); //{ operationName = s ; }
63  QString getName() { return operationName; }
64  bool isMarkedForDeletion() { return markedForDeletion; }
65  void markForDeletion() { markedForDeletion = true; }
66 
67  void addLink(GraphicsLinkItem* lnk) { links.append(lnk); }
68  void showName() { rectOperation->setVisible(true); }
69  void hideName() { rectOperation->setVisible(false); }
70 
71  void removeLinkItem(GraphicsLinkItem* item);
72 
73  void fireUpdate();
74 
75 protected:
76  virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * );
77  virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * );
78  virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
79  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
80  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
81  virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
82  virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
83  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
84 
85 
86 private:
87  void updateView();
88 
89  QGraphicsSimpleTextItem* textOperation;
90  QGraphicsRectItem* rectOperation;
91  PortType operationType ;
92  QString operationName;
93  GraphicsLinkItem* linkInConstruction;
94 
95  QList<GraphicsLinkItem*> links;
96  QPen defaultPen;
97  bool markedForDeletion;
98 
99 };
100 
101 
102 
103 #endif // __GRAPHICSPORTITEM_H__