17#include "penciltool.h"
21#include "pointerevent.h"
23#include "layermanager.h"
24#include "colormanager.h"
25#include "viewmanager.h"
26#include "preferencemanager.h"
27#include "selectionmanager.h"
30#include "scribblearea.h"
31#include "layervector.h"
32#include "vectorimage.h"
39void PencilTool::loadSettings()
43 mPropertyEnabled[WIDTH] =
true;
44 mPropertyEnabled[PRESSURE] =
true;
45 mPropertyEnabled[VECTORMERGE] =
false;
46 mPropertyEnabled[STABILIZATION] =
true;
47 mPropertyEnabled[FILLCONTOUR] =
true;
50 properties.width = settings.value(
"pencilWidth", 4).toDouble();
51 properties.feather = 50;
52 properties.pressure = settings.value(
"pencilPressure",
true).toBool();
53 properties.stabilizerLevel = settings.value(
"pencilLineStabilization", StabilizationLevel::STRONG).toInt();
54 properties.useAA = DISABLED;
55 properties.useFillContour =
false;
60void PencilTool::resetToDefault()
65 setStabilizerLevel(StabilizationLevel::STRONG);
68void PencilTool::setWidth(
const qreal width)
71 properties.width = width;
75 settings.setValue(
"pencilWidth", width);
79void PencilTool::setFeather(
const qreal feather)
81 properties.feather = feather;
84void PencilTool::setUseFeather(
const bool usingFeather)
87 properties.useFeather = usingFeather;
91 settings.setValue(
"brushUseFeather", usingFeather);
95void PencilTool::setInvisibility(
const bool)
98 properties.invisibility = 1;
101void PencilTool::setPressure(
const bool pressure)
104 properties.pressure = pressure;
108 settings.setValue(
"pencilPressure", pressure);
112void PencilTool::setPreserveAlpha(
const bool preserveAlpha)
115 Q_UNUSED( preserveAlpha )
116 properties.preserveAlpha = 0;
119void PencilTool::setStabilizerLevel(
const int level)
121 properties.stabilizerLevel = level;
124 settings.setValue(
"pencilLineStabilization", level);
128void PencilTool::setUseFillContour(
const bool useFillContour)
130 properties.useFillContour = useFillContour;
133 settings.setValue(
"FillContour", useFillContour);
139 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
141 return QCursor(
QPixmap(
":icons/general/cursor-pencil.svg"), 4, 14);
148 mInterpolator.pointerPressEvent(event);
149 if (handleQuickSizing(event)) {
153 mMouseDownPoint = getCurrentPoint();
154 mLastBrushPoint = getCurrentPoint();
156 startStroke(event->inputType());
159 if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR && !mEditor->preference()->isOn(SETTING::INVISIBLE_LINES))
161 mScribbleArea->toggleThinLines();
164 StrokeTool::pointerPressEvent(event);
169 mInterpolator.pointerMoveEvent(event);
170 if (handleQuickSizing(event)) {
176 mCurrentPressure = mInterpolator.getPressure();
178 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
180 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
183 StrokeTool::pointerMoveEvent(event);
186void PencilTool::pointerReleaseEvent(
PointerEvent *event)
188 mInterpolator.pointerReleaseEvent(event);
189 if (handleQuickSizing(event)) {
193 if (event->inputType() != mCurrentInputType)
return;
195 mEditor->backup(typeName());
196 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
199 paintAt(mMouseDownPoint);
206 Layer* layer = mEditor->layers()->currentLayer();
207 if (layer->type() == Layer::VECTOR) {
208 paintVectorStroke(layer);
212 StrokeTool::pointerReleaseEvent(event);
216void PencilTool::paintAt(
QPointF point)
219 Layer* layer = mEditor->layers()->currentLayer();
220 if (layer->type() == Layer::BITMAP)
222 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
223 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
224 qreal brushWidth = properties.width * pressure;
225 qreal fixedBrushFeather = properties.feather;
227 mCurrentWidth = brushWidth;
228 mScribbleArea->drawPencil(point,
237void PencilTool::drawStroke()
239 StrokeTool::drawStroke();
242 Layer* layer = mEditor->layers()->currentLayer();
244 if (layer->type() == Layer::BITMAP)
246 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
247 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
248 qreal brushWidth = properties.width * pressure;
249 mCurrentWidth = brushWidth;
251 qreal fixedBrushFeather = properties.feather;
252 qreal brushStep = qMax(1.0, (0.5 * brushWidth));
258 int steps = qRound(distance / brushStep);
260 for (
int i = 0; i < steps; i++)
262 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
263 mScribbleArea->drawPencil(point,
269 if (i == (steps - 1))
271 mLastBrushPoint = getCurrentPoint();
275 else if (layer->type() == Layer::VECTOR)
295void PencilTool::paintVectorStroke(
Layer* layer)
297 if (mStrokePoints.
empty())
301 mScribbleArea->clearDrawingBuffer();
302 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
304 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
307 curve.setFilled(
false);
308 curve.setInvisibility(
true);
309 curve.setVariableWidth(
false);
310 curve.setColorNumber(mEditor->color()->frontColorNumber());
311 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
312 if (vectorImage ==
nullptr) {
return; }
313 vectorImage->
addCurve(curve, qAbs(mEditor->view()->scaling()), properties.vectorMergeEnabled);
315 if (properties.useFillContour)
318 mEditor->color()->frontColorNumber());
323 mEditor->deselectAll();
331 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
QColor frontColor(bool useIndexedColor=true)
frontColor
Qt::MouseButtons buttons() const
Returns Qt::MouseButtons()
void setSelected(int curveNumber, bool YesOrNo)
VectorImage::setSelected.
int getLastCurveNumber()
VectorImage::getLastCurveNumber.
void addCurve(BezierCurve &newCurve, qreal factor, bool interacts=true)
VectorImage::addCurve.
void fillContour(QList< QPointF > contourPath, int color)
VectorImage::fillContour.
bool isAnyCurveSelected()
VectorImage::isAnyCurveSelected.
QHash::iterator insert(const Key &key, const T &value)
qreal length() const const