1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  *
16  * Author: John Abraham <john.abraham.in@gmail.com>
17  */
18 
19 #include "graphpacket.h"
20 #include "packetsview.h"
21 #include "logqt.h"
22 
23 namespace netanim {
24 #define PI 3.14159265
25 
26 NS_LOG_COMPONENT_DEFINE ("GraphPacket");
27 
GraphPacket(QPointF fromNodePos,QPointF toNodePos)28 GraphPacket::GraphPacket (QPointF fromNodePos, QPointF toNodePos):
29   m_fromNodePos (fromNodePos),
30   m_toNodePos (toNodePos)
31 {
32   QLineF l (fromNodePos, toNodePos);
33   setLine (l);
34   setFlags (QGraphicsItem::ItemIsSelectable);
35   QPen p = pen();
36   p.setColor (Qt::blue);
37   p.setWidthF (1.5);
38   setPen(p);
39 }
40 
41 
42 void
paint(QPainter * painter,const QStyleOptionGraphicsItem * option,QWidget * widget)43 GraphPacket::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
44 {
45 
46   painter->save();
47   QPen p;
48   p.setColor (Qt::black);
49   painter->setPen (p);
50   painter->translate (line().p2());
51   qreal angle = PI/4;
52   qreal mag = 9;
53   painter->rotate (360 - line().angle ());
54   painter->drawLine(0, 0, -mag * cos (angle), mag * sin (angle));
55   painter->drawLine(0, 0, -mag * cos (angle), -mag * sin (angle));
56   painter->restore ();
57   QGraphicsLineItem::paint(painter, option, widget);
58 
59 }
60 
61 }
62