17 #include "penciltool.h"
21 #include "pointerevent.h"
23 #include "layermanager.h"
24 #include "colormanager.h"
25 #include "strokemanager.h"
26 #include "viewmanager.h"
27 #include "preferencemanager.h"
28 #include "selectionmanager.h"
31 #include "scribblearea.h"
33 #include "layervector.h"
34 #include "vectorimage.h"
41 void 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.useFeather =
true;
56 properties.useFillContour =
false;
63 void PencilTool::resetToDefault()
68 setStabilizerLevel(StabilizationLevel::STRONG);
71 void PencilTool::setWidth(
const qreal width)
74 properties.width = width;
78 settings.setValue(
"pencilWidth", width);
82 void PencilTool::setFeather(
const qreal feather)
84 properties.feather = feather;
87 void PencilTool::setUseFeather(
const bool usingFeather)
90 properties.useFeather = usingFeather;
94 settings.setValue(
"brushUseFeather", usingFeather);
98 void PencilTool::setInvisibility(
const bool)
101 properties.invisibility = 1;
104 void PencilTool::setPressure(
const bool pressure)
107 properties.pressure = pressure;
111 settings.setValue(
"pencilPressure", pressure);
115 void PencilTool::setPreserveAlpha(
const bool preserveAlpha)
118 Q_UNUSED( preserveAlpha );
119 properties.preserveAlpha = 0;
122 void PencilTool::setStabilizerLevel(
const int level)
124 properties.stabilizerLevel = level;
127 settings.setValue(
"pencilLineStabilization", level);
131 void PencilTool::setUseFillContour(
const bool useFillContour)
133 properties.useFillContour = useFillContour;
136 settings.setValue(
"FillContour", useFillContour);
142 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
151 mScribbleArea->setAllDirty();
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();
169 mCurrentPressure = strokeManager()->getPressure();
171 if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel())
172 strokeManager()->setStabilizerLevel(properties.stabilizerLevel);
176 void PencilTool::pointerReleaseEvent(
PointerEvent *event)
178 if (event->inputType() != mCurrentInputType)
return;
180 mEditor->backup(typeName());
181 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
184 paintAt(mMouseDownPoint);
191 Layer* layer = mEditor->layers()->currentLayer();
192 if (layer->type() == Layer::BITMAP)
194 else if (layer->type() == Layer::VECTOR)
195 paintVectorStroke(layer);
200 void PencilTool::paintAt(
QPointF point)
203 Layer* layer = mEditor->layers()->currentLayer();
204 if (layer->type() == Layer::BITMAP)
206 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
207 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
208 qreal brushWidth = properties.width * pressure;
209 qreal fixedBrushFeather = properties.feather;
211 mCurrentWidth = brushWidth;
214 mScribbleArea->drawPencil(point,
217 mEditor->color()->frontColor(),
220 int rad = qRound(brushWidth) / 2 + 2;
221 mScribbleArea->refreshBitmap(rect, rad);
226 void PencilTool::drawStroke()
228 StrokeTool::drawStroke();
231 Layer* layer = mEditor->layers()->currentLayer();
233 if (layer->type() == Layer::BITMAP)
235 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
236 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
237 qreal brushWidth = properties.width * pressure;
238 mCurrentWidth = brushWidth;
240 qreal fixedBrushFeather = properties.feather;
241 qreal brushStep = qMax(1.0, (0.5 * brushWidth));
249 int steps = qRound(distance / brushStep);
251 for (
int i = 0; i < steps; i++)
253 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
255 mScribbleArea->drawPencil(point,
258 mEditor->color()->frontColor(),
261 if (i == (steps - 1))
263 mLastBrushPoint = getCurrentPoint();
267 int rad = qRound(brushWidth) / 2 + 2;
269 mScribbleArea->paintBitmapBufferRect(rect);
270 mScribbleArea->refreshBitmap(rect, rad);
272 else if (layer->type() == Layer::VECTOR)
274 properties.useFeather =
false;
276 QPen pen(mEditor->color()->frontColor(),
282 int rad = qRound((mCurrentWidth / 2 + 2) * mEditor->view()->scaling());
291 mScribbleArea->refreshVector(path.boundingRect().toRect(), rad);
297 void PencilTool::paintBitmapStroke()
299 mScribbleArea->paintBitmapBuffer();
300 mScribbleArea->setAllDirty();
301 mScribbleArea->clearBitmapBuffer();
304 void PencilTool::paintVectorStroke(
Layer* layer)
306 if (mStrokePoints.
empty())
310 mScribbleArea->clearBitmapBuffer();
311 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
313 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
316 curve.setFilled(
false);
317 curve.setInvisibility(
true);
318 curve.setVariableWidth(
false);
319 curve.setColorNumber(mEditor->color()->frontColorNumber());
320 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
321 if (vectorImage ==
nullptr) {
return; }
322 vectorImage->
addCurve(curve, qAbs(mEditor->view()->scaling()), properties.vectorMergeEnabled);
324 if (properties.useFillContour)
327 mEditor->color()->frontColorNumber());
332 mEditor->deselectAll();
340 mScribbleArea->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
341 mScribbleArea->setAllDirty();
QHash::iterator insert(const Key &key, const T &value)
void fillContour(QList< QPointF > contourPath, int color)
VectorImage::fillContour.
qreal length() const const
bool isAnyCurveSelected()
VectorImage::isAnyCurveSelected.
void addCurve(BezierCurve &newCurve, qreal factor, bool interacts=true)
VectorImage::addCurve.
Qt::MouseButtons buttons() const
Returns Qt::MouseButtons()
QPoint toPoint() const const
int getLastCurveNumber()
VectorImage::getLastCurveNumber.
void setSelected(int curveNumber, bool YesOrNo)
VectorImage::setSelected.