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;
57 properties.useFeather =
false;
62void PencilTool::saveSettings()
66 settings.setValue(
"pencilWidth", properties.width);
67 settings.setValue(
"pencilPressure", properties.pressure);
68 settings.setValue(
"brushUseFeather", properties.useFeather);
69 settings.setValue(
"pencilLineStabilization", properties.stabilizerLevel);
70 settings.setValue(
"FillContour", properties.useFillContour);
75void PencilTool::resetToDefault()
80 setStabilizerLevel(StabilizationLevel::STRONG);
83void PencilTool::setWidth(
const qreal width)
86 properties.width = width;
89void PencilTool::setFeather(
const qreal feather)
91 properties.feather = feather;
94void PencilTool::setUseFeather(
const bool usingFeather)
97 properties.useFeather = usingFeather;
101void PencilTool::setInvisibility(
const bool)
104 properties.invisibility = 1;
107void PencilTool::setPressure(
const bool pressure)
110 properties.pressure = 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;
125void PencilTool::setUseFillContour(
const bool useFillContour)
127 properties.useFillContour = useFillContour;
132 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
134 return QCursor(
QPixmap(
":icons/general/cursor-pencil.svg"), 4, 14);
141 mInterpolator.pointerPressEvent(
event);
142 if (handleQuickSizing(
event)) {
146 mMouseDownPoint = getCurrentPoint();
147 mLastBrushPoint = getCurrentPoint();
149 startStroke(
event->inputType());
152 if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR && !mEditor->preference()->isOn(SETTING::INVISIBLE_LINES))
154 mScribbleArea->toggleThinLines();
157 StrokeTool::pointerPressEvent(
event);
162 mInterpolator.pointerMoveEvent(
event);
163 if (handleQuickSizing(
event)) {
169 mCurrentPressure = mInterpolator.getPressure();
171 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
173 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
176 StrokeTool::pointerMoveEvent(
event);
179void PencilTool::pointerReleaseEvent(
PointerEvent *event)
181 mInterpolator.pointerReleaseEvent(
event);
182 if (handleQuickSizing(
event)) {
186 if (
event->inputType() != mCurrentInputType)
return;
188 mEditor->backup(typeName());
189 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
192 paintAt(mMouseDownPoint);
199 Layer* layer = mEditor->layers()->currentLayer();
200 if (layer->type() == Layer::VECTOR) {
201 paintVectorStroke(layer);
205 StrokeTool::pointerReleaseEvent(
event);
209void PencilTool::paintAt(
QPointF point)
212 Layer* layer = mEditor->layers()->currentLayer();
213 if (layer->type() == Layer::BITMAP)
215 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
216 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
217 qreal brushWidth = properties.width * pressure;
218 qreal fixedBrushFeather = properties.feather;
220 mCurrentWidth = brushWidth;
221 mScribbleArea->drawPencil(point,
230void PencilTool::drawStroke()
232 StrokeTool::drawStroke();
235 Layer* layer = mEditor->layers()->currentLayer();
237 if (layer->type() == Layer::BITMAP)
239 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
240 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
241 qreal brushWidth = properties.width * pressure;
242 mCurrentWidth = brushWidth;
244 qreal fixedBrushFeather = properties.feather;
245 qreal brushStep = qMax(1.0, (0.5 * brushWidth));
251 int steps = qRound(distance / brushStep);
253 for (
int i = 0; i < steps; i++)
255 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
256 mScribbleArea->drawPencil(point,
262 if (i == (steps - 1))
264 mLastBrushPoint = getCurrentPoint();
268 else if (layer->type() == Layer::VECTOR)
288void PencilTool::paintVectorStroke(
Layer* layer)
290 if (mStrokePoints.
empty())
294 mScribbleArea->clearDrawingBuffer();
295 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
297 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
300 curve.setFilled(
false);
301 curve.setInvisibility(
true);
302 curve.setVariableWidth(
false);
303 curve.setColorNumber(mEditor->color()->frontColorNumber());
304 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
305 if (vectorImage ==
nullptr) {
return; }
306 vectorImage->
addCurve(curve, qAbs(mEditor->view()->scaling()), properties.vectorMergeEnabled);
308 if (properties.useFillContour)
311 mEditor->color()->frontColorNumber());
316 mEditor->deselectAll();
324 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)