src/tools/pathtool.cpp

Tue, 15 Mar 2022 19:48:07 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 15 Mar 2022 19:48:07 +0200
changeset 185
a38a0eb007b0
permissions
-rw-r--r--

Added line path 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