src/tools/selecttool.cpp

Tue, 02 Nov 2021 15:43:57 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 02 Nov 2021 15:43:57 +0200
changeset 148
e1ced2523cad
parent 143
7b62c52835a1
child 152
03f8e6d42e13
permissions
-rw-r--r--

reworking

#include "selecttool.h"

SelectTool::SelectTool(Model* model, QWidget* parent) :
	BaseTool{model, parent},
	objectEditor{new ObjectEditor{model, ldraw::NULL_ID, parent}} {}

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);
	}
}

mercurial