1 //
2 // C++ Implementation: outputflownode
3 //
4 // Description:
5 //
6 //
7 // Author: David Saxton <david@bluehaze.org>, (C) 2008
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #include "connector.h"
13 #include "outputflownode.h"
14
15
16 #include <QDebug>
17 #include <QPainter>
18
OutputFlowNode(ICNDocument * _icnView,int dir,const QPoint & pos,QString * id)19 OutputFlowNode::OutputFlowNode(ICNDocument* _icnView, int dir, const QPoint& pos, QString* id): FPNode(_icnView, Node::fp_out, dir, pos, id)
20 {
21 }
22
23
~OutputFlowNode()24 OutputFlowNode::~OutputFlowNode()
25 {
26 }
27
28
acceptInput() const29 bool OutputFlowNode::acceptInput() const
30 {
31 return false;
32 }
33
34
acceptOutput() const35 bool OutputFlowNode::acceptOutput() const
36 {
37 return true;
38 }
39
addInputConnector(Connector * const)40 void OutputFlowNode::addInputConnector( Connector * const /*connector*/ )
41 {
42 qDebug() << Q_FUNC_INFO << "BUG: trying to add input connector to an output node" << endl;
43 }
44
45
arrowPoints(int dir)46 inline QPolygon arrowPoints( int dir )
47 {
48 QPolygon pa(3);
49 switch ( dir ) {
50 case 0:
51 pa[0] = QPoint( 3, 0 );
52 pa[1] = QPoint( 0, 2 );
53 pa[2] = QPoint( 0, -2 );
54 break;
55 case 180:
56 pa[0] = QPoint( -3, 0 );
57 pa[1] = QPoint( 0, 2 );
58 pa[2] = QPoint( 0, -2 );
59 break;
60 case 90:
61 pa[0] = QPoint( 2, 0 );
62 pa[1] = QPoint( -2, 0 );
63 pa[2] = QPoint( 0, 3 );
64 break;
65 case 270:
66 pa[0] = QPoint( 2, 0 );
67 pa[1] = QPoint( -2, 0 );
68 pa[2] = QPoint( 0, -3 );
69 break;
70 };
71 return pa;
72 }
73
drawShape(QPainter & p)74 void OutputFlowNode::drawShape ( QPainter &p )
75 {
76 const int _x = ( int ) x();
77 const int _y = ( int ) y();
78
79
80
81 if ( m_dir == 0 ) p.drawLine ( _x, _y, _x-8, _y );
82 else if ( m_dir == 90 ) p.drawLine ( _x, _y, _x, _y-8 );
83 else if ( m_dir == 180 ) p.drawLine ( _x, _y, _x+8, _y );
84 else if ( m_dir == 270 ) p.drawLine ( _x, _y, _x, _y+8 );
85
86 QPolygon pa ( 3 );
87
88 switch ( m_dir )
89 {
90 case 0: // right
91 pa = arrowPoints ( 0 );
92 break;
93 case 180: // left
94 pa = arrowPoints ( 180 );
95 break;
96 case 90: // down
97 pa = arrowPoints ( 90 );
98 break;
99 case 270: // up
100 pa = arrowPoints ( 270 );
101 break;
102 default:
103 qCritical() << Q_FUNC_INFO << "BUG: m_dir = " << m_dir << endl;
104 }
105
106
107 // Note: I have not tested the positioning of the arrows for all combinations.
108 // In fact, most almost definitely do not work. So feel free to change the code
109 // as you see fit if necessary.
110
111 if ( m_dir == 0 ) pa.translate ( -5, 0 );
112 else if ( m_dir == 90 ) pa.translate ( 0, -5 );
113 else if ( m_dir == 180 ) pa.translate ( 5, 0 );
114 else if ( m_dir == 270 ) pa.translate ( 0, 5 );
115
116 pa.translate ( _x, _y );
117 p.drawPolygon ( pa );
118 }
119
120