src/tools/pathtool.cpp

Tue, 24 May 2022 16:11:10 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 24 May 2022 16:11:10 +0300
changeset 188
64ea7282611e
parent 185
a38a0eb007b0
permissions
-rw-r--r--

more work on circle tool + cleanup

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

mercurial