2 #include <QApplication>
5 #include <QGraphicsSceneMouseEvent>
12 ToolTip
AreaItem::info() const
16 if (!_area
.name().isEmpty())
17 tt
.insert(qApp
->translate("PolygonItem", "Name"), _area
.name());
18 if (!_area
.description().isEmpty())
19 tt
.insert(qApp
->translate("PolygonItem", "Description"),
25 AreaItem::AreaItem(const Area
&area
, Map
*map
, GraphicsItem
*parent
)
26 : PlaneItem(parent
), _area(area
)
32 _penStyle
= Qt::SolidLine
;
34 _pen
= QPen(strokeColor(), width());
35 _brush
= QBrush(fillColor());
37 updatePainterPath(map
);
39 setCursor(Qt::ArrowCursor
);
40 setAcceptHoverEvents(true);
43 QPainterPath
AreaItem::painterPath(Map
*map
, const Polygon
&polygon
)
47 for (int i
= 0; i
< polygon
.size(); i
++) {
48 const QVector
<Coordinates
> &subpath
= polygon
.at(i
);
50 path
.moveTo(map
->ll2xy(subpath
.first()));
51 for (int j
= 1; j
< subpath
.size(); j
++)
52 path
.lineTo(map
->ll2xy(subpath
.at(j
)));
59 void AreaItem::updatePainterPath(Map
*map
)
61 _painterPath
= QPainterPath();
63 for (int i
= 0; i
< _area
.polygons().size(); i
++)
64 _painterPath
.addPath(painterPath(map
, _area
.polygons().at(i
)));
67 void AreaItem::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
,
73 painter
->setPen(_width
? _pen
: QPen(Qt::NoPen
));
74 painter
->drawPath(_painterPath
);
75 painter
->fillPath(_painterPath
, _brush
);
78 QPen p = QPen(QBrush(Qt::red), 0);
80 painter->drawRect(boundingRect());
84 void AreaItem::setMap(Map
*map
)
86 prepareGeometryChange();
87 updatePainterPath(map
);
90 const QColor
&AreaItem::strokeColor() const
92 return (_useStyle
&& _area
.style().isValid())
93 ? _area
.style().stroke() : _color
;
96 QColor
AreaItem::fillColor() const
98 if (_useStyle
&& _area
.style().isValid())
99 return _area
.style().fill();
102 fc
.setAlphaF(_opacity
* _color
.alphaF());
107 void AreaItem::setColor(const QColor
&color
)
113 void AreaItem::updateColor()
115 _pen
.setColor(strokeColor());
116 _brush
= QBrush(fillColor());
120 void AreaItem::setOpacity(qreal opacity
)
126 qreal
AreaItem::width() const
128 return (_useStyle
&& _area
.style().width() > 0)
129 ? _area
.style().width() : _width
;
132 void AreaItem::setWidth(qreal width
)
138 void AreaItem::updateWidth()
140 prepareGeometryChange();
142 _pen
.setWidthF(width() * pow(2, -_digitalZoom
));
145 Qt::PenStyle
AreaItem::penStyle() const
147 return _useStyle
? Qt::SolidLine
: _penStyle
;
150 void AreaItem::setPenStyle(Qt::PenStyle style
)
156 void AreaItem::updatePenStyle()
158 _pen
.setStyle(penStyle());
162 void AreaItem::updateStyle()
169 void AreaItem::setDigitalZoom(int zoom
)
171 if (_digitalZoom
== zoom
)
174 prepareGeometryChange();
177 _pen
.setWidthF(width() * pow(2, -_digitalZoom
));
180 void AreaItem::hoverEnterEvent(QGraphicsSceneHoverEvent
*event
)
184 _pen
.setWidthF((width() + 1) * pow(2, -_digitalZoom
));
188 void AreaItem::hoverLeaveEvent(QGraphicsSceneHoverEvent
*event
)
192 _pen
.setWidthF(width() * pow(2, -_digitalZoom
));