17#include "toolmanager.h"
21#include "penciltool.h"
23#include "buckettool.h"
24#include "erasertool.h"
25#include "eyedroppertool.h"
28#include "polylinetool.h"
29#include "selecttool.h"
30#include "smudgetool.h"
31#include "cameratool.h"
39ToolManager::~ToolManager()
41 foreach(
BaseTool* tool, mToolSetHash)
47bool ToolManager::init()
64 pTool->initialize(editor());
83BaseTool* ToolManager::currentTool()
const
85 if (mTemporaryTool !=
nullptr)
87 return mTemporaryTool;
89 else if (mTabletEraserTool !=
nullptr)
91 return mTabletEraserTool;
96BaseTool* ToolManager::getTool(ToolType eToolType)
98 return mToolSetHash[eToolType];
101void ToolManager::setDefaultTool()
105 ToolType defaultToolType = PENCIL;
107 setCurrentTool(defaultToolType);
108 mTabletEraserTool =
nullptr;
109 mTemporaryTool =
nullptr;
112void ToolManager::setCurrentTool(ToolType eToolType)
115 if (mCurrentTool == getTool(eToolType)) {
return; }
117 if (mCurrentTool !=
nullptr)
122 mCurrentTool = getTool(eToolType);
124 if (mTemporaryTool ==
nullptr && mTabletEraserTool ==
nullptr)
126 emit toolChanged(eToolType);
130bool ToolManager::leavingThisTool()
135void ToolManager::cleanupAllToolsData()
137 foreach(
BaseTool* tool, mToolSetHash)
139 tool->clearToolData();
143void ToolManager::resetAllTools()
149 foreach(
BaseTool* tool, mToolSetHash)
151 tool->resetToDefault();
153 qDebug(
"tools restored to default settings");
156void ToolManager::setWidth(
float newWidth)
158 if (std::isnan(newWidth) || newWidth < 0)
163 currentTool()->setWidth(
static_cast<qreal
>(newWidth));
164 emit toolPropertyChanged(currentTool()->type(), WIDTH);
167void ToolManager::setFeather(
float newFeather)
169 if (std::isnan(newFeather) || newFeather < 0)
174 currentTool()->setFeather(
static_cast<qreal
>(newFeather));
175 emit toolPropertyChanged(currentTool()->type(), FEATHER);
178void ToolManager::setUseFeather(
bool usingFeather)
180 int usingAA = currentTool()->properties.useAA;
181 int value = propertySwitch(usingFeather, usingAA);
183 currentTool()->setAA(value);
184 currentTool()->setUseFeather(usingFeather);
185 emit toolPropertyChanged(currentTool()->type(), USEFEATHER);
186 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
189void ToolManager::setInvisibility(
bool isInvisible)
191 currentTool()->setInvisibility(isInvisible);
192 emit toolPropertyChanged(currentTool()->type(), INVISIBILITY);
195void ToolManager::setPreserveAlpha(
bool isPreserveAlpha)
197 currentTool()->setPreserveAlpha(isPreserveAlpha);
198 emit toolPropertyChanged(currentTool()->type(), PRESERVEALPHA);
201void ToolManager::setVectorMergeEnabled(
bool isVectorMergeEnabled)
203 currentTool()->setVectorMergeEnabled(isVectorMergeEnabled);
204 emit toolPropertyChanged(currentTool()->type(), VECTORMERGE);
207void ToolManager::setBezier(
bool isBezierOn)
209 currentTool()->setBezier(isBezierOn);
210 emit toolPropertyChanged(currentTool()->type(), BEZIER);
213void ToolManager::setClosedPath(
bool isPathClosed)
215 currentTool()->setClosedPath(isPathClosed);
216 emit toolPropertyChanged(currentTool()->type(), CLOSEDPATH);
219void ToolManager::setPressure(
bool isPressureOn)
221 currentTool()->setPressure(isPressureOn);
222 emit toolPropertyChanged(currentTool()->type(), PRESSURE);
225void ToolManager::setAA(
int usingAA)
227 currentTool()->setAA(usingAA);
228 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
231void ToolManager::setFillMode(
int mode)
233 currentTool()->setFillMode(mode);
234 emit toolPropertyChanged(currentTool()->type(), FILL_MODE);
237void ToolManager::setStabilizerLevel(
int level)
239 currentTool()->setStabilizerLevel(level);
240 emit toolPropertyChanged(currentTool()->type(), STABILIZATION);
243void ToolManager::setTolerance(
int newTolerance)
245 newTolerance = qMax(0, newTolerance);
247 currentTool()->setTolerance(newTolerance);
248 emit toolPropertyChanged(currentTool()->type(), TOLERANCE);
251void ToolManager::setBucketColorToleranceEnabled(
bool enabled)
253 currentTool()->setToleranceEnabled(enabled);
254 emit toolPropertyChanged(currentTool()->type(), USETOLERANCE);
257void ToolManager::setBucketFillExpandEnabled(
bool expandValue)
259 currentTool()->setFillExpandEnabled(expandValue);
260 emit toolPropertyChanged(currentTool()->type(), USEBUCKETFILLEXPAND);
263void ToolManager::setBucketFillExpand(
int expandValue)
265 currentTool()->setFillExpand(expandValue);
266 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLEXPAND);
269void ToolManager::setBucketFillReferenceMode(
int referenceMode)
271 currentTool()->setFillReferenceMode(referenceMode);
272 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLLAYERREFERENCEMODE);
275void ToolManager::setUseFillContour(
bool useFillContour)
277 currentTool()->setUseFillContour(useFillContour);
278 emit toolPropertyChanged(currentTool()->type(), FILLCONTOUR);
281void ToolManager::setShowSelectionInfo(
bool b)
283 currentTool()->setShowSelectionInfo(b);
286void ToolManager::setShowCameraPath(
bool enabled)
289 cameraTool->setShowCameraPath(enabled);
290 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
293void ToolManager::resetCameraPath()
296 cameraTool->resetCameraPath();
297 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
300void ToolManager::resetCameraTransform(CameraFieldOption option)
303 cameraTool->resetTransform(option);
306void ToolManager::setCameraPathDotColor(
int dotColorNum)
309 cameraTool->setPathDotColorType(
static_cast<DotColorType
>(dotColorNum));
310 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
315 return referenceMode == 0;
320int ToolManager::propertySwitch(
bool condition,
int tool)
325 if (condition ==
true)
328 newValue = mOldValue;
331 else if (condition ==
false)
333 value = (newValue == 1) ? 1 : mOldValue;
338void ToolManager::tabletSwitchToEraser()
340 mTabletEraserTool = getTool(ERASER);
344 if (mTemporaryTool ==
nullptr)
346 emit toolChanged(ERASER);
350void ToolManager::tabletRestorePrevTool()
352 if (mTemporaryTool ==
nullptr && mTabletEraserTool !=
nullptr)
354 mTabletEraserTool =
nullptr;
355 emit toolChanged(currentTool()->type());
361 if (mTemporaryTool !=
nullptr)
return false;
362 mTemporaryTriggerKeys = keys;
363 mTemporaryTriggerModifiers = modifiers;
365 setTemporaryTool(eToolType);
369bool ToolManager::setTemporaryTool(ToolType eToolType,
Qt::MouseButtons buttons)
371 if (mTemporaryTool !=
nullptr)
return false;
372 mTemporaryTriggerKeys = {};
374 mTemporaryTriggerMouseButtons = buttons;
375 setTemporaryTool(eToolType);
379bool ToolManager::tryClearTemporaryTool(
Qt::Key key)
400 if (mTemporaryTriggerKeys.
testFlag(key) ||
401 mTemporaryTriggerModifiers.testFlag(modifier))
403 clearTemporaryTool();
411 if (mTemporaryTriggerMouseButtons !=
Qt::NoButton && mTemporaryTriggerMouseButtons.testFlag(button))
413 clearTemporaryTool();
419void ToolManager::setTemporaryTool(ToolType eToolType)
421 mTemporaryTool = getTool(eToolType);
422 emit toolChanged(eToolType);
425void ToolManager::clearTemporaryTool()
427 if (mTemporaryTool) {
429 mTemporaryTool =
nullptr;
431 mTemporaryTriggerKeys = {};
434 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