17#include "erasertool.h"
25#include "scribblearea.h"
26#include "layermanager.h"
27#include "viewmanager.h"
28#include "undoredomanager.h"
29#include "layervector.h"
30#include "vectorimage.h"
31#include "pointerevent.h"
38ToolType EraserTool::type()
43void EraserTool::loadSettings()
47 mPropertyEnabled[WIDTH] =
true;
48 mPropertyEnabled[USEFEATHER] =
true;
49 mPropertyEnabled[FEATHER] =
true;
50 mPropertyEnabled[USEFEATHER] =
true;
51 mPropertyEnabled[PRESSURE] =
true;
52 mPropertyEnabled[STABILIZATION] =
true;
53 mPropertyEnabled[ANTI_ALIASING] =
true;
57 properties.width = settings.value(
"eraserWidth", 24.0).toDouble();
58 properties.feather = settings.value(
"eraserFeather", 48.0).toDouble();
59 properties.useFeather = settings.value(
"eraserUseFeather",
true).toBool();
60 properties.pressure = settings.value(
"eraserPressure",
true).toBool();
61 properties.invisibility = DISABLED;
62 properties.preserveAlpha = OFF;
63 properties.stabilizerLevel = settings.value(
"stabilizerLevel", StabilizationLevel::NONE).toInt();
64 properties.useAA = settings.value(
"eraserAA", 1).toInt();
66 if (properties.useFeather) { properties.useAA = -1; }
72void EraserTool::resetToDefault()
79 setStabilizerLevel(StabilizationLevel::NONE);
82void EraserTool::setWidth(
const qreal width)
85 properties.width = width;
89 settings.setValue(
"eraserWidth", width);
93void EraserTool::setUseFeather(
const bool usingFeather)
96 properties.useFeather = usingFeather;
100 settings.setValue(
"eraserUseFeather", usingFeather);
104void EraserTool::setFeather(
const qreal feather)
107 properties.feather = feather;
111 settings.setValue(
"eraserFeather", feather);
115void EraserTool::setPressure(
const bool pressure)
118 properties.pressure = pressure;
122 settings.setValue(
"eraserPressure", pressure);
126void EraserTool::setAA(
const int AA)
129 properties.useAA = AA;
133 settings.setValue(
"eraserAA", AA);
137void EraserTool::setStabilizerLevel(
const int level)
139 properties.stabilizerLevel = level;
142 settings.setValue(
"stabilizerLevel", level);
154 mInterpolator.pointerPressEvent(
event);
155 if (handleQuickSizing(
event)) {
159 startStroke(
event->inputType());
160 mLastBrushPoint = getCurrentPoint();
161 mMouseDownPoint = getCurrentPoint();
163 StrokeTool::pointerPressEvent(
event);
168 mInterpolator.pointerMoveEvent(
event);
169 if (handleQuickSizing(
event)) {
175 mCurrentPressure = mInterpolator.getPressure();
177 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
179 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
183 StrokeTool::pointerMoveEvent(
event);
186void EraserTool::pointerReleaseEvent(
PointerEvent *event)
188 mInterpolator.pointerReleaseEvent(
event);
189 if (handleQuickSizing(
event)) {
193 if (
event->inputType() != mCurrentInputType)
return;
195 mEditor->backup(typeName());
197 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
200 paintAt(mMouseDownPoint);
210 StrokeTool::pointerReleaseEvent(
event);
214void EraserTool::paintAt(
QPointF point)
216 Layer* layer = mEditor->layers()->currentLayer();
217 if (layer->type() == Layer::BITMAP)
219 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
220 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
221 qreal brushWidth = properties.width * pressure;
222 mCurrentWidth = brushWidth;
224 mScribbleArea->drawBrush(point,
227 QColor(255, 255, 255, 255),
230 properties.useFeather,
231 properties.useAA == ON);
235void EraserTool::drawStroke()
237 StrokeTool::drawStroke();
240 Layer* layer = mEditor->layers()->currentLayer();
242 if (layer->type() == Layer::BITMAP)
244 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
245 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
246 qreal brushWidth = properties.width * pressure;
247 mCurrentWidth = brushWidth;
249 qreal brushStep = (0.5 * brushWidth);
250 brushStep = qMax(1.0, brushStep);
258 int steps = qRound(distance / brushStep);
260 for (
int i = 0; i < steps; i++)
262 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
264 mScribbleArea->drawBrush(point,
270 properties.useFeather,
271 properties.useAA == ON);
272 if (i == (steps - 1))
274 mLastBrushPoint = getCurrentPoint();
278 else if (layer->type() == Layer::VECTOR)
280 mCurrentWidth = properties.width;
281 if (properties.pressure)
283 mCurrentWidth = (mCurrentWidth + (mInterpolator.getPressure() * mCurrentWidth)) * 0.5;
285 qreal brushWidth = mCurrentWidth;
300void EraserTool::removeVectorPaint()
302 Layer* layer = mEditor->layers()->currentLayer();
303 if (layer->type() == Layer::VECTOR)
305 mScribbleArea->clearDrawingBuffer();
306 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
307 if (vectorImage ==
nullptr) {
return; }
313 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
317void EraserTool::updateStrokes()
319 Layer* layer = mEditor->layers()->currentLayer();
320 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
325 if (layer->type() == Layer::VECTOR)
327 qreal radius = properties.width / 2;
329 VectorImage* currKey =
static_cast<VectorImage*
>(layer->getLastKeyFrameAtPosition(mEditor->currentFrame()));
331 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)
CompositionMode_SourceOver