src/tools/pathtool.cpp

Mon, 16 May 2022 01:40:49 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 16 May 2022 01:40:49 +0300
changeset 187
30204975694a
parent 185
a38a0eb007b0
permissions
-rw-r--r--

work on circle tool

#include "pathtool.h"
#include "modeleditor.h"
#include "linetypes/edge.h"
#include "document.h"

PathTool::PathTool(Document *document) :
	AbstractDrawTool{document}
{
}

QString PathTool::name() const
{
	return tr("Draw path");
}

QString PathTool::toolTip() const
{
	return tr("Draw paths");
}

void PathTool::overpaint(Canvas* canvas, QPainter* painter) const
{
	painter->setPen(QPen{Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin});
	if (this->previewPolygon.size() >= 2)
	{
		canvas->drawWorldPolyline(painter, this->previewPolygon);
	}
	for (const glm::vec3& point : this->polygon)
	{
		canvas->drawWorldPoint(painter, point);
	}
	canvas->drawWorldPoint(painter, this->previewPoint);
}

QString PathTool::iconName() const
{
	return ":/icons/polyline.png";
}

void PathTool::closeShape()
{
	std::unique_ptr<ModelEditor> modelEditor = this->document->editModel();
	for (std::size_t i = 0; i < this->polygon.size() - 1; i += 1)
	{
		modelEditor->append<ldraw::Edge>(std::array{this->polygon[i], this->polygon[i + 1]}, ldraw::EDGE_COLOR);
	}
	this->clearPoints();
}

mercurial