17 #include "smudgetool.h"
21 #include "pointerevent.h"
22 #include "vectorimage.h"
24 #include "scribblearea.h"
26 #include "layermanager.h"
27 #include "strokemanager.h"
28 #include "viewmanager.h"
29 #include "selectionmanager.h"
31 #include "layerbitmap.h"
32 #include "layervector.h"
40 ToolType SmudgeTool::type()
45 void SmudgeTool::loadSettings()
47 mPropertyEnabled[WIDTH] =
true;
48 mPropertyEnabled[FEATHER] =
true;
51 properties.width = settings.value(
"smudgeWidth", 24.0).toDouble();
52 properties.feather = settings.value(
"smudgeFeather", 48.0).toDouble();
53 properties.pressure =
false;
54 properties.stabilizerLevel = -1;
60 void SmudgeTool::resetToDefault()
66 void SmudgeTool::setWidth(
const qreal width)
69 properties.width = width;
73 settings.setValue(
"smudgeWidth", width);
77 void SmudgeTool::setFeather(
const qreal feather)
80 properties.feather = feather;
84 settings.setValue(
"smudgeFeather", feather);
88 void SmudgeTool::setPressure(
const bool pressure)
91 properties.pressure = pressure;
95 settings.setValue(
"smudgePressure", pressure);
107 qDebug() <<
"smudge tool";
116 bool SmudgeTool::keyPressEvent(
QKeyEvent *event)
127 bool SmudgeTool::keyReleaseEvent(
QKeyEvent*)
140 Layer* layer = mEditor->layers()->currentLayer();
141 auto selectMan = mEditor->select();
142 if (layer == NULL) {
return; }
146 if (layer->type() == Layer::BITMAP)
148 mScribbleArea->setAllDirty();
149 startStroke(event->inputType());
150 mLastBrushPoint = getCurrentPoint();
152 else if (layer->type() == Layer::VECTOR)
154 const int currentFrame = mEditor->currentFrame();
155 const float distanceFrom = selectMan->selectionTolerance();
157 if (vectorImage ==
nullptr) {
return; }
158 selectMan->setCurves(vectorImage->
getCurvesCloseTo(getCurrentPoint(), distanceFrom));
159 selectMan->setVertices(vectorImage->
getVerticesCloseTo(getCurrentPoint(), distanceFrom));
161 if (selectMan->closestCurves().size() > 0 || selectMan->closestCurves().size() > 0)
173 mScribbleArea->paintTransformedSelection();
174 mEditor->deselectAll();
177 vectorImage->
setSelected(selectMan->closestVertices(),
true);
178 selectMan->vectorSelection.add(selectMan->closestCurves());
179 selectMan->vectorSelection.add(selectMan->closestVertices());
185 mEditor->deselectAll();
193 if (event->inputType() != mCurrentInputType)
return;
195 Layer* layer = mEditor->layers()->currentLayer();
196 if (layer == NULL) {
return; }
198 if (layer->type() != Layer::BITMAP && layer->type() != Layer::VECTOR)
203 auto selectMan = mEditor->select();
206 if (layer->type() == Layer::BITMAP)
214 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
215 if (vectorImage ==
nullptr) {
return; }
218 selectMan->setSelectionTransform(
QTransform().translate(offsetFromPressPos().x(), offsetFromPressPos().y()));
225 if (layer->type() == Layer::VECTOR)
227 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
228 if (vectorImage ==
nullptr) {
return; }
230 selectMan->setVertices(vectorImage->
getVerticesCloseTo(getCurrentPoint(), selectMan->selectionTolerance()));
234 mScribbleArea->setAllDirty();
237 void SmudgeTool::pointerReleaseEvent(
PointerEvent* event)
239 if (event->inputType() != mCurrentInputType)
return;
241 Layer* layer = mEditor->layers()->currentLayer();
242 if (layer == NULL) {
return; }
246 mEditor->backup(typeName());
248 if (layer->type() == Layer::BITMAP)
251 mScribbleArea->paintBitmapBuffer();
252 mScribbleArea->setAllDirty();
253 mScribbleArea->clearBitmapBuffer();
256 else if (layer->type() == Layer::VECTOR)
259 if (vectorImage ==
nullptr) {
return; }
262 auto selectMan = mEditor->select();
263 selectMan->resetSelectionTransform();
264 for (
int k = 0; k < selectMan->vectorSelection.curve.size(); k++)
266 int curveNumber = selectMan->vectorSelection.curve.at(k);
267 vectorImage->curve(curveNumber).smoothCurve();
269 mScribbleArea->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
274 void SmudgeTool::drawStroke()
276 if (!mScribbleArea->isLayerPaintable())
return;
278 Layer* layer = mEditor->layers()->currentLayer();
279 if (layer ==
nullptr) {
return; }
281 BitmapImage *sourceImage =
static_cast<LayerBitmap*
>(layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0);
282 if (sourceImage ==
nullptr) {
return; }
284 StrokeTool::drawStroke();
287 for (
int i = 0; i < p.
size(); i++)
289 p[i] = mEditor->view()->mapScreenToCanvas(p[i]);
293 mCurrentWidth = properties.width;
294 qreal brushWidth = mCurrentWidth + 0.0 * properties.feather;
295 qreal offset = qMax(0.0, mCurrentWidth - 0.5 * properties.feather) / brushWidth;
308 int steps = qRound(distance / brushStep);
309 int rad = qRound(brushWidth / 2.0) + 2;
311 QPointF sourcePoint = mLastBrushPoint;
312 for (
int i = 0; i < steps; i++)
314 targetImage.paste(mScribbleArea->mBufferImg);
315 QPointF targetPoint = mLastBrushPoint + (i + 1) * (brushStep) * (b - mLastBrushPoint) / distance;
316 rect.extend(targetPoint.
toPoint());
317 mScribbleArea->liquifyBrush(&targetImage,
324 if (i == (steps - 1))
326 mLastBrushPoint = targetPoint;
328 sourcePoint = targetPoint;
329 mScribbleArea->paintBitmapBufferRect(rect);
330 mScribbleArea->refreshBitmap(rect, rad);
335 qreal brushStep = 2.0;
337 int steps = qRound(distance / brushStep);
338 int rad = qRound(brushWidth / 2.0) + 2;
340 QPointF sourcePoint = mLastBrushPoint;
341 for (
int i = 0; i < steps; i++)
343 targetImage.paste(mScribbleArea->mBufferImg);
344 QPointF targetPoint = mLastBrushPoint + (i + 1) * (brushStep) * (b - mLastBrushPoint) / distance;
345 rect.extend(targetPoint.
toPoint());
346 mScribbleArea->blurBrush(&targetImage,
353 if (i == (steps - 1))
355 mLastBrushPoint = targetPoint;
357 sourcePoint = targetPoint;
358 mScribbleArea->paintBitmapBufferRect(rect);
359 mScribbleArea->refreshBitmap(rect, rad);
364 QPointF SmudgeTool::offsetFromPressPos()
366 return getCurrentPoint() - getCurrentPressPoint();
Qt::KeyboardModifiers modifiers() const
Returns the modifier created by keyboard while a device was in use.
QHash::iterator insert(const Key &key, const T &value)
QList< VertexRef > getVerticesCloseTo(QPointF thisPoint, qreal maxDistance)
VectorImage::getVerticesCloseTo.
QList< int > getCurvesCloseTo(QPointF thisPoint, qreal maxDistance)
VectorImage::getCurvesCloseTo.
qreal length() const const
bool isSelected(int curveNumber)
VectorImage::isSelected.
Qt::MouseButtons buttons() const
Returns Qt::MouseButtons()
void setSelectionTransformation(QTransform transform)
VectorImage::setSelectionTransformation.
QPoint toPoint() const const
Qt::MouseButton button() const
Returns Qt::MouseButton()
void applySelectionTransformation()
VectorImage::applySelectionTransformation.
void setSelected(int curveNumber, bool YesOrNo)
VectorImage::setSelected.