src/tools/selecttool.cpp

Sun, 12 Sep 2021 12:14:32 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 12 Sep 2021 12:14:32 +0300
changeset 128
7c834fe36b25
parent 126
a7c720aff97c
child 143
7b62c52835a1
permissions
-rw-r--r--

Moved automatic grid adjusting into a new action

#include "selecttool.h"

SelectTool::SelectTool(Model* model, QObject* parent) :
	BaseTool{model, parent},
	objectEditor{model, ldraw::NULL_ID, nullptr} {}

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