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()
const
43void EraserTool::loadSettings()
47 QSettings pencilSettings(PENCIL2D, PENCIL2D);
51 mPropertyUsed[StrokeToolProperties::WIDTH_VALUE] = { Layer::BITMAP, Layer::VECTOR };
52 mPropertyUsed[StrokeToolProperties::FEATHER_VALUE] = { Layer::BITMAP };
53 mPropertyUsed[StrokeToolProperties::FEATHER_ENABLED] = { Layer::BITMAP };
54 mPropertyUsed[StrokeToolProperties::PRESSURE_ENABLED] = { Layer::BITMAP, Layer::VECTOR };
55 mPropertyUsed[StrokeToolProperties::STABILIZATION_VALUE] = { Layer::BITMAP, Layer::VECTOR };
56 mPropertyUsed[StrokeToolProperties::ANTI_ALIASING_ENABLED] = { Layer::BITMAP };
58 info[StrokeToolProperties::WIDTH_VALUE] = { WIDTH_MIN, WIDTH_MAX, 24.0 };
59 info[StrokeToolProperties::FEATHER_VALUE] = { FEATHER_MIN, FEATHER_MAX, 48.0 };
60 info[StrokeToolProperties::FEATHER_ENABLED] =
true;
61 info[StrokeToolProperties::PRESSURE_ENABLED] =
true;
62 info[StrokeToolProperties::STABILIZATION_VALUE] = { StabilizationLevel::NONE, StabilizationLevel::STRONG, StabilizationLevel::NONE };
63 info[StrokeToolProperties::ANTI_ALIASING_ENABLED] =
true;
65 toolProperties().insertProperties(info);
66 toolProperties().loadFrom(typeName(), pencilSettings);
68 if (toolProperties().requireMigration(pencilSettings, ToolProperties::VERSION_1)) {
69 toolProperties().setBaseValue(StrokeToolProperties::WIDTH_VALUE, pencilSettings.
value(
"eraserWidth", 24.0).
toReal());
70 toolProperties().setBaseValue(StrokeToolProperties::FEATHER_VALUE, pencilSettings.
value(
"eraserFeather", 48.0).
toReal());
71 toolProperties().setBaseValue(StrokeToolProperties::STABILIZATION_VALUE, pencilSettings.
value(
"stabilizerLevel", StabilizationLevel::NONE).
toInt());
72 toolProperties().setBaseValue(StrokeToolProperties::FEATHER_ENABLED, pencilSettings.
value(
"eraserUseFeather",
true).
toBool());
73 toolProperties().setBaseValue(StrokeToolProperties::PRESSURE_ENABLED, pencilSettings.
value(
"eraserPressure",
true).
toBool());
74 toolProperties().setBaseValue(StrokeToolProperties::ANTI_ALIASING_ENABLED, pencilSettings.
value(
"eraserAA",
true).
toBool());
76 pencilSettings.
remove(
"eraserWidth");
77 pencilSettings.
remove(
"eraserFeather");
78 pencilSettings.
remove(
"stabilizerLevel");
79 pencilSettings.
remove(
"eraserUseFeather");
80 pencilSettings.
remove(
"eraserPressure");
81 pencilSettings.
remove(
"eraserAA");
95 mInterpolator.pointerPressEvent(
event);
96 if (handleQuickSizing(
event)) {
100 startStroke(
event->inputType());
101 mLastBrushPoint = getCurrentPoint();
102 mMouseDownPoint = getCurrentPoint();
104 StrokeTool::pointerPressEvent(
event);
109 mInterpolator.pointerMoveEvent(
event);
110 if (handleQuickSizing(
event)) {
116 mCurrentPressure = mInterpolator.getPressure();
118 if (mSettings.stabilizerLevel() != mInterpolator.getStabilizerLevel())
120 mInterpolator.setStabilizerLevel(mSettings.stabilizerLevel());
124 StrokeTool::pointerMoveEvent(
event);
127void EraserTool::pointerReleaseEvent(
PointerEvent *event)
129 mInterpolator.pointerReleaseEvent(
event);
130 if (handleQuickSizing(
event)) {
134 if (
event->inputType() != mCurrentInputType)
return;
136 mEditor->backup(typeName());
138 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
141 paintAt(mMouseDownPoint);
151 StrokeTool::pointerReleaseEvent(
event);
155void EraserTool::paintAt(
QPointF point)
157 Layer* layer = mEditor->layers()->currentLayer();
158 if (layer->type() == Layer::BITMAP)
160 qreal pressure = (mSettings.pressureEnabled()) ? mCurrentPressure : 1.0;
161 qreal opacity = (mSettings.pressureEnabled()) ? (mCurrentPressure * 0.5) : 1.0;
162 qreal brushWidth = mSettings.width() * pressure;
163 mCurrentWidth = brushWidth;
165 mScribbleArea->drawBrush(point,
168 QColor(255, 255, 255, 255),
171 mSettings.featherEnabled(),
172 mSettings.AntiAliasingEnabled() == ON);
176void EraserTool::drawStroke()
178 StrokeTool::drawStroke();
181 Layer* layer = mEditor->layers()->currentLayer();
183 if (layer->type() == Layer::BITMAP)
185 qreal pressure = (mSettings.pressureEnabled()) ? mCurrentPressure : 1.0;
186 qreal opacity = (mSettings.pressureEnabled()) ? (mCurrentPressure * 0.5) : 1.0;
187 qreal brushWidth = mSettings.width() * pressure;
188 mCurrentWidth = brushWidth;
190 qreal brushStep = (0.5 * brushWidth);
191 brushStep = qMax(1.0, brushStep);
199 int steps = qRound(distance / brushStep);
201 for (
int i = 0; i < steps; i++)
203 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
205 mScribbleArea->drawBrush(point,
211 mSettings.featherEnabled(),
212 mSettings.AntiAliasingEnabled() == ON);
213 if (i == (steps - 1))
215 mLastBrushPoint = getCurrentPoint();
219 else if (layer->type() == Layer::VECTOR)
221 mCurrentWidth = mSettings.width();
222 if (mSettings.pressureEnabled())
224 mCurrentWidth = (mCurrentWidth + (mInterpolator.getPressure() * mCurrentWidth)) * 0.5;
226 qreal brushWidth = mCurrentWidth;
241void EraserTool::removeVectorPaint()
243 Layer* layer = mEditor->layers()->currentLayer();
244 if (layer->type() == Layer::VECTOR)
246 mScribbleArea->clearDrawingBuffer();
247 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
248 if (vectorImage ==
nullptr) {
return; }
254 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
258void EraserTool::updateStrokes()
260 Layer* layer = mEditor->layers()->currentLayer();
261 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
266 if (layer->type() == Layer::VECTOR)
268 qreal radius = mSettings.width() / 2;
270 VectorImage* currKey =
static_cast<VectorImage*
>(layer->getLastKeyFrameAtPosition(mEditor->currentFrame()));
272 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
void remove(const QString &key)
QVariant value(const QString &key, const QVariant &defaultValue) const const
bool toBool() const const
int toInt(bool *ok) const const
qreal toReal(bool *ok) const const