src/tools/selecttool.cpp

Sat, 05 Mar 2022 16:57:28 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 05 Mar 2022 16:57:28 +0200
changeset 168
24590af32ad6
parent 163
36ea1a8aee33
child 185
a38a0eb007b0
permissions
-rw-r--r--

Draw tool now renders the winding of the new polygon

#include "selecttool.h"

SelectTool::SelectTool(Document* document) :
	BaseTool{document},
	objectEditor{new ObjectEditor{document, ldraw::NULL_ID}}
{
}

QString SelectTool::name() const
{
	static const QString result = tr("Select");
	return result;
}

QString SelectTool::toolTip() const
{
	static const QString result = tr("Select elements from the model.");
	return result;
}

bool SelectTool::mouseClick(Document* document, Canvas* canvas, QMouseEvent* event)
{
	if (event->button() == Qt::LeftButton)
	{
		static_cast<void>(document);
		const ldraw::id_t highlighted = canvas->getHighlightedObject();
		canvas->clearSelection();
		if (highlighted != ldraw::NULL_ID)
		{
			canvas->addToSelection(highlighted);
		}
		return true;
	}
	else
	{
		return false;
	}
}

QWidget* SelectTool::toolWidget()
{
	return this->objectEditor;
}

void SelectTool::selectionChanged(const QSet<ldraw::id_t>& newSelection)
{
	if (newSelection.size() == 1)
	{
		this->objectEditor->setObjectId(*newSelection.begin());
	}
	else
	{
		this->objectEditor->setObjectId(ldraw::NULL_ID);
	}
}

QString SelectTool::iconName() const
{
	return ":/icons/navigate-outline.png";
}

mercurial