Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tools/toolcommandids.h"
Toshihiro Shimizu 890ddd
#include "timage.h"
Toshihiro Shimizu 890ddd
//#include "tapp.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/menubarcommand.h"
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qmap></qmap>
Toshihiro Shimizu 890ddd
#include <qdebug></qdebug>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// ToolHandle
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolHandle::ToolHandle()
Toshihiro Shimizu 890ddd
	: m_tool(0), m_toolName(""), m_toolTargetType(TTool::NoTarget), m_storedToolName(""), m_toolIsBusy(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolHandle::~ToolHandle()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTool *ToolHandle::getTool() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_tool;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolHandle::setTool(QString name)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_oldToolName = m_toolName = name;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTool *tool = TTool::getTool(m_toolName.toStdString(), (TTool::ToolTargetType)m_toolTargetType);
Toshihiro Shimizu 890ddd
	if (tool == m_tool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_tool)
Toshihiro Shimizu 890ddd
		m_tool->onDeactivate();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Camera test uses the automaticly activated CameraTestTool
Toshihiro Shimizu 890ddd
	if (name != "T_CameraTest" && CameraTestCheck::instance()->isEnabled())
Toshihiro Shimizu 890ddd
		CameraTestCheck::instance()->setIsEnabled(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_tool = tool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (name != T_Hand && CleanupPreviewCheck::instance()->isEnabled()) {
Toshihiro Shimizu 890ddd
		// When using a tool, you have to exit from cleanup preview mode
Toshihiro Shimizu 890ddd
		QAction *act = CommandManager::instance()->getAction("MI_CleanupPreview");
Toshihiro Shimizu 890ddd
		if (act)
Toshihiro Shimizu 890ddd
			CommandManager::instance()->execute(act);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_tool) // Should always enter
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_tool->onActivate();
Toshihiro Shimizu 890ddd
		emit toolSwitched();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolHandle::storeTool()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_storedToolName = m_toolName;
Toshihiro Shimizu 890ddd
	m_storedToolTime.start();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolHandle::restoreTool()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// qDebug() << m_storedToolTime.elapsed();
Toshihiro Shimizu 890ddd
	if (m_storedToolName != m_toolName && m_storedToolName != "" && m_storedToolTime.elapsed() > 500) {
Toshihiro Shimizu 890ddd
		setTool(m_storedToolName);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolHandle::setPseudoTool(QString name)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString oldToolName = m_oldToolName;
Toshihiro Shimizu 890ddd
	setTool(name);
Toshihiro Shimizu 890ddd
	m_oldToolName = oldToolName;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolHandle::unsetPseudoTool()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_toolName != m_oldToolName)
Toshihiro Shimizu 890ddd
		setTool(m_oldToolName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolHandle::setToolBusy(bool value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_toolIsBusy = value;
Toshihiro Shimizu 890ddd
	if (!m_toolIsBusy)
Toshihiro Shimizu 890ddd
		emit toolEditingFinished();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QIcon currentIcon;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QIcon getCurrentIcon() { return currentIcon; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void ToolHandle::changeTool(QAction* action)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolHandle::onImageChanged(TImage::Type imageType)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTool::ToolTargetType targetType = TTool::NoTarget;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	switch (imageType) {
Toshihiro Shimizu 890ddd
	case TImage::RASTER:
Toshihiro Shimizu 890ddd
		targetType = TTool::RasterImage;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		CASE TImage::TOONZ_RASTER : targetType = TTool::ToonzImage;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		CASE TImage::VECTOR : default : targetType = TTool::VectorImage;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		CASE TImage::MESH : targetType = TTool::MeshImage;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (targetType != m_toolTargetType) {
Toshihiro Shimizu 890ddd
		m_toolTargetType = targetType;
Toshihiro Shimizu 890ddd
		setTool(m_toolName);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_tool) {
Toshihiro Shimizu 890ddd
		m_tool->updateMatrix();
Toshihiro Shimizu 890ddd
		m_tool->onImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToolHandle::updateMatrix()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_tool)
Toshihiro Shimizu 890ddd
		m_tool->updateMatrix();
Toshihiro Shimizu 890ddd
}