-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyarrowitem.cpp
68 lines (61 loc) · 1.87 KB
/
myarrowitem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "myarrowitem.h"
#include <QGraphicsScene>
#include <QPainter>
/*
* 构造函数 :
* length : 长度
* dir : 箭头方向 0:上 1:右 2:下 3:左
* size : 有无箭头 0:无箭头 1:有箭头
*/
MyArrowItem::MyArrowItem ( int length, int dir, int size) : direction(dir), arrowSize(size)
{
QPoint startP(0,0), endP, p1, p2;//p1,p2为箭头末端两端点
switch (dir) {
case 0:
p1=p2=endP=QPoint(0,-length);
if(size)
p1+=QPoint(-SIZE1_HEIGHT,SIZE1_WEIGHT),p2+=QPoint(SIZE1_HEIGHT,SIZE1_WEIGHT);
mboundingRect=QRect(-SIZE1_HEIGHT,-length,SIZE1_HEIGHT<<1,length);
break;
case 1:
p1=p2=endP=QPoint(length,0);
if(size)
p1+=QPoint(-SIZE1_WEIGHT,-SIZE1_HEIGHT),p2+=QPoint(-SIZE1_WEIGHT,SIZE1_HEIGHT);
mboundingRect=QRect(0,-SIZE1_HEIGHT,length,SIZE1_HEIGHT<<1);
break;
case 2:
p1=p2=endP=QPoint(0,length);
if(size)
p1+=QPoint(-SIZE1_HEIGHT,-SIZE1_WEIGHT),p2+=QPoint(SIZE1_HEIGHT,-SIZE1_WEIGHT);
mboundingRect=QRect(-SIZE1_HEIGHT,0,SIZE1_HEIGHT<<1,length);
break;
case 3:
p1=p2=endP=QPoint(-length,0);
if(size)
p1+=QPoint(SIZE1_WEIGHT,SIZE1_HEIGHT),p2+=QPoint(SIZE1_WEIGHT,-SIZE1_HEIGHT);
mboundingRect=QRect(-length,-SIZE1_HEIGHT,length,SIZE1_HEIGHT<<1);
break;
default:
break;
}
line1=QLine(startP,endP);
line2=QLine(endP,p1);
line3=QLine(endP,p2);
}
MyArrowItem::~MyArrowItem()
{
}
//执行绘制动作
void MyArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->drawLine(line1);
painter->drawLine(line2);
painter->drawLine(line3);
}
QRectF MyArrowItem::boundingRect() const
{
return mboundingRect;
}