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"
28#include "undoredomanager.h"
31#include "scribblearea.h"
32#include "layervector.h"
33#include "vectorimage.h"
40void PencilTool::loadSettings()
44 mPropertyEnabled[WIDTH] =
true;
45 mPropertyEnabled[PRESSURE] =
true;
46 mPropertyEnabled[VECTORMERGE] =
false;
47 mPropertyEnabled[STABILIZATION] =
true;
48 mPropertyEnabled[FILLCONTOUR] =
true;
51 properties.width = settings.value(
"pencilWidth", 4).toDouble();
52 properties.feather = 50;
53 properties.pressure = settings.value(
"pencilPressure",
true).toBool();
54 properties.stabilizerLevel = settings.value(
"pencilLineStabilization", StabilizationLevel::STRONG).toInt();
55 properties.useAA = DISABLED;
56 properties.useFillContour =
false;
61void PencilTool::resetToDefault()
66 setStabilizerLevel(StabilizationLevel::STRONG);
69void PencilTool::setWidth(
const qreal width)
72 properties.width = width;
76 settings.setValue(
"pencilWidth", width);
80void PencilTool::setFeather(
const qreal feather)
82 properties.feather = feather;
85void PencilTool::setUseFeather(
const bool usingFeather)
88 properties.useFeather = usingFeather;
92 settings.setValue(
"brushUseFeather", usingFeather);
96void PencilTool::setInvisibility(
const bool)
99 properties.invisibility = 1;
102void PencilTool::setPressure(
const bool pressure)
105 properties.pressure = pressure;
109 settings.setValue(
"pencilPressure", pressure);
113void PencilTool::setPreserveAlpha(
const bool preserveAlpha)
116 Q_UNUSED( preserveAlpha )
117 properties.preserveAlpha = 0;
120void PencilTool::setStabilizerLevel(
const int level)
122 properties.stabilizerLevel = level;
125 settings.setValue(
"pencilLineStabilization", level);
129void PencilTool::setUseFillContour(
const bool useFillContour)
131 properties.useFillContour = useFillContour;
134 settings.setValue(
"FillContour", useFillContour);
140 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
142 return QCursor(
QPixmap(
":icons/general/cursor-pencil.svg"), 4, 14);
149 mInterpolator.pointerPressEvent(
event);
150 if (handleQuickSizing(
event)) {
154 mMouseDownPoint = getCurrentPoint();
155 mLastBrushPoint = getCurrentPoint();
157 startStroke(
event->inputType());
160 if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR && !mEditor->preference()->isOn(SETTING::INVISIBLE_LINES))
162 mScribbleArea->toggleThinLines();
165 StrokeTool::pointerPressEvent(
event);
170 mInterpolator.pointerMoveEvent(
event);
171 if (handleQuickSizing(
event)) {
177 mCurrentPressure = mInterpolator.getPressure();
179 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
181 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
184 StrokeTool::pointerMoveEvent(
event);
187void PencilTool::pointerReleaseEvent(
PointerEvent *event)
189 mInterpolator.pointerReleaseEvent(
event);
190 if (handleQuickSizing(
event)) {
194 if (
event->inputType() != mCurrentInputType)
return;
196 mEditor->backup(typeName());
197 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
200 paintAt(mMouseDownPoint);
207 Layer* layer = mEditor->layers()->currentLayer();
208 if (layer->type() == Layer::VECTOR) {
209 paintVectorStroke(layer);
213 StrokeTool::pointerReleaseEvent(
event);
217void PencilTool::paintAt(
QPointF point)
220 Layer* layer = mEditor->layers()->currentLayer();
221 if (layer->type() == Layer::BITMAP)
223 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
224 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
225 qreal brushWidth = properties.width * pressure;
226 qreal fixedBrushFeather = properties.feather;
228 mCurrentWidth = brushWidth;
229 mScribbleArea->drawPencil(point,
238void PencilTool::drawStroke()
240 StrokeTool::drawStroke();
243 Layer* layer = mEditor->layers()->currentLayer();
245 if (layer->type() == Layer::BITMAP)
247 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
248 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
249 qreal brushWidth = properties.width * pressure;
250 mCurrentWidth = brushWidth;
252 qreal fixedBrushFeather = properties.feather;
253 qreal brushStep = qMax(1.0, (0.5 * brushWidth));
259 int steps = qRound(distance / brushStep);
261 for (
int i = 0; i < steps; i++)
263 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
264 mScribbleArea->drawPencil(point,
270 if (i == (steps - 1))
272 mLastBrushPoint = getCurrentPoint();
276 else if (layer->type() == Layer::VECTOR)
296void PencilTool::paintVectorStroke(
Layer* layer)
298 if (mStrokePoints.
empty())
302 mScribbleArea->clearDrawingBuffer();
303 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
305 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
308 curve.setFilled(
false);
309 curve.setInvisibility(
true);
310 curve.setVariableWidth(
false);
311 curve.setColorNumber(mEditor->color()->frontColorNumber());
312 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
313 if (vectorImage ==
nullptr) {
return; }
314 vectorImage->
addCurve(curve, qAbs(mEditor->view()->scaling()), properties.vectorMergeEnabled);
316 if (properties.useFillContour)
319 mEditor->color()->frontColorNumber());
324 mEditor->deselectAll();
332 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
QColor frontColor(bool useIndexedColor=true)
frontColor
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
virtual bool event(QEvent *e)