|
1 #include "pathtool.h" |
|
2 #include "modeleditor.h" |
|
3 #include "linetypes/edge.h" |
|
4 #include "document.h" |
|
5 |
|
6 PathTool::PathTool(Document *document) : |
|
7 AbstractDrawTool{document} |
|
8 { |
|
9 } |
|
10 |
|
11 QString PathTool::name() const |
|
12 { |
|
13 return tr("Draw path"); |
|
14 } |
|
15 |
|
16 QString PathTool::toolTip() const |
|
17 { |
|
18 return tr("Draw paths"); |
|
19 } |
|
20 |
|
21 void PathTool::overpaint(Canvas* canvas, QPainter* painter) const |
|
22 { |
|
23 painter->setPen(QPen{Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin}); |
|
24 if (this->previewPolygon.size() >= 2) |
|
25 { |
|
26 canvas->drawWorldPolyline(painter, this->previewPolygon); |
|
27 } |
|
28 for (const glm::vec3& point : this->polygon) |
|
29 { |
|
30 canvas->drawWorldPoint(painter, point); |
|
31 } |
|
32 canvas->drawWorldPoint(painter, this->previewPoint); |
|
33 } |
|
34 |
|
35 QString PathTool::iconName() const |
|
36 { |
|
37 return ":/icons/polyline.png"; |
|
38 } |
|
39 |
|
40 void PathTool::closeShape() |
|
41 { |
|
42 std::unique_ptr<ModelEditor> modelEditor = this->document->editModel(); |
|
43 for (std::size_t i = 0; i < this->polygon.size() - 1; i += 1) |
|
44 { |
|
45 modelEditor->append<ldraw::Edge>(std::array{this->polygon[i], this->polygon[i + 1]}, ldraw::EDGE_COLOR); |
|
46 } |
|
47 this->clearPoints(); |
|
48 } |