2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "tools/toolhandle.h"
|
|
|
|
#include "toonz/stage2.h"
|
|
|
|
#include "tools/tool.h"
|
|
|
|
#include "tools/toolcommandids.h"
|
|
|
|
#include "timage.h"
|
|
|
|
//#include "tapp.h"
|
|
|
|
#include "toonzqt/menubarcommand.h"
|
2021-02-13 08:34:23 +13:00
|
|
|
#include "toonz/preferences.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
#include <QAction>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// ToolHandle
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
ToolHandle::ToolHandle()
|
2016-06-15 18:43:10 +12:00
|
|
|
: m_tool(0)
|
|
|
|
, m_toolName("")
|
|
|
|
, m_toolTargetType(TTool::NoTarget)
|
|
|
|
, m_storedToolName("")
|
|
|
|
, m_toolIsBusy(false) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
ToolHandle::~ToolHandle() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TTool *ToolHandle::getTool() const { return m_tool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void ToolHandle::setTool(QString name) {
|
|
|
|
m_oldToolName = m_toolName = name;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TTool *tool = TTool::getTool(m_toolName.toStdString(),
|
|
|
|
(TTool::ToolTargetType)m_toolTargetType);
|
|
|
|
if (tool == m_tool) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_tool) m_tool->onDeactivate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2021-07-08 13:39:28 +12:00
|
|
|
// Camera test uses the automatically activated CameraTestTool
|
2016-06-15 18:43:10 +12:00
|
|
|
if (name != "T_CameraTest" && CameraTestCheck::instance()->isEnabled())
|
|
|
|
CameraTestCheck::instance()->setIsEnabled(false);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_tool = tool;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (name != T_Hand && CleanupPreviewCheck::instance()->isEnabled()) {
|
|
|
|
// When using a tool, you have to exit from cleanup preview mode
|
|
|
|
QAction *act = CommandManager::instance()->getAction("MI_CleanupPreview");
|
|
|
|
if (act) CommandManager::instance()->execute(act);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_tool) // Should always enter
|
|
|
|
{
|
|
|
|
m_tool->onActivate();
|
|
|
|
emit toolSwitched();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void ToolHandle::storeTool() {
|
|
|
|
m_storedToolName = m_toolName;
|
|
|
|
m_storedToolTime.start();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void ToolHandle::restoreTool() {
|
2021-02-13 08:34:23 +13:00
|
|
|
//qDebug() << m_storedToolTime.elapsed();
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_storedToolName != m_toolName && m_storedToolName != "" &&
|
2021-02-13 08:34:23 +13:00
|
|
|
m_storedToolTime.elapsed() >
|
|
|
|
Preferences::instance()->getTempToolSwitchtimer()) {
|
2016-06-15 18:43:10 +12:00
|
|
|
setTool(m_storedToolName);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void ToolHandle::setPseudoTool(QString name) {
|
|
|
|
QString oldToolName = m_oldToolName;
|
|
|
|
setTool(name);
|
|
|
|
m_oldToolName = oldToolName;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void ToolHandle::unsetPseudoTool() {
|
|
|
|
if (m_toolName != m_oldToolName) setTool(m_oldToolName);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void ToolHandle::setToolBusy(bool value) {
|
|
|
|
m_toolIsBusy = value;
|
|
|
|
if (!m_toolIsBusy) emit toolEditingFinished();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
QIcon currentIcon;
|
|
|
|
|
2016-07-22 16:38:33 +12:00
|
|
|
static QIcon getCurrentIcon() { return currentIcon; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
void ToolHandle::changeTool(QAction* action)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void ToolHandle::onImageChanged(TImage::Type imageType) {
|
|
|
|
TTool::ToolTargetType targetType = TTool::NoTarget;
|
|
|
|
|
|
|
|
switch (imageType) {
|
|
|
|
case TImage::RASTER:
|
|
|
|
targetType = TTool::RasterImage;
|
|
|
|
break;
|
|
|
|
case TImage::TOONZ_RASTER:
|
|
|
|
targetType = TTool::ToonzImage;
|
|
|
|
break;
|
|
|
|
case TImage::VECTOR:
|
|
|
|
default:
|
|
|
|
targetType = TTool::VectorImage;
|
|
|
|
break;
|
|
|
|
case TImage::MESH:
|
|
|
|
targetType = TTool::MeshImage;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetType != m_toolTargetType) {
|
|
|
|
m_toolTargetType = targetType;
|
|
|
|
setTool(m_toolName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_tool) {
|
|
|
|
m_tool->updateMatrix();
|
|
|
|
m_tool->onImageChanged();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void ToolHandle::updateMatrix() {
|
|
|
|
if (m_tool) m_tool->updateMatrix();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|