src/tools/drawtool.cpp

changeset 108
94c92c923713
parent 106
128efb9d148b
child 109
40a1cf2f38f5
equal deleted inserted replaced
107:02f142b399b1 108:94c92c923713
1 #include <QMessageBox> 1 #include <QMessageBox>
2 #include "drawtool.h" 2 #include "drawtool.h"
3
4 static const QBrush brush = {Qt::white};
5 static const QPen pen = {Qt::black};
6 static const QBrush polygonBrush = {QColor{64, 255, 128}};
3 7
4 DrawTool::DrawTool(QObject* parent) : 8 DrawTool::DrawTool(QObject* parent) :
5 BaseTool{parent} {} 9 BaseTool{parent} {}
6 10
7 QString DrawTool::name() const 11 QString DrawTool::name() const
27 QMessageBox::information(nullptr, "test", "close the polygon"); 31 QMessageBox::information(nullptr, "test", "close the polygon");
28 } 32 }
29 else 33 else
30 { 34 {
31 this->polygon.push_back(pos); 35 this->polygon.push_back(pos);
32 auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview).polygons; 36 auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview);
33 previewLayer.clear(); 37 previewLayer.points.resize(this->polygon.size());
34 previewLayer.push_back({this->polygon}); 38 previewLayer.points.back() = {pos, brush, pen};
39 previewLayer.polygons.clear();
40 previewLayer.polygons.push_back({geom::NPolygon{this->polygon}, polygonBrush, pen});
35 if (this->polygon.size() == 4) 41 if (this->polygon.size() == 4)
36 { 42 {
37 QMessageBox::information(nullptr, "test", "close the polygon"); 43 QMessageBox::information(nullptr, "test", "close the polygon");
38 } 44 }
39 } 45 }
40 } 46 }
41 return true; 47 return true;
42 } 48 }
43 49
50 bool DrawTool::mouseMove(const Canvas::MouseMoveInfo& info)
51 {
52 if (this->polygon.size() < 4 and info.worldPosition.has_value())
53 {
54 auto& previewLayer = info.invoker->modifyPreviewLayer(Canvas::DrawToolPreview);
55 previewLayer.points.resize(this->polygon.size() + 1);
56 previewLayer.points.back() = {info.worldPosition.value(), brush, pen};
57 if (previewLayer.polygons.size() > 0)
58 {
59 auto& polygon = previewLayer.polygons.back();
60 polygon.geometry.points.resize(this->polygon.size() + 1);
61 polygon.geometry.points.back() = info.worldPosition.value();
62 }
63 return true;
64 }
65 else
66 {
67 return false;
68 }
69 }
70
44 void DrawTool::reset() 71 void DrawTool::reset()
45 { 72 {
46 this->polygon.clear(); 73 this->polygon.clear();
47 } 74 }

mercurial