]> AND Private Git Repository - blast.git/blob - ConnectionItem.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
1st commit of all files
[blast.git] / ConnectionItem.cpp
1 #include "ConnectionItem.h"
2
3 #include "Dispatcher.h"
4 #include "Parameters.h"
5 #include "AbstractBoxItem.h"
6 #include "ConnectedInterface.h"
7 #include "InterfaceItem.h"
8 #include "AbstractBlock.h"
9
10 //int ConnectionItem::counter = 0;
11
12 ConnectionItem::ConnectionItem(InterfaceItem* _iface1,
13                                InterfaceItem* _iface2,
14                                Dispatcher* _dispatcher,
15                                Parameters* _params,
16                                QGraphicsItem *_parent) : QGraphicsItem(_parent) {
17
18
19   dispatcher = _dispatcher;
20   params = _params;
21
22   ConnectedInterface* ref1 = _iface1->refInter;
23   ConnectedInterface* ref2 = _iface2->refInter;
24   /* ref. note in .h
25      case 1 : ref1 is group interface, and ref2 block interface of a block within the group
26      case 2 : the opposite of case 1
27      case 3 : ref1 and ref2 are block interface of blocks that are both within the same parent group.
28    */
29   if (ref1->getOwner() == ref2->getOwner()->getParent()) {
30
31     if (ref1->getDirection() == AbstractInterface::Input) {
32       fromInterfaceItem = _iface1;
33       toInterfaceItem = _iface2;
34     }
35     else if (ref1->getDirection() == AbstractInterface::InOut) {
36       fromInterfaceItem = _iface1;
37       toInterfaceItem = _iface2;
38     }
39     else if (ref1->getDirection() == AbstractInterface::Output) {
40       toInterfaceItem = _iface1;
41       fromInterfaceItem = _iface2;
42     }
43   }
44   else if (ref1->getOwner()->getParent() == ref2->getOwner()) {
45
46     if (ref1->getDirection() == AbstractInterface::Input) {
47       fromInterfaceItem = _iface2;
48       toInterfaceItem = _iface1;
49     }
50     else if (ref1->getDirection() == AbstractInterface::InOut) {
51       fromInterfaceItem = _iface2;
52       toInterfaceItem = _iface1;
53     }
54     else if (ref1->getDirection() == AbstractInterface::Output) {
55       toInterfaceItem = _iface2;
56       fromInterfaceItem = _iface1;
57     }
58   }
59   // NB : this case is in fact similar to the previous. Kept here for clarity
60   else if (ref1->getOwner()->getParent() == ref2->getOwner()->getParent()) {
61
62     if (ref1->getDirection() == AbstractInterface::Input) {
63       fromInterfaceItem = _iface2;
64       toInterfaceItem = _iface1;
65     }
66     else if (ref1->getDirection() == AbstractInterface::InOut) {
67       fromInterfaceItem = _iface2;
68       toInterfaceItem = _iface1;
69     }
70     else if (ref1->getDirection() == AbstractInterface::Output) {
71       toInterfaceItem = _iface2;
72       fromInterfaceItem = _iface1;
73     }
74   }
75   // adding this to interface items
76   fromInterfaceItem->addConnectionItem(this);
77   toInterfaceItem->addConnectionItem(this);
78
79   selected = false;
80   marginConn = params->arrowLineLength+params->arrowWidth;
81
82   setFlag(ItemIsSelectable);
83   setAcceptHoverEvents(true);
84   setFlag(ItemSendsGeometryChanges);
85   setCursor(Qt::PointingHandCursor);
86   setZValue(0);
87
88   setPathes();
89 }
90
91
92 ConnectionItem::ConnectionItem(const ConnectionItem &copy) {
93   pointFrom = copy.pointFrom;
94   pointTo = copy.pointTo;
95   interPoint1 = copy.interPoint1;
96   interPoint2 = copy.interPoint2;
97   interPoint3 = copy.interPoint3;
98   interPoint4 = copy.interPoint4;
99 }
100
101 ConnectionItem::~ConnectionItem() {
102 }
103
104 ConnectionItem::ConnectionItem() {
105 }
106
107 QPainterPath ConnectionItem::shape() const {
108   return pathShape;
109 }
110
111 QRectF ConnectionItem::boundingRect() const {
112
113   QPointF start, end;
114
115   if(pointFrom.x() < pointTo.x()){
116     start.setX(pointFrom.x()-20);
117     end.setX(pointTo.x()+20);
118   } else {
119     start.setX(pointTo.x()-20);
120     end.setX(pointFrom.x()+20);
121   }
122   if(pointFrom.y() < pointTo.y()){
123     start.setY(pointFrom.y()-20);
124     end.setY(pointTo.y()+20);
125   } else {
126     start.setY(pointTo.y()-20);
127     end.setY(pointFrom.y()+20);
128   }
129   return QRectF(start, end);
130 }
131
132 void ConnectionItem::paint(QPainter *painter,
133                            const QStyleOptionGraphicsItem *option,
134                            QWidget *widget) {
135
136   painter->setPen(Qt::blue);
137   if(selected){
138     painter->setPen(Qt::red);
139   }
140
141   painter->drawPath(pathPaint);
142 }
143
144 void ConnectionItem::addInterPoint(QPointF point) {
145
146 }
147
148 void ConnectionItem::setPathes() {
149
150   prepareGeometryChange();
151
152   pointFrom = fromInterfaceItem->getEndPointInGroup();
153   pointTo = toInterfaceItem->getEndPointInGroup();
154
155   int oriFrom, oriTo;
156   oriFrom = fromInterfaceItem->getOrientation();
157   oriTo = toInterfaceItem->getOrientation();
158
159 /* NB: if src or dest is onwed by a GroupItem the orientation
160    must be changed as it is a block.
161  */
162   if(fromInterfaceItem->owner->isGroupItem()){
163     switch(fromInterfaceItem->getOrientation()){
164     case Parameters::North :
165       oriFrom = Parameters::South;
166       break;
167     case Parameters::South :
168       oriFrom = Parameters::North;
169       break;
170     case Parameters::East :
171       oriFrom = Parameters::West;
172       break;
173     case Parameters::West :
174       oriFrom = Parameters::East;
175       break;
176     }
177   }
178   if(toInterfaceItem->owner->isGroupItem()){
179     switch(toInterfaceItem->getOrientation()){
180     case Parameters::North :
181       oriTo = Parameters::South;
182       break;
183     case Parameters::South :
184       oriTo = Parameters::North;
185       break;
186     case Parameters::East :
187       oriTo = Parameters::West;
188       break;
189     case Parameters::West :
190       oriTo = Parameters::East;
191       break;
192     }
193   }
194   double gap1 = 0.0;
195   double gap2 = 0.0;
196
197   if(oriFrom == Parameters::South) {
198
199     // FROM SOUTH TO SOUTH
200     if(oriTo == Parameters::South) {
201       computeElle(oriFrom);
202     }
203     // FROM SOUTH TO NORTH
204     else if(oriTo == Parameters::North) {
205       gap1 = pointTo.y() - pointFrom.y();
206       if (gap1 > 2*marginConn) {
207         computeStaircase(oriFrom);
208       }
209       else {
210         computeEsse(oriFrom);
211       }
212     }
213     // FROM SOUTH TO EAST OR WEST
214     else if ((oriTo == Parameters::East) || (oriTo == Parameters::West)){
215
216       gap1 = pointTo.x() - pointFrom.x();
217       if (oriTo == Parameters::West) gap1 = -gap1;
218       gap2 = pointTo.y() - pointFrom.y();
219
220       if (gap1 > 0.0) {
221         if (gap2 > 0.0) {
222           computeHookSmallEnd(oriFrom,oriTo);
223         }
224         else {
225           computeOpenRect(oriFrom,oriTo);
226         }
227       }
228       else {
229         if (gap2 >= 0.0) {
230           computeCorner(oriFrom);
231         }
232         else {
233           computeHookSmallStart(oriFrom,oriTo);
234         }
235       }
236     }
237   }
238   else if(oriFrom == Parameters::North) {
239
240     // FROM NORTH TO SOUTH
241     if(oriTo == Parameters::South) {
242       gap1 = pointFrom.y() - pointTo.y();
243       if (gap1 > 2*marginConn) {
244         computeStaircase(oriFrom);
245       }
246       else {
247         computeEsse(oriFrom);
248       }
249     }
250     // FROM NORTH TO NORTH
251     else if(oriTo == Parameters::North) {
252       computeElle(oriFrom);
253     }
254     // FROM NORTH TO EAST OR WEST
255     else if ((oriTo == Parameters::East) || (oriTo == Parameters::West)){
256
257       gap1 = pointTo.x() - pointFrom.x();
258       if (oriTo == Parameters::West) gap1 = -gap1;
259       gap2 = pointFrom.y() - pointTo.y();
260
261       if (gap1 > 0.0) {
262         if (gap2 > 0.0) {
263           computeHookSmallEnd(oriFrom,oriTo);
264         }
265         else {
266           computeOpenRect(oriFrom,oriTo);
267         }
268       }
269       else {
270         if (gap2 >= 0.0) {
271           computeCorner(oriFrom);
272         }
273         else {
274           computeHookSmallStart(oriFrom,oriTo);
275         }
276       }
277     }
278   }
279   else if(oriFrom == Parameters::East) {
280     // FROM EAST TO NORTH OR SOUTH
281     if ((oriTo == Parameters::South) || (oriTo == Parameters::North)){
282
283       gap1 = pointFrom.x() - pointTo.x();
284       gap2 = pointFrom.y() - pointTo.y();
285       if (oriTo == Parameters::North) gap2 = -gap2;
286
287       if (gap1 > 0.0) {
288         if (gap2 > 0.0) {
289           computeHookSmallStart(oriFrom,oriTo);
290         }
291         else {
292           computeOpenRect(oriFrom,oriTo);
293         }
294       }
295       else {
296         if (gap2 >= 0.0) {
297           computeCorner(oriFrom);
298         }
299         else {
300           computeHookSmallEnd(oriFrom,oriTo);
301         }
302       }
303     }
304     else if(oriTo == Parameters::East) {
305       computeElle(oriFrom);
306     }
307     else if (oriTo == Parameters::West) {
308       gap1 = pointTo.x() - pointFrom.x();
309       if (gap1 > 2*marginConn) {
310         computeStaircase(oriFrom);
311       }
312       else {
313         computeEsse(oriFrom);
314       }
315     }
316   }
317   else if (oriFrom == Parameters::West) {
318
319     // FROM WEST TO NORTH OR SOUTH
320     if ((oriTo == Parameters::South) || (oriTo == Parameters::North)){
321
322       gap1 = pointTo.x() - pointFrom.x();
323       gap2 = pointFrom.y() - pointTo.y();
324       if (oriTo == Parameters::North) gap2 = -gap2;
325
326       if (gap1 > 0.0) {
327         if (gap2 > 0.0) {
328           computeHookSmallStart(oriFrom,oriTo);
329         }
330         else {
331           computeOpenRect(oriFrom,oriTo);
332         }
333       }
334       else {
335         if (gap2 >= 0.0) {
336           computeCorner(oriFrom);
337         }
338         else {
339           computeHookSmallEnd(oriFrom,oriTo);
340         }
341       }
342     }
343     else if(oriTo == Parameters::East) {
344       gap1 = pointFrom.x() - pointTo.x();
345       if (gap1 > 2*marginConn) {
346         computeStaircase(oriFrom);
347       }
348       else {
349         computeEsse(oriFrom);
350       }
351     }
352     else if (oriTo == Parameters::West) {
353       computeElle(oriFrom);
354     }
355   }
356
357   pps.setWidth(5);
358   pathShape = pps.createStroke(pathPaint);
359 }
360
361
362 void ConnectionItem::computeEsse(int orientationFrom) {
363
364   //cout << "drawing an esse" << endl;
365   pathPaint = QPainterPath(pointFrom);
366   interPoints.clear();
367   double gap = marginConn;
368   if ((orientationFrom == Parameters::North)||(orientationFrom == Parameters::West)) gap = -gap;
369   QPointF p(0.0,0.0);
370
371   if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) {
372     // must draw a complete esse
373     p = QPointF(pointFrom.x()+gap,pointFrom.y());
374     pathPaint.lineTo(p);
375     interPoints.append(p);
376     p = QPointF(pointFrom.x()+gap,(pointFrom.y()+pointTo.y())/2.0);
377     pathPaint.lineTo(p);
378     interPoints.append(p);
379     p = QPointF(pointTo.x()-gap,(pointFrom.y()+pointTo.y())/2.0);
380     pathPaint.lineTo(p);
381     interPoints.append(p);
382     p = QPointF(pointTo.x()-gap,pointTo.y());
383     pathPaint.lineTo(p);
384     interPoints.append(p);
385     pathPaint.lineTo(pointTo);
386   }
387   else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) {
388
389     // must draw a complete esse
390     p = QPointF(pointFrom.x(),pointFrom.y()+gap);
391     pathPaint.lineTo(p);
392     interPoints.append(p);
393     p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y()+gap);
394     pathPaint.lineTo(p);
395     interPoints.append(p);
396     p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y()-gap);
397     pathPaint.lineTo(p);
398     interPoints.append(p);
399     p = QPointF(pointTo.x(), pointTo.y()-gap);
400     pathPaint.lineTo(p);
401     interPoints.append(p);
402     pathPaint.lineTo(pointTo);
403   }
404 }
405
406 void ConnectionItem::computeStaircase(int orientationFrom) {
407
408   pathPaint = QPainterPath(pointFrom);
409   interPoints.clear();
410   QPointF p(0.0,0.0);
411
412   if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) {
413     if (pointFrom.y() == pointTo.y()) {
414       //cout << "drawing straight line" << endl;
415       pathPaint.lineTo(pointTo);
416     }
417     else  {
418       //cout << "drawing a staircase" << endl;
419       // sufficient place to draw a simple staircase
420       p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y());
421       pathPaint.lineTo(p);
422       interPoints.append(p);
423       p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y());
424       pathPaint.lineTo(p);
425       interPoints.append(p);
426       pathPaint.lineTo(pointTo);
427     }
428   }
429   else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) {
430     if (pointFrom.x() == pointTo.x()) {
431       //cout << "drawing straight line" << endl;
432       pathPaint.lineTo(pointTo);
433     }
434     else {
435       //cout << "drawing a staircase" << endl;
436       // sufficient place to draw a simple staircase
437       p = QPointF(pointFrom.x(),(pointFrom.y()+pointTo.y())/2.0);
438       pathPaint.lineTo(p);
439       interPoints.append(p);
440       p = QPointF(pointTo.x(),(pointFrom.y()+pointTo.y())/2.0);
441       pathPaint.lineTo(p);
442       interPoints.append(p);
443       pathPaint.lineTo(pointTo);
444     }
445   }
446 }
447
448 /* drawCorner():
449
450   A Corner has the following shape :
451   |
452   |__
453
454 */
455 void ConnectionItem::computeCorner(int orientationFrom) {
456
457   pathPaint = QPainterPath(pointFrom);
458   interPoints.clear();
459   QPointF p(0.0,0.0);
460   //cout << "drawing a corner" << endl;
461
462   if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) {
463     p = QPointF(pointTo.x(),pointFrom.y());
464     pathPaint.lineTo(p);
465     interPoints.append(p);
466     pathPaint.lineTo(pointTo);
467   }
468   else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) {
469     p = QPointF(pointFrom.x(),pointTo.y());
470     pathPaint.lineTo(p);
471     interPoints.append(p);
472     pathPaint.lineTo(pointTo);
473   }
474 }
475
476 /* drawOpenRect():
477
478   A OpenRect has the following shape :
479   __
480   |
481   |_|
482 */
483 void ConnectionItem::computeOpenRect(int orientationFrom, int orientationTo) {
484   pathPaint = QPainterPath(pointFrom);
485   interPoints.clear();
486   QPointF p(0.0,0.0);
487   double gap1 = marginConn;
488   double gap2 = marginConn;
489   //cout << "drawing an OpenRect" << endl;
490
491   if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) {
492     if (orientationFrom == Parameters::West) {
493       gap1 = -gap1;
494     }
495     if (orientationTo == Parameters::North) {
496       gap2 = -gap2;
497     }
498     p = QPointF(pointFrom.x()+gap1,pointFrom.y());
499     pathPaint.lineTo(p);
500     interPoints.append(p);
501     p = QPointF(pointFrom.x()+gap1,pointTo.y()+gap2);
502     pathPaint.lineTo(p);
503     interPoints.append(p);
504     p = QPointF(pointTo.x(),pointTo.y()+gap2);
505     pathPaint.lineTo(p);
506     interPoints.append(p);
507     pathPaint.lineTo(pointTo);
508
509   }
510   else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) {
511     if (orientationFrom == Parameters::North) {
512       gap1 = -gap1;
513     }
514     if (orientationTo == Parameters::West) {
515       gap2 = -gap2;
516     }
517     p = QPointF(pointFrom.x(),pointFrom.y()+gap1);
518     pathPaint.lineTo(p);
519     interPoints.append(p);
520     p = QPointF(pointTo.x()+gap2,pointFrom.y()+gap1);
521     pathPaint.lineTo(p);
522     interPoints.append(p);
523     p = QPointF(pointTo.x()+gap2,pointTo.y());
524     pathPaint.lineTo(p);
525     interPoints.append(p);
526     pathPaint.lineTo(pointTo);
527   }
528 }
529
530 /* drawHookSmallEnd():
531
532   A Hook has the following shape :
533   _
534    |
535    |_|
536    Its end has always a size of marginConn
537 */
538 void ConnectionItem::computeHookSmallEnd(int orientationFrom, int orientationTo) {
539   pathPaint = QPainterPath(pointFrom);
540   interPoints.clear();
541   QPointF p(0.0,0.0);
542   double gap = marginConn;
543   //cout << "drawing a Hook with small end" << endl;
544
545   if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) {
546
547     if (orientationTo == Parameters::North) gap = -gap;
548
549     p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y());
550     pathPaint.lineTo(p);
551     interPoints.append(p);
552     p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y()+gap);
553     pathPaint.lineTo(p);
554     interPoints.append(p);
555     p = QPointF(pointTo.x(),pointTo.y()+gap);
556     pathPaint.lineTo(p);
557     interPoints.append(p);
558     pathPaint.lineTo(pointTo);
559
560   }
561   else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) {
562
563     if (orientationTo == Parameters::West) gap = -gap;
564
565     p = QPointF(pointFrom.x(),(pointFrom.y()+pointTo.y())/2.0);
566     pathPaint.lineTo(p);
567     interPoints.append(p);
568     p = QPointF(pointTo.x()+gap,(pointFrom.y()+pointTo.y())/2.0);
569     pathPaint.lineTo(p);
570     interPoints.append(p);
571     p = QPointF(pointTo.x()+gap,pointTo.y());
572     pathPaint.lineTo(p);
573     interPoints.append(p);
574     pathPaint.lineTo(pointTo);
575   }
576 }
577
578 /* drawHookSmallStart():
579
580   A Hook has the following shape :
581   _
582    |
583    |_|
584    Its start has always a size of marginConn
585 */
586 void ConnectionItem::computeHookSmallStart(int orientationFrom, int orientationTo) {
587   pathPaint = QPainterPath(pointFrom);
588   interPoints.clear();
589   QPointF p(0.0,0.0);
590   double gap = marginConn;
591   //cout << "drawing a Hook with small start" << endl;
592
593   if ((orientationFrom == Parameters::East)||(orientationFrom == Parameters::West)) {
594
595     if (orientationFrom == Parameters::West) gap = -gap;
596
597     p = QPointF(pointFrom.x()+gap,pointFrom.y());
598     pathPaint.lineTo(p);
599     interPoints.append(p);
600     p = QPointF(pointFrom.x()+gap,(pointFrom.y()+pointTo.y())/2.0);
601     pathPaint.lineTo(p);
602     interPoints.append(p);
603     p = QPointF(pointTo.x(),(pointFrom.y()+pointTo.y())/2.0);
604     pathPaint.lineTo(p);
605     interPoints.append(p);
606     pathPaint.lineTo(pointTo);
607   }
608   else if ((orientationFrom == Parameters::South)||(orientationFrom == Parameters::North)) {
609
610     if (orientationFrom == Parameters::North) gap = -gap;
611
612     p = QPointF(pointFrom.x(),pointFrom.y()+gap);
613     pathPaint.lineTo(p);
614     interPoints.append(p);
615     p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointFrom.y()+gap);
616     pathPaint.lineTo(p);
617     interPoints.append(p);
618     p = QPointF((pointFrom.x()+pointTo.x())/2.0,pointTo.y());
619     pathPaint.lineTo(p);
620     interPoints.append(p);
621     pathPaint.lineTo(pointTo);
622   }
623 }
624
625 /* drawElle():
626
627   An Elle has the following shape :
628   |
629   |_|
630
631 */
632 void ConnectionItem::computeElle(int orientationFrom) {
633
634   pathPaint = QPainterPath(pointFrom);
635   interPoints.clear();
636   QPointF p(0.0,0.0);
637   double x;
638   double y;
639   switch(orientationFrom){
640   case Parameters::North :
641     if(pointFrom.y() < pointTo.y()) {
642       y = pointFrom.y()-marginConn;
643     }
644     else {
645       y = pointTo.y()-marginConn;
646     }
647     p = QPointF(pointFrom.x(),y);
648     pathPaint.lineTo(p);
649     interPoints.append(p);
650     p = QPointF(pointTo.x(),y);
651     pathPaint.lineTo(p);
652     interPoints.append(p);
653     pathPaint.lineTo(pointTo);
654     break;
655   case Parameters::South :
656     if(pointFrom.y() > pointTo.y()) {
657       y = pointFrom.y()+marginConn;
658     }
659     else {
660       y = pointTo.y()+marginConn;
661     }
662     p = QPointF(pointFrom.x(),y);
663     pathPaint.lineTo(p);
664     interPoints.append(p);
665     p = QPointF(pointTo.x(),y);
666     pathPaint.lineTo(p);
667     interPoints.append(p);
668     pathPaint.lineTo(pointTo);
669     break;
670   case Parameters::West :
671     if(pointFrom.x() < pointTo.x()) {
672       x = pointFrom.x()-marginConn;
673     }
674     else {
675       x = pointTo.x()-marginConn;
676     }
677     p = QPointF(x, pointFrom.y());
678     pathPaint.lineTo(p);
679     interPoints.append(p);
680     p = QPointF(x, pointTo.y());
681     pathPaint.lineTo(p);
682     interPoints.append(p);
683     pathPaint.lineTo(pointTo);
684     break;
685   case Parameters::East :
686     if(pointFrom.x() > pointTo.x()) {
687       x = pointFrom.x()+marginConn;
688     }
689     else {
690       x = pointTo.x()+marginConn;
691     }
692     p = QPointF(x, pointFrom.y());
693     pathPaint.lineTo(p);
694     interPoints.append(p);
695     p = QPointF(x, pointTo.y());
696     pathPaint.lineTo(p);
697     interPoints.append(p);
698     pathPaint.lineTo(pointTo);
699     break;
700   }
701 }
702
703 void ConnectionItem::setSelected(bool selected) {
704   this->selected = selected;
705   if(selected){
706     setZValue(50);
707   } else {
708     setZValue(0);
709   }
710 }
711
712 void ConnectionItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
713   QGraphicsItem::mousePressEvent(event);
714   setZValue(zValue()+100);  
715   setSelected(!selected);
716   update(boundingRect());
717 }
718
719 void ConnectionItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
720   QGraphicsItem::mouseReleaseEvent(event);
721   setZValue(zValue()-100);
722 }
723
724 void ConnectionItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
725   QGraphicsItem::mouseMoveEvent(event);
726 }
727
728 void ConnectionItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
729   QMenu menu;
730   QAction* removeAction = menu.addAction("Remove");
731   QAction * selectedAction= menu.exec(event->screenPos());
732
733   if(selectedAction == removeAction){
734     dispatcher->removeConnection(this);
735     dispatcher->removeUselessGroupInterfaces();
736   }
737 }
738
739 void ConnectionItem::prepareChange() {
740   prepareGeometryChange();
741 }
742
743 QDataStream &operator <<(QDataStream &out, ConnectionItem &c) {
744   out.setVersion(QDataStream::Qt_4_8);
745
746   QByteArray connData;
747   QDataStream toWrite(&connData, QIODevice::WriteOnly);
748
749   toWrite << c.id;
750   toWrite << c.getFromInterfaceItem()->getId();
751   toWrite << c.getToInterfaceItem()->getId();
752
753   out << connData;
754
755   return out;
756 }
757
758 QDataStream &operator >>(QDataStream &in, ConnectionItem &c) {
759   in.setVersion(QDataStream::Qt_4_8);
760
761   return in;
762 }