17#include "toolmanager.h"
22#include "penciltool.h"
24#include "buckettool.h"
25#include "erasertool.h"
26#include "eyedroppertool.h"
29#include "polylinetool.h"
30#include "selecttool.h"
31#include "smudgetool.h"
32#include "cameratool.h"
40ToolManager::~ToolManager()
42 foreach(
BaseTool* tool, mToolSetHash)
48bool ToolManager::init()
65 pTool->initialize(editor());
84BaseTool* ToolManager::currentTool()
const
86 if (mTemporaryTool !=
nullptr)
88 return mTemporaryTool;
90 else if (mTabletEraserTool !=
nullptr)
92 return mTabletEraserTool;
97BaseTool* ToolManager::getTool(ToolType eToolType)
99 return mToolSetHash[eToolType];
102void ToolManager::setDefaultTool()
106 ToolType defaultToolType = PENCIL;
108 setCurrentTool(defaultToolType);
109 mTabletEraserTool =
nullptr;
110 mTemporaryTool =
nullptr;
113void ToolManager::setCurrentTool(ToolType eToolType)
116 if (mCurrentTool == getTool(eToolType)) {
return; }
118 if (mCurrentTool !=
nullptr)
123 mCurrentTool = getTool(eToolType);
125 if (mTemporaryTool ==
nullptr && mTabletEraserTool ==
nullptr)
127 emit toolChanged(eToolType);
131bool ToolManager::leavingThisTool()
136void ToolManager::cleanupAllToolsData()
138 foreach(
BaseTool* tool, mToolSetHash)
140 tool->clearToolData();
144void ToolManager::resetAllTools()
150 foreach(
BaseTool* tool, mToolSetHash)
152 tool->resetToDefault();
154 qDebug(
"tools restored to default settings");
157void ToolManager::setWidth(
float newWidth)
159 if (std::isnan(newWidth) || newWidth < 0)
164 currentTool()->setWidth(
static_cast<qreal
>(newWidth));
165 emit toolPropertyChanged(currentTool()->type(), WIDTH);
168void ToolManager::setFeather(
float newFeather)
170 if (std::isnan(newFeather) || newFeather < 0)
175 currentTool()->setFeather(
static_cast<qreal
>(newFeather));
176 emit toolPropertyChanged(currentTool()->type(), FEATHER);
179void ToolManager::setUseFeather(
bool usingFeather)
181 int usingAA = currentTool()->properties.useAA;
182 int value = propertySwitch(usingFeather, usingAA);
184 currentTool()->setAA(value);
185 currentTool()->setUseFeather(usingFeather);
186 emit toolPropertyChanged(currentTool()->type(), USEFEATHER);
187 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
190void ToolManager::setInvisibility(
bool isInvisible)
192 currentTool()->setInvisibility(isInvisible);
193 emit toolPropertyChanged(currentTool()->type(), INVISIBILITY);
196void ToolManager::setPreserveAlpha(
bool isPreserveAlpha)
198 currentTool()->setPreserveAlpha(isPreserveAlpha);
199 emit toolPropertyChanged(currentTool()->type(), PRESERVEALPHA);
202void ToolManager::setVectorMergeEnabled(
bool isVectorMergeEnabled)
204 currentTool()->setVectorMergeEnabled(isVectorMergeEnabled);
205 emit toolPropertyChanged(currentTool()->type(), VECTORMERGE);
208void ToolManager::setBezier(
bool isBezierOn)
210 currentTool()->setBezier(isBezierOn);
211 emit toolPropertyChanged(currentTool()->type(), BEZIER);
214void ToolManager::setClosedPath(
bool isPathClosed)
216 currentTool()->setClosedPath(isPathClosed);
217 emit toolPropertyChanged(currentTool()->type(), CLOSEDPATH);
220void ToolManager::setPressure(
bool isPressureOn)
222 currentTool()->setPressure(isPressureOn);
223 emit toolPropertyChanged(currentTool()->type(), PRESSURE);
226void ToolManager::setAA(
int usingAA)
228 currentTool()->setAA(usingAA);
229 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
232void ToolManager::setFillMode(
int mode)
234 currentTool()->setFillMode(mode);
235 emit toolPropertyChanged(currentTool()->type(), FILL_MODE);
238void ToolManager::setStabilizerLevel(
int level)
240 currentTool()->setStabilizerLevel(level);
241 emit toolPropertyChanged(currentTool()->type(), STABILIZATION);
244void ToolManager::setTolerance(
int newTolerance)
246 newTolerance = qMax(0, newTolerance);
248 currentTool()->setTolerance(newTolerance);
249 emit toolPropertyChanged(currentTool()->type(), TOLERANCE);
252void ToolManager::setBucketColorToleranceEnabled(
bool enabled)
254 currentTool()->setToleranceEnabled(enabled);
255 emit toolPropertyChanged(currentTool()->type(), USETOLERANCE);
258void ToolManager::setBucketFillExpandEnabled(
bool expandValue)
260 currentTool()->setFillExpandEnabled(expandValue);
261 emit toolPropertyChanged(currentTool()->type(), USEBUCKETFILLEXPAND);
264void ToolManager::setBucketFillExpand(
int expandValue)
266 currentTool()->setFillExpand(expandValue);
267 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLEXPAND);
270void ToolManager::setBucketFillReferenceMode(
int referenceMode)
272 currentTool()->setFillReferenceMode(referenceMode);
273 emit toolPropertyChanged(currentTool()->type(), BUCKETFILLLAYERREFERENCEMODE);
276void ToolManager::setUseFillContour(
bool useFillContour)
278 currentTool()->setUseFillContour(useFillContour);
279 emit toolPropertyChanged(currentTool()->type(), FILLCONTOUR);
282void ToolManager::setShowSelectionInfo(
bool b)
284 currentTool()->setShowSelectionInfo(b);
287void ToolManager::setShowCameraPath(
bool enabled)
290 cameraTool->setShowCameraPath(enabled);
291 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
294void ToolManager::resetCameraPath()
297 cameraTool->resetCameraPath();
298 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
301void ToolManager::resetCameraTransform(CameraFieldOption option)
304 cameraTool->resetTransform(option);
307void ToolManager::setCameraPathDotColor(
int dotColorNum)
310 cameraTool->setPathDotColorType(
static_cast<DotColorType
>(dotColorNum));
311 emit toolPropertyChanged(cameraTool->type(), CAMERAPATH);
316 return referenceMode == 0;
321int ToolManager::propertySwitch(
bool condition,
int tool)
326 if (condition ==
true)
329 newValue = mOldValue;
332 else if (condition ==
false)
334 value = (newValue == 1) ? 1 : mOldValue;
339void ToolManager::tabletSwitchToEraser()
341 mTabletEraserTool = getTool(ERASER);
345 if (mTemporaryTool ==
nullptr)
347 emit toolChanged(ERASER);
351void ToolManager::tabletRestorePrevTool()
353 if (mTemporaryTool ==
nullptr && mTabletEraserTool !=
nullptr)
355 mTabletEraserTool =
nullptr;
356 emit toolChanged(currentTool()->type());
362 if (mTemporaryTool !=
nullptr)
return false;
363 mTemporaryTriggerKeys = keys;
364 mTemporaryTriggerModifiers = modifiers;
366 setTemporaryTool(eToolType);
370bool ToolManager::setTemporaryTool(ToolType eToolType,
Qt::MouseButtons buttons)
372 if (mTemporaryTool !=
nullptr)
return false;
373 mTemporaryTriggerKeys = {};
375 mTemporaryTriggerMouseButtons = buttons;
376 setTemporaryTool(eToolType);
380bool ToolManager::tryClearTemporaryTool(
Qt::Key key)
401 if (mTemporaryTriggerKeys.
testFlag(key) ||
402 mTemporaryTriggerModifiers.testFlag(modifier))
404 clearTemporaryTool();
412 if (mTemporaryTriggerMouseButtons !=
Qt::NoButton && mTemporaryTriggerMouseButtons.testFlag(button))
414 clearTemporaryTool();
420void ToolManager::setTemporaryTool(ToolType eToolType)
422 mTemporaryTool = getTool(eToolType);
423 emit toolChanged(eToolType);
426void ToolManager::clearTemporaryTool()
428 if (mTemporaryTool) {
430 mTemporaryTool =
nullptr;
432 mTemporaryTriggerKeys = {};
435 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