19 #include "penciltool.h"
20 #include "brushtool.h"
21 #include "buckettool.h"
22 #include "erasertool.h"
23 #include "eyedroppertool.h"
26 #include "polylinetool.h"
27 #include "selecttool.h"
28 #include "smudgetool.h"
29 #include "toolmanager.h"
31 #include "pencilsettings.h"
34 ToolManager::ToolManager(QObject* parent ) :
BaseManager( parent )
38 bool ToolManager::init()
40 mIsSwitchedToEraser =
false;
42 mToolSetHash.insert( PEN,
new PenTool( parent() ) );
43 mToolSetHash.insert( PENCIL,
new PencilTool( parent() ) );
44 mToolSetHash.insert( BRUSH,
new BrushTool( parent() ) );
45 mToolSetHash.insert( ERASER,
new EraserTool( parent() ) );
46 mToolSetHash.insert( BUCKET,
new BucketTool( parent() ) );
48 mToolSetHash.insert( HAND,
new HandTool( parent() ) );
49 mToolSetHash.insert( MOVE,
new MoveTool( parent() ) );
50 mToolSetHash.insert( POLYLINE,
new PolylineTool( parent() ) );
51 mToolSetHash.insert( SELECT,
new SelectTool( parent() ) );
52 mToolSetHash.insert( SMUDGE,
new SmudgeTool( parent() ) );
54 foreach(
BaseTool* pTool, mToolSetHash.values() )
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 != NULL)
93 mCurrentTool->leavingThisTool();
95 mCurrentTool = getTool( eToolType );
96 Q_EMIT toolChanged( eToolType );
99 void ToolManager::cleanupAllToolsData()
101 foreach (
BaseTool* pTool, mToolSetHash.values() )
107 void ToolManager::resetAllTools()
112 getTool( PEN )->properties.width = 1.5;
113 getTool( PEN )->properties.inpolLevel = -1;
114 getTool( POLYLINE )->properties.width = 1.5;
115 getTool( PENCIL )->properties.width = 1.0;
116 getTool( PENCIL )->properties.feather = -1.0;
117 getTool( PENCIL )->properties.inpolLevel = -1;
118 getTool( ERASER )->properties.width = 25.0;
119 getTool( ERASER )->properties.feather = 50.0;
120 getTool( BRUSH )->properties.width = 15.0;
121 getTool( BRUSH )->properties.feather = 200.0;
122 getTool( BRUSH )->properties.inpolLevel = -1;
123 getTool( BRUSH )->properties.useFeather =
false;
124 getTool( SMUDGE )->properties.width = 25.0;
125 getTool( SMUDGE )->properties.feather = 200.0;
126 getTool( BUCKET )->properties.tolerance = 10.0;
130 qDebug(
"tools restored to default settings" );
133 void ToolManager::setWidth(
float newWidth )
135 if ( std::isnan( newWidth ) || newWidth < 0 )
140 currentTool()->setWidth(newWidth);
141 Q_EMIT penWidthValueChanged( newWidth );
142 Q_EMIT toolPropertyChanged( currentTool()->type(), WIDTH );
145 void ToolManager::setFeather(
float newFeather )
147 if ( std::isnan( newFeather ) || newFeather < 0 )
152 currentTool()->setFeather(newFeather);
153 Q_EMIT penFeatherValueChanged( newFeather );
154 Q_EMIT toolPropertyChanged( currentTool()->type(), FEATHER );
157 void ToolManager::setUseFeather(
bool usingFeather )
159 int usingAA = currentTool()->properties.useAA;
160 int value = propertySwitch(usingFeather, usingAA);
162 currentTool()->setAA(value);
163 currentTool()->setUseFeather( usingFeather );
164 Q_EMIT toolPropertyChanged( currentTool()->type(), USEFEATHER );
165 Q_EMIT toolPropertyChanged( currentTool()->type(), ANTI_ALIASING );
168 void ToolManager::setInvisibility(
bool isInvisible )
170 currentTool()->setInvisibility(isInvisible);
171 Q_EMIT toolPropertyChanged( currentTool()->type(), INVISIBILITY );
174 void ToolManager::setPreserveAlpha(
bool isPreserveAlpha )
176 currentTool()->setPreserveAlpha(isPreserveAlpha);
177 Q_EMIT toolPropertyChanged( currentTool()->type(), PRESERVEALPHA );
180 void ToolManager::setVectorMergeEnabled(
bool isVectorMergeEnabled)
182 currentTool()->setVectorMergeEnabled(isVectorMergeEnabled);
183 Q_EMIT toolPropertyChanged( currentTool()->type(), VECTORMERGE );
186 void ToolManager::setBezier(
bool isBezierOn )
188 currentTool()->setBezier( isBezierOn );
189 Q_EMIT toolPropertyChanged( currentTool()->type(), BEZIER );
192 void ToolManager::setPressure(
bool isPressureOn )
194 currentTool()->setPressure( isPressureOn );
195 Q_EMIT toolPropertyChanged( currentTool()->type(), PRESSURE );
198 void ToolManager::setAA(
int usingAA )
200 currentTool()->setAA( usingAA );
201 Q_EMIT toolPropertyChanged( currentTool()->type(), ANTI_ALIASING );
204 void ToolManager::setInpolLevel(
int level)
206 currentTool()->setInpolLevel( level );
207 Q_EMIT toolPropertyChanged(currentTool()->type(), INTERPOLATION );
211 void ToolManager::setTolerance(
int newTolerance )
213 if ( newTolerance < 0 )
218 currentTool()->setTolerance( newTolerance );
219 Q_EMIT toleranceValueChanged( newTolerance );
220 Q_EMIT toolPropertyChanged( currentTool()->type(), TOLERANCE );
223 void ToolManager::setUseFillContour(
bool useFillContour)
225 currentTool()->setUseFillContour( useFillContour );
226 Q_EMIT toolPropertyChanged( currentTool()->type(), FILLCONTOUR);
232 int ToolManager::propertySwitch(
bool condition,
int tool)
237 if (condition ==
true){
243 if (condition ==
false) {
253 void ToolManager::tabletSwitchToEraser()
255 if (!mIsSwitchedToEraser)
257 mIsSwitchedToEraser =
true;
259 meTabletBackupTool = mCurrentTool->type();
260 setCurrentTool( ERASER );
264 void ToolManager::tabletRestorePrevTool()
266 if ( mIsSwitchedToEraser )
268 mIsSwitchedToEraser =
false;
269 if ( meTabletBackupTool == INVALID_TOOL )
271 meTabletBackupTool = PENCIL;
273 setCurrentTool( meTabletBackupTool );