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 penWidthValueChanged(newWidth);
157 emit toolPropertyChanged(currentTool()->type(), WIDTH);
160void ToolManager::setFeather(
float newFeather)
162 if (std::isnan(newFeather) || newFeather < 0)
167 currentTool()->setFeather(
static_cast<qreal
>(newFeather));
168 emit penFeatherValueChanged(newFeather);
169 emit toolPropertyChanged(currentTool()->type(), FEATHER);
172void ToolManager::setUseFeather(
bool usingFeather)
174 int usingAA = currentTool()->properties.useAA;
175 int value = propertySwitch(usingFeather, usingAA);
177 currentTool()->setAA(value);
178 currentTool()->setUseFeather(usingFeather);
179 emit toolPropertyChanged(currentTool()->type(), USEFEATHER);
180 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
183void ToolManager::setInvisibility(
bool isInvisible)
185 currentTool()->setInvisibility(isInvisible);
186 emit toolPropertyChanged(currentTool()->type(), INVISIBILITY);
189void ToolManager::setPreserveAlpha(
bool isPreserveAlpha)
191 currentTool()->setPreserveAlpha(isPreserveAlpha);
192 emit toolPropertyChanged(currentTool()->type(), PRESERVEALPHA);
195void ToolManager::setVectorMergeEnabled(
bool isVectorMergeEnabled)
197 currentTool()->setVectorMergeEnabled(isVectorMergeEnabled);
198 emit toolPropertyChanged(currentTool()->type(), VECTORMERGE);
201void ToolManager::setBezier(
bool isBezierOn)
203 currentTool()->setBezier(isBezierOn);
204 emit toolPropertyChanged(currentTool()->type(), BEZIER);
207void ToolManager::setPressure(
bool isPressureOn)
209 currentTool()->setPressure(isPressureOn);
210 emit toolPropertyChanged(currentTool()->type(), PRESSURE);
213void ToolManager::setAA(
int usingAA)
215 currentTool()->setAA(usingAA);
216 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
219void ToolManager::setFillMode(
int mode)
221 currentTool()->setFillMode(mode);
222 emit toolPropertyChanged(currentTool()->type(), FILL_MODE);
225void ToolManager::setStabilizerLevel(
int level)
227 currentTool()->setStabilizerLevel(level);
228 emit toolPropertyChanged(currentTool()->type(), STABILIZATION);
231void ToolManager::setTolerance(
int newTolerance)
233 newTolerance = qMax(0, newTolerance);
235 currentTool()->setTolerance(newTolerance);
236 emit toleranceValueChanged(newTolerance);
237 emit toolPropertyChanged(currentTool()->type(), TOLERANCE);
240void ToolManager::setBucketColorToleranceEnabled(
bool enabled)
242 currentTool()->setToleranceEnabled(enabled);
243 emit toolPropertyChanged(currentTool()->type(), USETOLERANCE);
246void ToolManager::setBucketFillExpandEnabled(
bool expandValue)
248 currentTool()->setFillExpandEnabled(expandValue);
249 emit toolPropertyChanged(currentTool()->type(), USEBUCKETFILLEXPAND);
252void ToolManager::setBucketFillExpand(
int expandValue)
254 currentTool()->setFillExpand(expandValue);
255 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLEXPAND);
258void ToolManager::setBucketFillReferenceMode(
int referenceMode)
260 currentTool()->setFillReferenceMode(referenceMode);
261 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLLAYERREFERENCEMODE);
264void ToolManager::setUseFillContour(
bool useFillContour)
266 currentTool()->setUseFillContour(useFillContour);
267 emit toolPropertyChanged(currentTool()->type(), FILLCONTOUR);
270void ToolManager::setShowSelectionInfo(
bool b)
272 currentTool()->setShowSelectionInfo(b);
275void ToolManager::setShowCameraPath(
bool enabled)
278 cameraTool->setShowCameraPath(enabled);
279 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
282void ToolManager::resetCameraPath()
285 cameraTool->resetCameraPath();
286 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
289void ToolManager::resetCameraTransform(CameraFieldOption option)
292 cameraTool->resetTransform(option);
295void ToolManager::setCameraPathDotColor(
int dotColorNum)
298 cameraTool->setPathDotColorType(
static_cast<DotColorType
>(dotColorNum));
299 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
304 return referenceMode == 0;
309int ToolManager::propertySwitch(
bool condition,
int tool)
314 if (condition ==
true)
317 newValue = mOldValue;
320 else if (condition ==
false)
322 value = (newValue == 1) ? 1 : mOldValue;
327void ToolManager::tabletSwitchToEraser()
329 mTabletEraserTool = getTool(ERASER);
333 if (mTemporaryTool ==
nullptr)
335 emit toolChanged(ERASER);
339void ToolManager::tabletRestorePrevTool()
341 if (mTemporaryTool ==
nullptr && mTabletEraserTool !=
nullptr)
343 mTabletEraserTool =
nullptr;
344 emit toolChanged(currentTool()->type());
350 if (mTemporaryTool !=
nullptr)
return false;
351 mTemporaryTriggerKeys = keys;
352 mTemporaryTriggerModifiers = modifiers;
354 setTemporaryTool(eToolType);
358bool ToolManager::setTemporaryTool(ToolType eToolType,
Qt::MouseButtons buttons)
360 if (mTemporaryTool !=
nullptr)
return false;
361 mTemporaryTriggerKeys = {};
363 mTemporaryTriggerMouseButtons = buttons;
364 setTemporaryTool(eToolType);
368bool ToolManager::tryClearTemporaryTool(
Qt::Key key)
389 if (mTemporaryTriggerKeys.
testFlag(key) ||
390 mTemporaryTriggerModifiers.testFlag(modifier))
392 clearTemporaryTool();
400 if (mTemporaryTriggerMouseButtons !=
Qt::NoButton && mTemporaryTriggerMouseButtons.testFlag(button))
402 clearTemporaryTool();
408void ToolManager::setTemporaryTool(ToolType eToolType)
410 mTemporaryTool = getTool(eToolType);
411 emit toolChanged(eToolType);
414void ToolManager::clearTemporaryTool()
416 if (mTemporaryTool) {
418 mTemporaryTool =
nullptr;
420 mTemporaryTriggerKeys = {};
423 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