graphicslinkitem.h
1 /*
2  name: tools/editor/graphicslinkitem.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 __GRAPHICSLINKITEM_H__
30 #define __GRAPHICSLINKITEM_H__
31 
32 #include <QGraphicsPathItem>
33 #include <QGraphicsRectItem>
34 #include <QPen>
35 #include <arcs/arcsconnection.h>
36 
37 class GraphicsPortItem;
38 
39 
40 class GraphicsGripLinkItem : public QGraphicsRectItem
41 {
42 public:
43  GraphicsGripLinkItem(QGraphicsItem* parent);
44 
45  void setNext(GraphicsGripLinkItem* n) {next = n ; }
46  void setPrevious(GraphicsGripLinkItem* p) { previous = p; }
47 
48 protected:
49  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
50 
51 private :
52  GraphicsGripLinkItem* previous;
54 
55 };
56 
57 
58 
59 class GraphicsLinkItem : public QGraphicsPathItem
60 {
61 public:
62  GraphicsLinkItem(QGraphicsItem* parent,ARCSConnection* c = 0) ;
64 
65 
66  enum { Type = UserType + 3 };
78  {
79  Step,
80  S_Shape,
81  Loop
82  } ;
83 
84  int type() const
85  {
86  return Type;
87  }
88 
89 
90  ARCSConnection* getConnection() { return connection;}
91  void setSource(GraphicsPortItem* s ) { source = s ; }
92  void setDestination(GraphicsPortItem* d) { destination = d; }
93  GraphicsPortItem* getSource() { return source; }
94  GraphicsPortItem* getDestination() { return destination ; }
95  void setCurrentPoint(QPointF p);
96  void markForDeletion() { markedForDeletion = true; }
97 
98  bool isFinalized() { return finalized;}
99  void finalize(); // { finalized = true; }
100  void connectGrips() ;
101  void connectGrips(QPointF orig,QPointF dest) ;
102  void redraw(bool isSource=true);
103 
104  virtual QPainterPath shape() const;
105 
106 protected:
107  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
108  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
109  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
110 
111 private:
112  Configuration computeConfiguration(QPointF orig, QPointF dest);
113  void computePath(QPointF orig, QPointF dest);
114  GraphicsPortItem* source;
115  GraphicsPortItem* destination;
116  bool finalized;
117  GraphicsGripLinkItem* grips[4];
118  Configuration configuration;
119  ARCSConnection* connection;
120  QPen defaultPen;
121  bool markedForDeletion;
122 
123 };
124 
125 
126 #endif // __GRAPHICSLINKITEM_H__
Describes a connection.
This class is a loop sending as much iterations as needed.
Definition: sample.h:44