forked from UIDO/UMapControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeoTri.cpp
46 lines (41 loc) · 1.16 KB
/
GeoTri.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
#include "GeoTri.h"
GeoTri::GeoTri(QPointF world, int size, QColor pen, QColor brush) :
Geometry(UM::iGeoTri, size*0.6, pen, brush)
{
list.append(world);
checkRect();
}
QRectF GeoTri::boundingRect() const
{
return QRectF(-size/2, -size/2, size, size);
}
QPainterPath GeoTri::shape() const
{
QPainterPath path;
QPolygonF polygon;
polygon.append(QPointF(0,-size/2));
polygon.append(QPointF(-size/2,size/2));
polygon.append(QPointF(size/2,size/2));
path.addPolygon(polygon);
return path;
}
void GeoTri::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->setPen(pen);
painter->setBrush(brush);
painter->setRenderHint(QPainter::Antialiasing);
QPolygonF polygon;
polygon.append(QPointF(0,-size/2));
polygon.append(QPointF(-size/2,size/2));
polygon.append(QPointF(size/2,size/2));
painter->drawPolygon(polygon);
if(label.length())
{
QFont font = painter->font();
font.setFamily("Microsoft YaHei");
font.setBold(true);
painter->setFont(font);
painter->setPen(brush);
painter->drawText(-getLabelPixeSize()/2,size+5,label);
}
}