17 #include "toolmanager.h"
21 #include "penciltool.h"
22 #include "brushtool.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"
38 bool ToolManager::init()
40 mIsSwitchedToEraser =
false;
56 pTool->initialize(editor());
74 BaseTool* ToolManager::getTool(ToolType eToolType)
76 return mToolSetHash[eToolType];
79 void ToolManager::setDefaultTool()
83 ToolType defaultToolType = PENCIL;
85 setCurrentTool(defaultToolType);
86 meTabletBackupTool = defaultToolType;
89 void ToolManager::setCurrentTool(ToolType eToolType)
91 if (mCurrentTool !=
nullptr)
96 mCurrentTool = getTool(eToolType);
97 emit toolChanged(eToolType);
100 bool ToolManager::leavingThisTool()
102 return mCurrentTool->leavingThisTool();
105 void ToolManager::cleanupAllToolsData()
107 foreach(
BaseTool* tool, mToolSetHash)
109 tool->clearToolData();
113 void ToolManager::resetAllTools()
119 foreach(
BaseTool* tool, mToolSetHash)
121 tool->resetToDefault();
123 qDebug(
"tools restored to default settings");
126 void ToolManager::setWidth(
float newWidth)
128 if (std::isnan(newWidth) || newWidth < 0)
133 currentTool()->setWidth(static_cast<qreal>(newWidth));
134 emit penWidthValueChanged(newWidth);
135 emit toolPropertyChanged(currentTool()->type(), WIDTH);
138 void ToolManager::setFeather(
float newFeather)
140 if (std::isnan(newFeather) || newFeather < 0)
145 currentTool()->setFeather(static_cast<qreal>(newFeather));
146 emit penFeatherValueChanged(newFeather);
147 emit toolPropertyChanged(currentTool()->type(), FEATHER);
150 void ToolManager::setUseFeather(
bool usingFeather)
152 int usingAA = currentTool()->properties.useAA;
153 int value = propertySwitch(usingFeather, usingAA);
155 currentTool()->setAA(value);
156 currentTool()->setUseFeather(usingFeather);
157 emit toolPropertyChanged(currentTool()->type(), USEFEATHER);
158 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
161 void ToolManager::setInvisibility(
bool isInvisible)
163 currentTool()->setInvisibility(isInvisible);
164 emit toolPropertyChanged(currentTool()->type(), INVISIBILITY);
167 void ToolManager::setPreserveAlpha(
bool isPreserveAlpha)
169 currentTool()->setPreserveAlpha(isPreserveAlpha);
170 emit toolPropertyChanged(currentTool()->type(), PRESERVEALPHA);
173 void ToolManager::setVectorMergeEnabled(
bool isVectorMergeEnabled)
175 currentTool()->setVectorMergeEnabled(isVectorMergeEnabled);
176 emit toolPropertyChanged(currentTool()->type(), VECTORMERGE);
179 void ToolManager::setBezier(
bool isBezierOn)
181 currentTool()->setBezier(isBezierOn);
182 emit toolPropertyChanged(currentTool()->type(), BEZIER);
185 void ToolManager::setPressure(
bool isPressureOn)
187 currentTool()->setPressure(isPressureOn);
188 emit toolPropertyChanged(currentTool()->type(), PRESSURE);
191 void ToolManager::setAA(
int usingAA)
193 currentTool()->setAA(usingAA);
194 emit toolPropertyChanged(currentTool()->type(), ANTI_ALIASING);
197 void ToolManager::setStabilizerLevel(
int level)
199 currentTool()->setStabilizerLevel(level);
200 emit toolPropertyChanged(currentTool()->type(), STABILIZATION);
203 void ToolManager::setTolerance(
int newTolerance)
205 newTolerance = qMax(0, newTolerance);
207 currentTool()->setTolerance(newTolerance);
208 emit toleranceValueChanged(newTolerance);
209 emit toolPropertyChanged(currentTool()->type(), TOLERANCE);
212 void ToolManager::setUseFillContour(
bool useFillContour)
214 currentTool()->setUseFillContour(useFillContour);
215 emit toolPropertyChanged(currentTool()->type(), FILLCONTOUR);
221 int ToolManager::propertySwitch(
bool condition,
int tool)
226 if (condition ==
true) {
228 newValue = mOldValue;
232 if (condition ==
false) {
243 void ToolManager::tabletSwitchToEraser()
245 if (!mIsSwitchedToEraser)
247 mIsSwitchedToEraser =
true;
249 meTabletBackupTool = mCurrentTool->type();
250 setCurrentTool(ERASER);
254 void ToolManager::tabletRestorePrevTool()
256 if (mIsSwitchedToEraser)
258 mIsSwitchedToEraser =
false;
259 if (meTabletBackupTool == INVALID_TOOL)
261 meTabletBackupTool = PENCIL;
263 setCurrentTool(meTabletBackupTool);
QHash::iterator insert(const Key &key, const T &value)
QList< T > values() const const