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 "toonzqt/menubarcommand.h"
Kite ce2d82
#include "toonz/preferences.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()
Shinya Kitaoka 120a6e
    : m_tool(0)
Shinya Kitaoka 120a6e
    , m_toolName("")
Shinya Kitaoka 120a6e
    , m_toolTargetType(TTool::NoTarget)
Shinya Kitaoka 120a6e
    , m_storedToolName("")
Shinya Kitaoka 120a6e
    , m_toolIsBusy(false) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ToolHandle::~ToolHandle() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TTool *ToolHandle::getTool() const { return m_tool; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToolHandle::setTool(QString name) {
Shinya Kitaoka 120a6e
  m_oldToolName = m_toolName = name;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TTool *tool = TTool::getTool(m_toolName.toStdString(),
Shinya Kitaoka 120a6e
                               (TTool::ToolTargetType)m_toolTargetType);
Shinya Kitaoka 120a6e
  if (tool == m_tool) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_tool) m_tool->onDeactivate();
Toshihiro Shimizu 890ddd
luz paz 6454c4
  // Camera test uses the automatically activated CameraTestTool
Shinya Kitaoka 120a6e
  if (name != "T_CameraTest" && CameraTestCheck::instance()->isEnabled())
Shinya Kitaoka 120a6e
    CameraTestCheck::instance()->setIsEnabled(false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_tool = tool;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (name != T_Hand && CleanupPreviewCheck::instance()->isEnabled()) {
Shinya Kitaoka 120a6e
    // When using a tool, you have to exit from cleanup preview mode
Shinya Kitaoka 120a6e
    QAction *act = CommandManager::instance()->getAction("MI_CleanupPreview");
Shinya Kitaoka 120a6e
    if (act) CommandManager::instance()->execute(act);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_tool)  // Should always enter
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    m_tool->onActivate();
Shinya Kitaoka 120a6e
    emit toolSwitched();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToolHandle::storeTool() {
Shinya Kitaoka 120a6e
  m_storedToolName = m_toolName;
Shinya Kitaoka 120a6e
  m_storedToolTime.start();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToolHandle::restoreTool() {
Shinya Kitaoka 120a6e
  // qDebug() << m_storedToolTime.elapsed();
Shinya Kitaoka 120a6e
  if (m_storedToolName != m_toolName && m_storedToolName != "" &&
Kite ce2d82
      m_storedToolTime.elapsed() >
Kite ce2d82
          Preferences::instance()->getTempToolSwitchTimer()) {
Shinya Kitaoka 120a6e
    setTool(m_storedToolName);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToolHandle::setPseudoTool(QString name) {
Shinya Kitaoka 120a6e
  QString oldToolName = m_oldToolName;
Shinya Kitaoka 120a6e
  setTool(name);
Shinya Kitaoka 120a6e
  m_oldToolName = oldToolName;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToolHandle::unsetPseudoTool() {
Shinya Kitaoka 120a6e
  if (m_toolName != m_oldToolName) setTool(m_oldToolName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToolHandle::setToolBusy(bool value) {
Shinya Kitaoka 120a6e
  m_toolIsBusy = value;
Shinya Kitaoka 120a6e
  if (!m_toolIsBusy) emit toolEditingFinished();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QIcon currentIcon;
Toshihiro Shimizu 890ddd
Campbell Barton 8c6c57
static 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
Shinya Kitaoka 120a6e
void ToolHandle::onImageChanged(TImage::Type imageType) {
66ffab
  TTool::ToolTargetType targetType = TTool::EmptyTarget;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (imageType) {
Shinya Kitaoka 120a6e
  case TImage::RASTER:
Shinya Kitaoka 120a6e
    targetType = TTool::RasterImage;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TImage::TOONZ_RASTER:
Shinya Kitaoka 120a6e
    targetType = TTool::ToonzImage;
Shinya Kitaoka 120a6e
    break;
249386
  case TImage::MESH:
249386
    targetType = TTool::MeshImage;
249386
    break;
249386
  case TImage::META:
249386
    targetType = TTool::MetaImage;
249386
    break;
Shinya Kitaoka 120a6e
  case TImage::VECTOR:
Shinya Kitaoka 120a6e
    targetType = TTool::VectorImage;
Shinya Kitaoka 120a6e
    break;
66ffab
  default:
66ffab
    targetType = TTool::EmptyTarget;
66ffab
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (targetType != m_toolTargetType) {
Shinya Kitaoka 120a6e
    m_toolTargetType = targetType;
Shinya Kitaoka 120a6e
    setTool(m_toolName);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_tool) {
Shinya Kitaoka 120a6e
    m_tool->updateMatrix();
Shinya Kitaoka 120a6e
    m_tool->onImageChanged();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToolHandle::updateMatrix() {
Shinya Kitaoka 120a6e
  if (m_tool) m_tool->updateMatrix();
Toshihiro Shimizu 890ddd
}