22 #include "toolmanager.h"
23 #include "scribblearea.h"
24 #include "strokemanager.h"
28 ToolPropertyType BaseTool::assistedSettingType;
29 qreal BaseTool::OriginalSettingValue;
30 bool BaseTool::isAdjusting =
false;
33 QString BaseTool::TypeName( ToolType type )
35 static std::array< QString, TOOL_TYPE_COUNT > map;
37 if ( map[ 0 ].isEmpty() )
39 map[ PENCIL ] = tr(
"Pencil" );
40 map[ ERASER ] = tr(
"Eraser" );
41 map[ SELECT ] = tr(
"Select" );
42 map[ MOVE ] = tr(
"Move" );
43 map[ HAND ] = tr(
"Hand" );
44 map[ SMUDGE ] = tr(
"Smudge" );
45 map[ PEN ] = tr(
"Pen" );
46 map[ POLYLINE ] = tr(
"Polyline" );
47 map[ BUCKET ] = tr(
"Bucket" );
48 map[ EYEDROPPER ] = tr(
"Eyedropper" );
49 map[ BRUSH ] = tr(
"Brush" );
52 return map.at( type );
55 BaseTool::BaseTool( QObject *parent ) : QObject( parent )
57 m_enabledProperties.insert( WIDTH,
false );
58 m_enabledProperties.insert( FEATHER,
false );
59 m_enabledProperties.insert( USEFEATHER,
false );
60 m_enabledProperties.insert( PRESSURE,
false );
61 m_enabledProperties.insert( INVISIBILITY,
false );
62 m_enabledProperties.insert( PRESERVEALPHA,
false );
63 m_enabledProperties.insert( BEZIER,
false );
64 m_enabledProperties.insert( ANTI_ALIASING,
false );
65 m_enabledProperties.insert( INTERPOLATION,
false );
68 QCursor BaseTool::cursor()
70 return Qt::ArrowCursor;
73 void BaseTool::initialize(
Editor* editor )
79 qCritical(
"ERROR: editor is null!" );
82 mScribbleArea = editor->getScribbleArea();
85 Q_ASSERT( mScribbleArea );
87 if ( mScribbleArea == NULL )
89 qCritical(
"ERROR: mScribbleArea is null in editor!" );
93 m_pStrokeManager = mEditor->getScribbleArea()->getStrokeManager();
112 void BaseTool::mouseDoubleClickEvent( QMouseEvent *event )
114 mousePressEvent( event );
123 Q_ASSERT( mEditor->getScribbleArea() );
125 propWidth = properties.width;
126 propFeather = properties.feather;
127 cursorWidth = propWidth + 0.5 * propFeather;
129 if ( cursorWidth < 1 ) { cursorWidth = 1; }
130 radius = cursorWidth / 2;
131 xyA = 1 + propFeather / 2;
132 xyB = 1 + propFeather / 8;
133 whA = qMax( 0, propWidth - xyA - 1 );
134 whB = qMax( 0, cursorWidth - propFeather / 4 - 2 );
135 cursorPixmap = QPixmap( cursorWidth, cursorWidth );
136 if ( !cursorPixmap.isNull() )
138 cursorPixmap.fill( QColor( 255, 255, 255, 0 ) );
139 QPainter cursorPainter( &cursorPixmap );
140 cursorPen = cursorPainter.pen();
141 cursorPainter.translate(-1,-1);
144 cursorPen.setStyle( Qt::SolidLine );
145 cursorPen.setColor( QColor( 0, 0, 0, 127 ) );
146 cursorPainter.setPen(cursorPen);
147 cursorPainter.drawLine( QPointF( radius - 2, radius ), QPointF( radius + 2, radius ) );
148 cursorPainter.drawLine( QPointF( radius, radius - 2 ), QPointF( radius, radius + 2 ) );
151 cursorPen.setStyle( Qt::DotLine );
152 cursorPen.setColor( QColor( 0, 0, 0, 255 ) );
153 cursorPainter.setPen(cursorPen);
154 cursorPainter.drawEllipse( QRectF( xyB, xyB, whB, whB ) );
155 cursorPen.setDashOffset( 4 );
156 cursorPen.setColor( QColor( 255, 255, 255, 255 ) );
157 cursorPainter.setPen(cursorPen);
158 cursorPainter.drawEllipse( QRectF( xyB, xyB, whB, whB ) );
161 cursorPen.setStyle( Qt::DotLine );
162 cursorPen.setColor( QColor( 0, 0, 0, 255 ) );
163 cursorPainter.setPen(cursorPen);
164 cursorPainter.drawEllipse( QRectF( xyA, xyA, whA, whA ) );
165 cursorPen.setDashOffset( 4 );
166 cursorPen.setColor( QColor( 255, 255, 255, 255 ) );
167 cursorPainter.setPen(cursorPen);
168 cursorPainter.drawEllipse( QRectF( xyA, xyA, whA, whA ) );
181 Q_ASSERT( mEditor->getScribbleArea() );
183 propWidth = properties.width;
184 propFeather = properties.feather;
185 cursorWidth = propWidth + 0.5 * propFeather;
187 if ( cursorWidth < 1 ) { cursorWidth = 1; }
188 radius = cursorWidth / 2;
189 xyA = 1 + propFeather / 2;
190 xyB = 1 + propFeather / 8;
191 whA = qMax( 0, propWidth - xyA - 1 );
192 whB = qMax( 0, cursorWidth - propFeather / 4 - 2 );
193 cursorPixmap = QPixmap( cursorWidth, cursorWidth );
194 if ( !cursorPixmap.isNull() )
196 cursorPixmap.fill( QColor( 255, 255, 255, 0 ) );
197 QPainter cursorPainter( &cursorPixmap );
198 cursorPainter.setPen( QColor( 0, 0, 0, 255 ) );
199 cursorPainter.drawLine( QPointF( radius - 2, radius ), QPointF( radius + 2, radius ) );
200 cursorPainter.drawLine( QPointF( radius, radius - 2 ), QPointF( radius, radius + 2 ) );
201 cursorPainter.setRenderHints( QPainter::Antialiasing,
true );
202 cursorPainter.setPen( QColor( 0, 0, 0, 0 ) );
203 cursorPainter.setBrush( QColor( 0, 255, 127, 64 ) );
204 cursorPainter.setCompositionMode( QPainter::CompositionMode_Exclusion );
205 cursorPainter.drawEllipse( QRectF( xyB, xyB, whB, whB ) );
206 cursorPainter.setBrush( QColor( 255, 64, 0, 255 ) );
207 cursorPainter.drawEllipse( QRectF( xyA, xyA, whA, whA ) );
213 void BaseTool::startAdjusting( ToolPropertyType argSettingType, qreal argStep )
216 assistedSettingType = argSettingType;
217 mAdjustmentStep = argStep;
218 if ( argSettingType == WIDTH )
220 OriginalSettingValue = properties.width;
222 else if ( argSettingType == FEATHER )
224 OriginalSettingValue = properties.feather;
226 mEditor->getScribbleArea()->updateCanvasCursor();
229 void BaseTool::stopAdjusting()
233 OriginalSettingValue = 0;
234 mEditor->getScribbleArea()->updateCanvasCursor();
237 void BaseTool::adjustCursor( qreal argOffsetX, ToolPropertyType type )
239 qreal inc = pow( OriginalSettingValue * 100, 0.5 );
240 qreal newValue = inc + argOffsetX;
241 int max = type == FEATHER ? 64 : 200;
242 int min = type == FEATHER ? 2 : 1;
249 newValue = pow( newValue, 2 ) / 100;
250 if ( mAdjustmentStep > 0 )
252 int tempValue = ( int )( newValue / mAdjustmentStep );
253 newValue = tempValue * mAdjustmentStep;
255 if ( newValue < min )
259 else if ( newValue > max )
266 if ( ( this->type() == BRUSH ) || ( this->type() == ERASER ) || ( this->type() == SMUDGE ) )
268 mEditor->tools()->setFeather( newValue );
272 mEditor->tools()->setWidth( newValue );
279 void BaseTool::adjustPressureSensitiveProperties( qreal pressure,
bool mouseDevice )
281 Q_UNUSED( pressure );
282 Q_UNUSED( mouseDevice );
285 QPointF BaseTool::getCurrentPixel()
287 return m_pStrokeManager->getCurrentPixel();
290 QPointF BaseTool::getCurrentPoint()
292 return mEditor->view()->mapScreenToCanvas( getCurrentPixel() );
295 QPointF BaseTool::getLastPixel()
297 return m_pStrokeManager->getLastPixel();
300 QPointF BaseTool::getLastPoint()
302 return mEditor->view()->mapScreenToCanvas( getLastPixel() );
305 QPointF BaseTool::getLastPressPixel()
307 return m_pStrokeManager->getLastPressPixel();
310 QPointF BaseTool::getLastPressPoint()
312 return mEditor->view()->mapScreenToCanvas( getLastPressPixel() );
315 void BaseTool::setWidth(
const qreal width )
317 properties.width = width;
320 void BaseTool::setFeather(
const qreal feather )
322 properties.feather = feather;
325 void BaseTool::setUseFeather(
const bool usingFeather )
327 properties.useFeather = usingFeather;
330 void BaseTool::setInvisibility(
const bool invisibility )
332 properties.invisibility = invisibility;
335 void BaseTool::setBezier(
const bool _bezier_state )
337 properties.bezier_state = _bezier_state;
340 void BaseTool::setPressure(
const bool pressure )
342 properties.pressure = pressure;
345 void BaseTool::setPreserveAlpha(
const bool preserveAlpha )
347 properties.preserveAlpha = preserveAlpha;
350 void BaseTool::setVectorMergeEnabled(
const bool vectorMergeEnabled)
352 properties.vectorMergeEnabled = vectorMergeEnabled;
355 void BaseTool::setAA(
const int useAA)
357 properties.useAA = useAA;
360 void BaseTool::setInpolLevel(
const int level)
362 properties.inpolLevel = level;
365 void BaseTool::setTolerance(
const int tolerance)
367 properties.tolerance = tolerance;
370 void BaseTool::setUseFillContour(
const bool useFillContour)
372 properties.useFillContour = useFillContour;