22 #include "scribblearea.h"
24 #include "pencilsettings.h"
25 #include "strokemanager.h"
26 #include "layermanager.h"
29 #include "layervector.h"
30 #include "erasertool.h"
33 EraserTool::EraserTool( QObject *parent )
38 ToolType EraserTool::type()
43 void EraserTool::loadSettings()
45 m_enabledProperties[WIDTH] =
true;
46 m_enabledProperties[FEATHER] =
true;
47 m_enabledProperties[PRESSURE] =
true;
48 m_enabledProperties[INTERPOLATION] =
true;
51 QSettings settings( PENCIL2D, PENCIL2D );
53 properties.width = settings.value(
"eraserWidth" ).toDouble();
54 properties.feather = settings.value(
"eraserFeather" ).toDouble();
56 properties.pressure = settings.value(
"eraserPressure" ).toBool();
57 properties.invisibility = DISABLED;
58 properties.preserveAlpha = OFF;
59 properties.inpolLevel = 0;
62 if ( properties.width <= 0 )
70 void EraserTool::setWidth(
const qreal width)
73 properties.width = width;
76 QSettings settings( PENCIL2D, PENCIL2D );
77 settings.setValue(
"eraserWidth", width);
81 void EraserTool::setFeather(
const qreal feather )
84 properties.feather = feather;
87 QSettings settings( PENCIL2D, PENCIL2D );
88 settings.setValue(
"eraserFeather", feather);
92 void EraserTool::setPressure(
const bool pressure )
95 properties.pressure = pressure;
98 QSettings settings( PENCIL2D, PENCIL2D );
99 settings.setValue(
"eraserPressure", pressure);
103 void EraserTool::setInpolLevel(
const int level)
105 properties.inpolLevel = level;
107 QSettings settings( PENCIL2D, PENCIL2D);
108 settings.setValue(
"lineInpol", level);
113 QCursor EraserTool::cursor()
115 return Qt::CrossCursor;
118 void EraserTool::adjustPressureSensitiveProperties( qreal pressure,
bool mouseDevice )
120 if ( properties.pressure && !mouseDevice )
122 mCurrentPressure = pressure;
126 mCurrentPressure = 1.0;
130 void EraserTool::mousePressEvent( QMouseEvent *event )
132 if ( event->button() == Qt::LeftButton )
134 mEditor->backup( typeName() );
135 mScribbleArea->setAllDirty();
139 mLastBrushPoint = getCurrentPoint();
142 void EraserTool::mouseReleaseEvent( QMouseEvent *event )
145 if ( event->button() == Qt::LeftButton )
147 if ( mScribbleArea->isLayerPaintable() )
158 void EraserTool::mouseMoveEvent( QMouseEvent *event )
161 if ( event->buttons() & Qt::LeftButton )
163 if ( mScribbleArea->isLayerPaintable() )
166 if (properties.inpolLevel != m_pStrokeManager->getInpolLevel()) {
167 m_pStrokeManager->setInpolLevel(properties.inpolLevel);
174 void EraserTool::paintAt( QPointF )
178 void EraserTool::drawStroke()
180 StrokeTool::drawStroke();
183 Layer* layer = mEditor->layers()->currentLayer();
185 if ( layer->type() == Layer::BITMAP )
187 for (
int i = 0; i < p.size(); i++ )
189 p[ i ] = mEditor->view()->mapScreenToCanvas( p[ i ] );
192 qreal opacity = m_pStrokeManager->getPressure();
193 mCurrentWidth = properties.width;
195 qreal brushWidth = (mCurrentWidth + ( m_pStrokeManager->getPressure() * mCurrentWidth)) * 0.5;
196 qreal brushStep = (0.5 * brushWidth) - ((properties.feather/100.0) * brushWidth * 0.5);
197 brushStep = qMax( 1.0, brushStep );
201 QPointF a = mLastBrushPoint;
202 QPointF b = getCurrentPoint();
204 qreal distance = 4 * QLineF( b, a ).length();
205 int steps = qRound( distance ) / brushStep;
207 for (
int i = 0; i < steps; i++ )
209 QPointF point = mLastBrushPoint + ( i + 1 ) * ( brushStep )* ( b - mLastBrushPoint ) / distance;
210 rect.extend( point.toPoint() );
211 mScribbleArea->drawBrush( point,
214 QColor(255, 255, 255, 255),
217 if ( i == ( steps - 1 ) )
219 mLastBrushPoint = point;
223 int rad = qRound( brushWidth ) / 2 + 2;
226 mScribbleArea->paintBitmapBufferRect(rect);
228 mScribbleArea->refreshBitmap( rect, rad );
230 else if ( layer->type() == Layer::VECTOR )
232 qreal brushWidth = 0;
233 if (properties.pressure ) {
234 brushWidth = properties.width * m_pStrokeManager->getPressure();
237 brushWidth = properties.width;
240 QPen pen( Qt::white, brushWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
241 int rad = qRound( ( brushWidth / 2 + 2 ) * mEditor->view()->scaling() );
243 if ( p.size() == 4 ) {
245 QPainterPath path( p[ 0 ] );
246 path.cubicTo( p[ 1 ],
250 mScribbleArea->drawPath( path, pen, Qt::NoBrush, QPainter::CompositionMode_Source );
251 mScribbleArea->refreshVector( path.boundingRect().toRect(), rad );
256 void EraserTool::removeVectorPaint()
258 Layer* layer = mEditor->layers()->currentLayer();
259 if ( layer->type() == Layer::BITMAP )
261 mScribbleArea->paintBitmapBuffer();
262 mScribbleArea->setAllDirty();
263 mScribbleArea->clearBitmapBuffer();
265 else if ( layer->type() == Layer::VECTOR )
267 VectorImage *vectorImage = ( (
LayerVector * )layer )->getLastVectorImageAtFrame( mEditor->currentFrame(), 0 );
271 mScribbleArea->clearBitmapBuffer();
272 vectorImage->deleteSelectedPoints();
274 mScribbleArea->setModified( mEditor->layers()->currentLayerIndex(), mEditor->currentFrame() );
275 mScribbleArea->setAllDirty();
279 void EraserTool::updateStrokes()
281 Layer* layer = mEditor->layers()->currentLayer();
282 if ( layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR )
287 if ( layer->type() == Layer::VECTOR )
289 qreal radius = ( properties.width / 2 ) / mEditor->view()->scaling();
291 ->getVerticesCloseTo( getCurrentPoint(), radius );
292 for (
int i = 0; i < nearbyVertices.size(); i++ )
294 ( (
LayerVector * )layer )->getLastVectorImageAtFrame( mEditor->currentFrame(), 0 )->setSelected( nearbyVertices.at( i ), true );
297 mScribbleArea->setAllDirty();