17#include "toolmanager.h"
22#include "stroketool.h"
24#include "penciltool.h"
26#include "buckettool.h"
27#include "erasertool.h"
28#include "eyedroppertool.h"
31#include "polylinetool.h"
32#include "selecttool.h"
33#include "smudgetool.h"
34#include "cameratool.h"
42ToolManager::~ToolManager()
44 foreach(
BaseTool* tool, mToolSetHash)
50bool ToolManager::init()
67 pTool->initialize(editor());
86BaseTool* ToolManager::currentTool()
const
88 if (mTemporaryTool !=
nullptr)
90 return mTemporaryTool;
92 else if (mTabletEraserTool !=
nullptr)
94 return mTabletEraserTool;
99StrokeTool* ToolManager::currentStrokeTool()
const
101 return dynamic_cast<StrokeTool*
>(mCurrentTool);
104bool ToolManager::isStrokeTool(
const BaseTool *baseTool)
const
106 return dynamic_cast<const StrokeTool*
>(baseTool) !=
nullptr;
109bool ToolManager::isTransformTool(
const BaseTool *baseTool)
const
111 return dynamic_cast<const TransformTool*
>(baseTool) !=
nullptr;
119BaseTool* ToolManager::getTool(ToolType eToolType)
121 return mToolSetHash[eToolType];
124void ToolManager::setDefaultTool()
128 ToolType defaultToolType = PENCIL;
130 setCurrentTool(defaultToolType);
131 mTabletEraserTool =
nullptr;
132 mTemporaryTool =
nullptr;
135void ToolManager::setCurrentTool(ToolType eToolType)
138 if (mCurrentTool == getTool(eToolType)) {
return; }
140 if (mCurrentTool !=
nullptr)
145 mCurrentTool = getTool(eToolType);
147 if (mTemporaryTool ==
nullptr && mTabletEraserTool ==
nullptr)
149 emit toolChanged(eToolType);
153bool ToolManager::leavingThisTool()
158void ToolManager::cleanupAllToolsData()
160 foreach(
BaseTool* tool, mToolSetHash)
162 tool->clearToolData();
166void ToolManager::resetAllTools()
172 foreach(
BaseTool* tool, mToolSetHash)
174 tool->resetSettings();
177 qDebug(
"tools restored to default settings");
180void ToolManager::tabletSwitchToEraser()
182 mTabletEraserTool = getTool(ERASER);
186 if (mTemporaryTool ==
nullptr)
188 emit toolChanged(ERASER);
192void ToolManager::tabletRestorePrevTool()
194 if (mTemporaryTool ==
nullptr && mTabletEraserTool !=
nullptr)
196 mTabletEraserTool =
nullptr;
197 emit toolChanged(currentTool()->type());
203 if (mTemporaryTool !=
nullptr)
return false;
204 mTemporaryTriggerKeys = keys;
205 mTemporaryTriggerModifiers = modifiers;
207 setTemporaryTool(eToolType);
211bool ToolManager::setTemporaryTool(ToolType eToolType,
Qt::MouseButtons buttons)
213 if (mTemporaryTool !=
nullptr)
return false;
214 mTemporaryTriggerKeys = {};
216 mTemporaryTriggerMouseButtons = buttons;
217 setTemporaryTool(eToolType);
221bool ToolManager::tryClearTemporaryTool(
Qt::Key key)
242 if (mTemporaryTriggerKeys.
testFlag(key) ||
243 mTemporaryTriggerModifiers.testFlag(modifier))
245 clearTemporaryTool();
253 if (mTemporaryTriggerMouseButtons !=
Qt::NoButton && mTemporaryTriggerMouseButtons.testFlag(button))
255 clearTemporaryTool();
261void ToolManager::setTemporaryTool(ToolType eToolType)
263 mTemporaryTool = getTool(eToolType);
264 emit toolChanged(eToolType);
267void ToolManager::clearTemporaryTool()
269 if (mTemporaryTool) {
271 mTemporaryTool =
nullptr;
273 mTemporaryTriggerKeys = {};
276 emit toolChanged(currentTool()->type());
bool testFlag(Enum flag) const const
QHash::iterator insert(const Key &key, const T &value)
QList< T > values() const const
typedef KeyboardModifiers