graphicscomponentitem.h
1 /*
2  name: tools/editor/graphicscomponentitem.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 __GRAPHICSCOMPONENTITEM_H__
30 #define __GRAPHICSCOMPONENTITEM_H__
31 
32 #include <QGraphicsRectItem>
33 #include <QGraphicsSimpleTextItem>
34 #include <QGraphicsScene>
35 #include <QMap>
36 #include <arcs/arcsabstractcomponent.h>
37 #include <QPen>
38 
39 #include "graphicsportitem.h"
40 
41 class GraphicsComponentItem : public QGraphicsRectItem
42 {
43 public:
44  GraphicsComponentItem(ARCSAbstractComponent* aac); // : QGraphicsRectItem(0,scene)
45  virtual ~GraphicsComponentItem();
46 
47 
48  enum { Type = UserType + 1 };
49  int type() const
50  {
51  return Type;
52  }
53 
54 
55  void addSignal(QString s,bool updateSheet = true);
56  void addSlot(QString s,bool updateSheet = true);
57 
58  bool isMarkedForDeletion() { return markedForDeletion; }
59 
60  void markForDeletion() { markedForDeletion = true; }
61  void removePort(QString name);
62  ARCSAbstractComponent* getComponent() { return component; }
63  GraphicsPortItem* getSlotPort(QString name) {
64  if (slotPorts.contains(name))
65  return slotPorts[name];
66  return 0;
67  }
68 
69  GraphicsPortItem* getSignalPort(QString name) {
70  if (signalPorts.contains(name))
71  return signalPorts[name];
72  return 0;
73  }
74 
75 
76 protected:
77  virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * );
78  virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * );
79  virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
80  virtual QVariant itemChange ( GraphicsItemChange change, const QVariant & value );
81  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
82  virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
83 
84 private:
85  ARCSAbstractComponent* component;
86  QGraphicsSimpleTextItem* componentLabel;
87  QMap<QString,GraphicsPortItem*> slotPorts;
88  QMap<QString,GraphicsPortItem*> signalPorts;
89  QPen defaultPen;
90  bool markedForDeletion;
91 
92 };
93 
94 
95 #endif // __GRAPHICSCOMPONENTITEM_H__
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Class handling the generic description of a component.