1 #include "qnstgraphicsreference.h"
6 setnstType(Qnst::Reference);
9 QnstGraphicsReference::~QnstGraphicsReference()
14 void QnstGraphicsReference::draw(QPainter* painter)
16 if (getEntityA() != NULL && getEntityB() != NULL)
18 painter->setRenderHint(QPainter::Antialiasing,
true);
20 QLineF line = QLineF(QPointF(getEntityA()->getLeft() + getEntityA()->getWidth()/2,
21 getEntityA()->getTop() + getEntityA()->getHeight()/2),
22 QPointF(getEntityB()->getLeft() + getEntityB()->getWidth()/2,
23 getEntityB()->getTop() + getEntityB()->getHeight()/2));
25 if (getEntityA()->getncgType() == Qncg::Interface)
27 line.setP1(getnstGraphicsParent()->mapFromItem(getEntityA()->getnstGraphicsParent(), line.p1()));
30 if (getEntityB()->getncgType() == Qncg::Interface)
32 line.setP2(getnstGraphicsParent()->mapFromItem(getEntityB()->getnstGraphicsParent(), line.p2()));
37 QPointF pointa = line.p1();
38 QPointF pointb = line.p2();
40 if (pointa.x() <= pointb.x() && pointa.y() <= pointb.y())
42 painter->setPen(QPen(QBrush(QColor(
"#000000")), 1, Qt::DashLine));
44 painter->drawLine(4+6,4+6, 4+6+getWidth()-12, 4+6+getHeight()-12);
46 painter->setBrush(QBrush(QColor(
"#000000")));
47 painter->setPen(Qt::NoPen);
49 p1 = QPointF(4+6+getWidth()-12, 4+6+getHeight()-12);
52 else if (pointa.x() > pointb.x() && pointa.y() < pointb.y())
54 painter->setPen(QPen(QBrush(QColor(
"#000000")), 1, Qt::DashLine));
56 painter->drawLine(4+6+getWidth()-12,4+6, 4+6, 4+6+getHeight()-12);
58 painter->setBrush(QBrush(QColor(
"#000000")));
59 painter->setPen(Qt::NoPen);
61 p1 = QPointF(4+6, 4+6+getHeight()-12);
64 else if (pointa.x() < pointb.x() && pointa.y() > pointb.y())
66 painter->setPen(QPen(QBrush(QColor(
"#000000")), 1, Qt::DashLine));
68 painter->drawLine(4+6, 4+6+getHeight()-12, 4+6+getWidth()-12, 4+6);
70 painter->setBrush(QBrush(QColor(
"#000000")));
71 painter->setPen(Qt::NoPen);
73 p1 = QPointF(4+6+getWidth()-12, 4+6);
76 else if (pointa.x() > pointb.x() && pointa.y() > pointb.y())
78 painter->setPen(QPen(QBrush(QColor(
"#000000")), 1, Qt::DashLine));
80 painter->drawLine(4+6+getWidth()-12, 4+6+getHeight()-12, 4+6, 4+6);
82 painter->setBrush(QBrush(QColor(
"#000000")));
83 painter->setPen(Qt::NoPen);
85 p1 = QPointF(4+6, 4+6);
88 double angle = ::acos(line.dx() / line.length());
92 angle = (PI * 2) - angle;
95 QPointF p2 = p1 - QPointF(sin(angle + PI / 3) * 12, cos(angle + PI / 3) * 12);
96 QPointF p3 = p1 - QPointF(sin(angle + PI - PI / 3) * 12, cos(angle + PI - PI / 3) * 12);
98 QVector<QPointF> polygon;
104 painter->drawPolygon(QPolygonF(polygon));
108 void QnstGraphicsReference::delineate(QPainterPath* painter)
const
110 if (getEntityA() != NULL && getEntityB() != NULL)
112 QLineF line = QLineF(QPointF(getEntityA()->getLeft() + getEntityA()->getWidth()/2,
113 getEntityA()->getTop() + getEntityA()->getHeight()/2),
114 QPointF(getEntityB()->getLeft() + getEntityB()->getWidth()/2,
115 getEntityB()->getTop() + getEntityB()->getHeight()/2));
117 if (getEntityA()->getncgType() == Qncg::Interface)
119 if(getnstGraphicsParent())
120 line.setP1(getnstGraphicsParent()->mapFromItem(getEntityA()->getnstGraphicsParent(), line.p1()));
123 if (getEntityB()->getncgType() == Qncg::Interface)
125 if(getnstGraphicsParent())
126 line.setP2(getnstGraphicsParent()->mapFromItem(getEntityB()->getnstGraphicsParent(), line.p2()));
131 QPointF pointa = line.p1();
132 QPointF pointb = line.p2();
134 if (pointa.x() <= pointb.x() && pointa.y() <= pointb.y())
136 painter->addEllipse(4,4,3,3);
138 p1 = QPointF(4+6+getWidth()-12, 4+6+getHeight()-12);
141 else if (pointa.x() > pointb.x() && pointa.y() < pointb.y())
143 painter->addEllipse(4+getWidth()-3,4,3,3);
145 p1 = QPointF(4+6, 4+6+getHeight()-12);
148 else if (pointa.x() < pointb.x() && pointa.y() > pointb.y())
150 painter->addEllipse(4, 4+getHeight()-3, 3, 3);
152 p1 = QPointF(4+6+getWidth()-12, 4+6);
155 else if (pointa.x() > pointb.x() && pointa.y() > pointb.y())
157 painter->addEllipse(4+getWidth()-3, 4+getHeight()-3, 3, 3);
159 p1 = QPointF(4+6, 4+6);
162 double angle = ::acos(line.dx() / line.length());
166 angle = (PI * 2) - angle;
169 QPointF p2 = p1 - QPointF(sin(angle + PI / 3) * 12, cos(angle + PI / 3) * 12);
170 QPointF p3 = p1 - QPointF(sin(angle + PI - PI / 3) * 12, cos(angle + PI - PI / 3) * 12);
172 QVector<QPointF> polygon;
178 painter->addPolygon(QPolygonF(polygon));