-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathGeoPolygon.cpp
56 lines (51 loc) · 1.73 KB
/
GeoPolygon.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
#include "GeoPolygon.h"
GeoPolygon::GeoPolygon(ILong *iL, QList<QPointF> * pointList, bool closePath, quint8 lineWidth, QColor pen, QColor brush) :
Geometry(iGeoPolygon,lineWidth, pen, brush),iLong(iL)
{
closeFlag = closePath;
for(int i=0; i<pointList->size(); i++)
list.append(pointList->at(i));
checkRect();
QPointF tl = iLong->worldToScene(QPointF(rect.minX,rect.minY));
QPointF br = iLong->worldToScene(QPointF(rect.maxX,rect.maxY));
size = fabs(tl.x()-br.x());//polygonWidth.length();
pHeight = fabs(tl.y()-br.y());//polygonHeight.length();
QPointF telta = iLong->worldToScene(QPointF(rect.minX,rect.maxY));
for(int i=0; i<list.size(); i++)
polygon.append(iLong->worldToScene(list.at(i))-telta);
}
QRectF GeoPolygon::boundingRect() const
{
return QRectF(0, 0, size, pHeight);
}
QPainterPath GeoPolygon::shape() const
{
QPainterPath path;
if(closeFlag)
path.addPolygon(polygon);
return path;
}
void GeoPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
QPen xPen(QBrush(pen),lineWidth);
painter->setPen(xPen);
painter->setRenderHint(QPainter::Antialiasing);
if(closeFlag)
painter->setBrush(brush);
QPainterPath path;
path.addPolygon(polygon);
if(closeFlag)
path.closeSubpath();
painter->drawPath(path);
//多段线就不应该显示标注
if((label.length() && closeFlag) ||
(label.length() && polygon.size() == 2 && !closeFlag))
{
QFont font = painter->font();
font.setFamily("Microsoft YaHei");
font.setBold(true);
painter->setFont(font);
painter->setPen(pen);
painter->drawText((size-getLabelPixeSize())/2,pHeight/2,label);
}
}