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::saveSettings()
65 settings.setValue(
"pencilWidth", properties.width);
66 settings.setValue(
"pencilPressure", properties.pressure);
67 settings.setValue(
"brushUseFeather", properties.useFeather);
68 settings.setValue(
"pencilLineStabilization", properties.stabilizerLevel);
69 settings.setValue(
"FillContour", properties.useFillContour);
74void PencilTool::resetToDefault()
79 setStabilizerLevel(StabilizationLevel::STRONG);
82void PencilTool::setWidth(
const qreal width)
85 properties.width = width;
88void PencilTool::setFeather(
const qreal feather)
90 properties.feather = feather;
93void PencilTool::setUseFeather(
const bool usingFeather)
96 properties.useFeather = usingFeather;
100void PencilTool::setInvisibility(
const bool)
103 properties.invisibility = 1;
106void PencilTool::setPressure(
const bool pressure)
109 properties.pressure = 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;
124void PencilTool::setUseFillContour(
const bool useFillContour)
126 properties.useFillContour = useFillContour;
131 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
133 return QCursor(
QPixmap(
":icons/general/cursor-pencil.svg"), 4, 14);
140 mInterpolator.pointerPressEvent(
event);
141 if (handleQuickSizing(
event)) {
145 mMouseDownPoint = getCurrentPoint();
146 mLastBrushPoint = getCurrentPoint();
148 startStroke(
event->inputType());
151 if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR && !mEditor->preference()->isOn(SETTING::INVISIBLE_LINES))
153 mScribbleArea->toggleThinLines();
156 StrokeTool::pointerPressEvent(
event);
161 mInterpolator.pointerMoveEvent(
event);
162 if (handleQuickSizing(
event)) {
168 mCurrentPressure = mInterpolator.getPressure();
170 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
172 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
175 StrokeTool::pointerMoveEvent(
event);
178void PencilTool::pointerReleaseEvent(
PointerEvent *event)
180 mInterpolator.pointerReleaseEvent(
event);
181 if (handleQuickSizing(
event)) {
185 if (
event->inputType() != mCurrentInputType)
return;
187 mEditor->backup(typeName());
188 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
191 paintAt(mMouseDownPoint);
198 Layer* layer = mEditor->layers()->currentLayer();
199 if (layer->type() == Layer::VECTOR) {
200 paintVectorStroke(layer);
204 StrokeTool::pointerReleaseEvent(
event);
208void PencilTool::paintAt(
QPointF point)
211 Layer* layer = mEditor->layers()->currentLayer();
212 if (layer->type() == Layer::BITMAP)
214 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
215 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
216 qreal brushWidth = properties.width * pressure;
217 qreal fixedBrushFeather = properties.feather;
219 mCurrentWidth = brushWidth;
220 mScribbleArea->drawPencil(point,
229void PencilTool::drawStroke()
231 StrokeTool::drawStroke();
234 Layer* layer = mEditor->layers()->currentLayer();
236 if (layer->type() == Layer::BITMAP)
238 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
239 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
240 qreal brushWidth = properties.width * pressure;
241 mCurrentWidth = brushWidth;
243 qreal fixedBrushFeather = properties.feather;
244 qreal brushStep = qMax(1.0, (0.5 * brushWidth));
250 int steps = qRound(distance / brushStep);
252 for (
int i = 0; i < steps; i++)
254 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
255 mScribbleArea->drawPencil(point,
261 if (i == (steps - 1))
263 mLastBrushPoint = getCurrentPoint();
267 else if (layer->type() == Layer::VECTOR)
287void PencilTool::paintVectorStroke(
Layer* layer)
289 if (mStrokePoints.
empty())
293 mScribbleArea->clearDrawingBuffer();
294 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
296 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
299 curve.setFilled(
false);
300 curve.setInvisibility(
true);
301 curve.setVariableWidth(
false);
302 curve.setColorNumber(mEditor->color()->frontColorNumber());
303 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
304 if (vectorImage ==
nullptr) {
return; }
305 vectorImage->
addCurve(curve, qAbs(mEditor->view()->scaling()), properties.vectorMergeEnabled);
307 if (properties.useFillContour)
310 mEditor->color()->frontColorNumber());
315 mEditor->deselectAll();
323 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)