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)
111 mCurrentTool->leavingThisTool();
114 mCurrentTool = getTool(eToolType);
115 if (mTemporaryTool ==
nullptr && mTabletEraserTool ==
nullptr)
117 emit toolChanged(eToolType);
121bool ToolManager::leavingThisTool()
123 return currentTool()->leavingThisTool();
126void ToolManager::cleanupAllToolsData()
128 foreach(
BaseTool* tool, mToolSetHash)
130 tool->clearToolData();
134void ToolManager::resetAllTools()
140 foreach(
BaseTool* tool, mToolSetHash)
142 tool->resetToDefault();
144 qDebug(
"tools restored to default settings");
147void ToolManager::setWidth(
float newWidth)
149 if (std::isnan(newWidth) || newWidth < 0)
154 currentTool()->setWidth(
static_cast<qreal
>(newWidth));
155 emit penWidthValueChanged(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 penFeatherValueChanged(newFeather);
168 emit toolPropertyChanged(currentTool()->type(), FEATHER);
171void ToolManager::setUseFeather(
bool usingFeather)
173 int usingAA = currentTool()->properties.useAA;
174 int value = propertySwitch(usingFeather, usingAA);
176 currentTool()->setAA(value);
177 currentTool()->setUseFeather(usingFeather);
178 emit toolPropertyChanged(currentTool()->type(), USEFEATHER);
179 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
182void ToolManager::setInvisibility(
bool isInvisible)
184 currentTool()->setInvisibility(isInvisible);
185 emit toolPropertyChanged(currentTool()->type(), INVISIBILITY);
188void ToolManager::setPreserveAlpha(
bool isPreserveAlpha)
190 currentTool()->setPreserveAlpha(isPreserveAlpha);
191 emit toolPropertyChanged(currentTool()->type(), PRESERVEALPHA);
194void ToolManager::setVectorMergeEnabled(
bool isVectorMergeEnabled)
196 currentTool()->setVectorMergeEnabled(isVectorMergeEnabled);
197 emit toolPropertyChanged(currentTool()->type(), VECTORMERGE);
200void ToolManager::setBezier(
bool isBezierOn)
202 currentTool()->setBezier(isBezierOn);
203 emit toolPropertyChanged(currentTool()->type(), BEZIER);
206void ToolManager::setPressure(
bool isPressureOn)
208 currentTool()->setPressure(isPressureOn);
209 emit toolPropertyChanged(currentTool()->type(), PRESSURE);
212void ToolManager::setAA(
int usingAA)
214 currentTool()->setAA(usingAA);
215 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
218void ToolManager::setFillMode(
int mode)
220 currentTool()->setFillMode(mode);
221 emit toolPropertyChanged(currentTool()->type(), FILL_MODE);
224void ToolManager::setStabilizerLevel(
int level)
226 currentTool()->setStabilizerLevel(level);
227 emit toolPropertyChanged(currentTool()->type(), STABILIZATION);
230void ToolManager::setTolerance(
int newTolerance)
232 newTolerance = qMax(0, newTolerance);
234 currentTool()->setTolerance(newTolerance);
235 emit toleranceValueChanged(newTolerance);
236 emit toolPropertyChanged(currentTool()->type(), TOLERANCE);
239void ToolManager::setBucketColorToleranceEnabled(
bool enabled)
241 currentTool()->setToleranceEnabled(enabled);
242 emit toolPropertyChanged(currentTool()->type(), USETOLERANCE);
245void ToolManager::setBucketFillExpandEnabled(
bool expandValue)
247 currentTool()->setFillExpandEnabled(expandValue);
248 emit toolPropertyChanged(currentTool()->type(), USEBUCKETFILLEXPAND);
251void ToolManager::setBucketFillExpand(
int expandValue)
253 currentTool()->setFillExpand(expandValue);
254 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLEXPAND);
257void ToolManager::setBucketFillReferenceMode(
int referenceMode)
259 currentTool()->setFillReferenceMode(referenceMode);
260 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLLAYERREFERENCEMODE);
263void ToolManager::setUseFillContour(
bool useFillContour)
265 currentTool()->setUseFillContour(useFillContour);
266 emit toolPropertyChanged(currentTool()->type(), FILLCONTOUR);
269void ToolManager::setShowSelectionInfo(
bool b)
271 currentTool()->setShowSelectionInfo(b);
274void ToolManager::setShowCameraPath(
bool enabled)
277 cameraTool->setShowCameraPath(enabled);
278 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
281void ToolManager::resetCameraPath()
284 cameraTool->resetCameraPath();
285 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
288void ToolManager::resetCameraTransform(CameraFieldOption option)
291 cameraTool->resetTransform(option);
294void ToolManager::setCameraPathDotColor(
int dotColorNum)
297 cameraTool->setPathDotColorType(
static_cast<DotColorType
>(dotColorNum));
298 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
303 return referenceMode == 0;
308int ToolManager::propertySwitch(
bool condition,
int tool)
313 if (condition ==
true)
316 newValue = mOldValue;
319 else if (condition ==
false)
321 value = (newValue == 1) ? 1 : mOldValue;
326void ToolManager::tabletSwitchToEraser()
328 mTabletEraserTool = getTool(ERASER);
332 if (mTemporaryTool ==
nullptr)
334 emit toolChanged(ERASER);
338void ToolManager::tabletRestorePrevTool()
340 if (mTemporaryTool ==
nullptr && mTabletEraserTool !=
nullptr)
342 mTabletEraserTool =
nullptr;
343 emit toolChanged(currentTool()->type());
349 if (mTemporaryTool !=
nullptr)
return false;
350 mTemporaryTriggerKeys = keys;
351 mTemporaryTriggerModifiers = modifiers;
353 setTemporaryTool(eToolType);
357bool ToolManager::setTemporaryTool(ToolType eToolType,
Qt::MouseButtons buttons)
359 if (mTemporaryTool !=
nullptr)
return false;
360 mTemporaryTriggerKeys = {};
362 mTemporaryTriggerMouseButtons = buttons;
363 setTemporaryTool(eToolType);
367bool ToolManager::tryClearTemporaryTool(
Qt::Key key)
388 if (mTemporaryTriggerKeys.
testFlag(key) ||
389 mTemporaryTriggerModifiers.testFlag(modifier))
391 clearTemporaryTool();
399 if (mTemporaryTriggerMouseButtons !=
Qt::NoButton && mTemporaryTriggerMouseButtons.testFlag(button))
401 clearTemporaryTool();
407void ToolManager::setTemporaryTool(ToolType eToolType)
409 mTemporaryTool = getTool(eToolType);
410 emit toolChanged(eToolType);
413void ToolManager::clearTemporaryTool()
415 mTemporaryTool =
nullptr;
416 mTemporaryTriggerKeys = {};
419 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