17#include "erasertool.h"
25#include "scribblearea.h"
26#include "strokemanager.h"
27#include "layermanager.h"
28#include "viewmanager.h"
29#include "layervector.h"
30#include "vectorimage.h"
31#include "pointerevent.h"
38ToolType EraserTool::type()
43void EraserTool::loadSettings()
45 mPropertyEnabled[WIDTH] =
true;
46 mPropertyEnabled[USEFEATHER] =
true;
47 mPropertyEnabled[FEATHER] =
true;
48 mPropertyEnabled[USEFEATHER] =
true;
49 mPropertyEnabled[PRESSURE] =
true;
50 mPropertyEnabled[STABILIZATION] =
true;
51 mPropertyEnabled[ANTI_ALIASING] =
true;
55 properties.width = settings.value(
"eraserWidth", 24.0).toDouble();
56 properties.feather = settings.value(
"eraserFeather", 48.0).toDouble();
57 properties.useFeather = settings.value(
"eraserUseFeather",
true).toBool();
58 properties.pressure = settings.value(
"eraserPressure",
true).toBool();
59 properties.invisibility = DISABLED;
60 properties.preserveAlpha = OFF;
61 properties.stabilizerLevel = settings.value(
"stabilizerLevel", StabilizationLevel::NONE).toInt();
62 properties.useAA = settings.value(
"eraserAA", 1).toInt();
64 if (properties.useFeather) { properties.useAA = -1; }
70void EraserTool::resetToDefault()
77 setStabilizerLevel(StabilizationLevel::NONE);
80void EraserTool::setWidth(
const qreal width)
83 properties.width = width;
87 settings.setValue(
"eraserWidth", width);
91void EraserTool::setUseFeather(
const bool usingFeather)
94 properties.useFeather = usingFeather;
98 settings.setValue(
"eraserUseFeather", usingFeather);
102void EraserTool::setFeather(
const qreal feather)
105 properties.feather = feather;
109 settings.setValue(
"eraserFeather", feather);
113void EraserTool::setPressure(
const bool pressure)
116 properties.pressure = pressure;
120 settings.setValue(
"eraserPressure", pressure);
124void EraserTool::setAA(
const int AA)
127 properties.useAA = AA;
131 settings.setValue(
"eraserAA", AA);
135void EraserTool::setStabilizerLevel(
const int level)
137 properties.stabilizerLevel = level;
140 settings.setValue(
"stabilizerLevel", level);
152 startStroke(
event->inputType());
153 mLastBrushPoint = getCurrentPoint();
154 mMouseDownPoint = getCurrentPoint();
161 mCurrentPressure = strokeManager()->getPressure();
163 if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel())
164 strokeManager()->setStabilizerLevel(properties.stabilizerLevel);
168void EraserTool::pointerReleaseEvent(
PointerEvent *event)
170 if (
event->inputType() != mCurrentInputType)
return;
172 mEditor->backup(typeName());
174 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
177 paintAt(mMouseDownPoint);
188void EraserTool::paintAt(
QPointF point)
190 Layer* layer = mEditor->layers()->currentLayer();
191 if (layer->type() == Layer::BITMAP)
193 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
194 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
195 qreal brushWidth = properties.width * pressure;
196 mCurrentWidth = brushWidth;
198 mScribbleArea->drawBrush(point,
201 QColor(255, 255, 255, 255),
203 properties.useFeather,
204 properties.useAA == ON);
208void EraserTool::drawStroke()
210 StrokeTool::drawStroke();
213 Layer* layer = mEditor->layers()->currentLayer();
215 if (layer->type() == Layer::BITMAP)
217 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
218 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
219 qreal brushWidth = properties.width * pressure;
220 mCurrentWidth = brushWidth;
222 qreal brushStep = (0.5 * brushWidth);
223 brushStep = qMax(1.0, brushStep);
231 int steps = qRound(distance / brushStep);
233 for (
int i = 0; i < steps; i++)
235 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
237 mScribbleArea->drawBrush(point,
242 properties.useFeather,
243 properties.useAA == ON);
244 if (i == (steps - 1))
246 mLastBrushPoint = getCurrentPoint();
250 else if (layer->type() == Layer::VECTOR)
252 mCurrentWidth = properties.width;
253 if (properties.pressure)
255 mCurrentWidth = (mCurrentWidth + (strokeManager()->getPressure() * mCurrentWidth)) * 0.5;
257 qreal brushWidth = mCurrentWidth;
272void EraserTool::removeVectorPaint()
274 Layer* layer = mEditor->layers()->currentLayer();
275 if (layer->type() == Layer::BITMAP)
277 mScribbleArea->paintBitmapBuffer();
278 mScribbleArea->clearBitmapBuffer();
280 else if (layer->type() == Layer::VECTOR)
282 mScribbleArea->clearBitmapBuffer();
283 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
284 if (vectorImage ==
nullptr) {
return; }
290 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
294void EraserTool::updateStrokes()
296 Layer* layer = mEditor->layers()->currentLayer();
297 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
302 if (layer->type() == Layer::VECTOR)
304 qreal radius = properties.width / 2;
306 VectorImage* currKey =
static_cast<VectorImage*
>(layer->getLastKeyFrameAtPosition(mEditor->currentFrame()));
308 for (
auto nearbyVertice : nearbyVertices)
void setSelected(int curveNumber, bool YesOrNo)
VectorImage::setSelected.
void deleteSelectedPoints()
VectorImage::deleteSelectedPoints.
QList< VertexRef > getVerticesCloseTo(QPointF thisPoint, qreal maxDistance)
VectorImage::getVerticesCloseTo.
QHash::iterator insert(const Key &key, const T &value)
qreal length() const const
virtual bool event(QEvent *e)