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"
39bool ToolManager::init()
56 pTool->initialize(editor());
75BaseTool* ToolManager::currentTool()
const
77 if (mTemporaryTool !=
nullptr)
79 return mTemporaryTool;
81 else if (mTabletEraserTool !=
nullptr)
83 return mTabletEraserTool;
88BaseTool* ToolManager::getTool(ToolType eToolType)
90 return mToolSetHash[eToolType];
93void ToolManager::setDefaultTool()
97 ToolType defaultToolType = PENCIL;
99 setCurrentTool(defaultToolType);
100 mTabletEraserTool =
nullptr;
101 mTemporaryTool =
nullptr;
104void ToolManager::setCurrentTool(ToolType eToolType)
107 if (mCurrentTool == getTool(eToolType)) {
return; }
109 if (mCurrentTool !=
nullptr)
114 mCurrentTool = getTool(eToolType);
116 if (mTemporaryTool ==
nullptr && mTabletEraserTool ==
nullptr)
118 emit toolChanged(eToolType);
122bool ToolManager::leavingThisTool()
127void ToolManager::cleanupAllToolsData()
129 foreach(
BaseTool* tool, mToolSetHash)
131 tool->clearToolData();
135void ToolManager::resetAllTools()
141 foreach(
BaseTool* tool, mToolSetHash)
143 tool->resetToDefault();
145 qDebug(
"tools restored to default settings");
148void ToolManager::setWidth(
float newWidth)
150 if (std::isnan(newWidth) || newWidth < 0)
155 currentTool()->setWidth(
static_cast<qreal
>(newWidth));
156 emit toolPropertyChanged(currentTool()->type(), WIDTH);
159void ToolManager::setFeather(
float newFeather)
161 if (std::isnan(newFeather) || newFeather < 0)
166 currentTool()->setFeather(
static_cast<qreal
>(newFeather));
167 emit toolPropertyChanged(currentTool()->type(), FEATHER);
170void ToolManager::setUseFeather(
bool usingFeather)
172 int usingAA = currentTool()->properties.useAA;
173 int value = propertySwitch(usingFeather, usingAA);
175 currentTool()->setAA(value);
176 currentTool()->setUseFeather(usingFeather);
177 emit toolPropertyChanged(currentTool()->type(), USEFEATHER);
178 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
181void ToolManager::setInvisibility(
bool isInvisible)
183 currentTool()->setInvisibility(isInvisible);
184 emit toolPropertyChanged(currentTool()->type(), INVISIBILITY);
187void ToolManager::setPreserveAlpha(
bool isPreserveAlpha)
189 currentTool()->setPreserveAlpha(isPreserveAlpha);
190 emit toolPropertyChanged(currentTool()->type(), PRESERVEALPHA);
193void ToolManager::setVectorMergeEnabled(
bool isVectorMergeEnabled)
195 currentTool()->setVectorMergeEnabled(isVectorMergeEnabled);
196 emit toolPropertyChanged(currentTool()->type(), VECTORMERGE);
199void ToolManager::setBezier(
bool isBezierOn)
201 currentTool()->setBezier(isBezierOn);
202 emit toolPropertyChanged(currentTool()->type(), BEZIER);
205void ToolManager::setClosedPath(
bool isPathClosed)
207 currentTool()->setClosedPath(isPathClosed);
208 emit toolPropertyChanged(currentTool()->type(), CLOSEDPATH);
211void ToolManager::setPressure(
bool isPressureOn)
213 currentTool()->setPressure(isPressureOn);
214 emit toolPropertyChanged(currentTool()->type(), PRESSURE);
217void ToolManager::setAA(
int usingAA)
219 currentTool()->setAA(usingAA);
220 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
223void ToolManager::setFillMode(
int mode)
225 currentTool()->setFillMode(mode);
226 emit toolPropertyChanged(currentTool()->type(), FILL_MODE);
229void ToolManager::setStabilizerLevel(
int level)
231 currentTool()->setStabilizerLevel(level);
232 emit toolPropertyChanged(currentTool()->type(), STABILIZATION);
235void ToolManager::setTolerance(
int newTolerance)
237 newTolerance = qMax(0, newTolerance);
239 currentTool()->setTolerance(newTolerance);
240 emit toolPropertyChanged(currentTool()->type(), TOLERANCE);
243void ToolManager::setBucketColorToleranceEnabled(
bool enabled)
245 currentTool()->setToleranceEnabled(enabled);
246 emit toolPropertyChanged(currentTool()->type(), USETOLERANCE);
249void ToolManager::setBucketFillExpandEnabled(
bool expandValue)
251 currentTool()->setFillExpandEnabled(expandValue);
252 emit toolPropertyChanged(currentTool()->type(), USEBUCKETFILLEXPAND);
255void ToolManager::setBucketFillExpand(
int expandValue)
257 currentTool()->setFillExpand(expandValue);
258 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLEXPAND);
261void ToolManager::setBucketFillReferenceMode(
int referenceMode)
263 currentTool()->setFillReferenceMode(referenceMode);
264 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLLAYERREFERENCEMODE);
267void ToolManager::setUseFillContour(
bool useFillContour)
269 currentTool()->setUseFillContour(useFillContour);
270 emit toolPropertyChanged(currentTool()->type(), FILLCONTOUR);
273void ToolManager::setShowSelectionInfo(
bool b)
275 currentTool()->setShowSelectionInfo(b);
278void ToolManager::setShowCameraPath(
bool enabled)
281 cameraTool->setShowCameraPath(enabled);
282 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
285void ToolManager::resetCameraPath()
288 cameraTool->resetCameraPath();
289 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
292void ToolManager::resetCameraTransform(CameraFieldOption option)
295 cameraTool->resetTransform(option);
298void ToolManager::setCameraPathDotColor(
int dotColorNum)
301 cameraTool->setPathDotColorType(
static_cast<DotColorType
>(dotColorNum));
302 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
307 return referenceMode == 0;
312int ToolManager::propertySwitch(
bool condition,
int tool)
317 if (condition ==
true)
320 newValue = mOldValue;
323 else if (condition ==
false)
325 value = (newValue == 1) ? 1 : mOldValue;
330void ToolManager::tabletSwitchToEraser()
332 mTabletEraserTool = getTool(ERASER);
336 if (mTemporaryTool ==
nullptr)
338 emit toolChanged(ERASER);
342void ToolManager::tabletRestorePrevTool()
344 if (mTemporaryTool ==
nullptr && mTabletEraserTool !=
nullptr)
346 mTabletEraserTool =
nullptr;
347 emit toolChanged(currentTool()->type());
353 if (mTemporaryTool !=
nullptr)
return false;
354 mTemporaryTriggerKeys = keys;
355 mTemporaryTriggerModifiers = modifiers;
357 setTemporaryTool(eToolType);
361bool ToolManager::setTemporaryTool(ToolType eToolType,
Qt::MouseButtons buttons)
363 if (mTemporaryTool !=
nullptr)
return false;
364 mTemporaryTriggerKeys = {};
366 mTemporaryTriggerMouseButtons = buttons;
367 setTemporaryTool(eToolType);
371bool ToolManager::tryClearTemporaryTool(
Qt::Key key)
392 if (mTemporaryTriggerKeys.
testFlag(key) ||
393 mTemporaryTriggerModifiers.testFlag(modifier))
395 clearTemporaryTool();
403 if (mTemporaryTriggerMouseButtons !=
Qt::NoButton && mTemporaryTriggerMouseButtons.testFlag(button))
405 clearTemporaryTool();
411void ToolManager::setTemporaryTool(ToolType eToolType)
413 mTemporaryTool = getTool(eToolType);
414 emit toolChanged(eToolType);
417void ToolManager::clearTemporaryTool()
419 if (mTemporaryTool) {
421 mTemporaryTool =
nullptr;
423 mTemporaryTriggerKeys = {};
426 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