22#include "vectorimage.h"
23#include "layervector.h"
24#include "colormanager.h"
25#include "layermanager.h"
26#include "viewmanager.h"
27#include "undoredomanager.h"
28#include "selectionmanager.h"
30#include "scribblearea.h"
32#include "pointerevent.h"
39void PenTool::loadSettings()
43 mPropertyEnabled[WIDTH] =
true;
44 mPropertyEnabled[PRESSURE] =
true;
45 mPropertyEnabled[VECTORMERGE] =
true;
46 mPropertyEnabled[ANTI_ALIASING] =
true;
47 mPropertyEnabled[STABILIZATION] =
true;
51 properties.width = settings.value(
"penWidth", 12.0).toDouble();
52 properties.pressure = settings.value(
"penPressure",
true).toBool();
53 properties.invisibility = OFF;
54 properties.preserveAlpha = OFF;
55 properties.useAA = settings.value(
"penAA",
true).toBool();
56 properties.stabilizerLevel = settings.value(
"penLineStabilization", StabilizationLevel::STRONG).toInt();
61void PenTool::resetToDefault()
66 setStabilizerLevel(StabilizationLevel::STRONG);
70void PenTool::setWidth(
const qreal width)
73 properties.width = width;
77 settings.setValue(
"penWidth", width);
81void PenTool::setPressure(
const bool pressure)
84 properties.pressure = pressure;
88 settings.setValue(
"penPressure", pressure);
92void PenTool::setAA(
const int AA)
95 properties.useAA = AA;
99 settings.setValue(
"penAA", AA);
103void PenTool::setStabilizerLevel(
const int level)
105 properties.stabilizerLevel = level;
108 settings.setValue(
"penLineStabilization", level);
114 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
123 mInterpolator.pointerPressEvent(
event);
124 if (handleQuickSizing(
event)) {
128 mMouseDownPoint = getCurrentPoint();
129 mLastBrushPoint = getCurrentPoint();
131 startStroke(
event->inputType());
133 StrokeTool::pointerPressEvent(
event);
138 mInterpolator.pointerMoveEvent(
event);
139 if (handleQuickSizing(
event)) {
145 mCurrentPressure = mInterpolator.getPressure();
147 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
149 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
153 StrokeTool::pointerMoveEvent(
event);
158 mInterpolator.pointerReleaseEvent(
event);
159 if (handleQuickSizing(
event)) {
163 if (
event->inputType() != mCurrentInputType)
return;
165 mEditor->backup(typeName());
167 Layer* layer = mEditor->layers()->currentLayer();
169 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
172 paintAt(mMouseDownPoint);
179 if (layer->type() == Layer::VECTOR) {
180 paintVectorStroke(layer);
184 StrokeTool::pointerReleaseEvent(
event);
188void PenTool::paintAt(
QPointF point)
190 Layer* layer = mEditor->layers()->currentLayer();
191 if (layer->type() == Layer::BITMAP)
193 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
194 qreal brushWidth = properties.width * pressure;
195 mCurrentWidth = brushWidth;
197 mScribbleArea->drawPen(point,
204void PenTool::drawStroke()
206 StrokeTool::drawStroke();
209 Layer* layer = mEditor->layers()->currentLayer();
211 if (layer->type() == Layer::BITMAP)
213 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
214 qreal brushWidth = properties.width * pressure;
215 mCurrentWidth = brushWidth;
219 qreal brushStep = (0.5 * brushWidth);
220 brushStep = qMax(1.0, brushStep);
226 int steps = qRound(distance / brushStep);
228 for (
int i = 0; i < steps; i++)
230 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
231 mScribbleArea->drawPen(point,
236 if (i == (steps - 1))
238 mLastBrushPoint = getCurrentPoint();
242 else if (layer->type() == Layer::VECTOR)
244 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
245 qreal brushWidth = properties.width * pressure;
256 path.cubicTo(p[1], p[2], p[3]);
262void PenTool::paintVectorStroke(
Layer* layer)
264 if (mStrokePoints.
empty())
268 mScribbleArea->clearDrawingBuffer();
269 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
271 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
272 curve.setWidth(properties.width);
273 curve.setFeather(properties.feather);
274 curve.setFilled(
false);
275 curve.setInvisibility(properties.invisibility);
276 curve.setVariableWidth(properties.pressure);
277 curve.setColorNumber(mEditor->color()->frontColorNumber());
279 auto pLayerVector =
static_cast<LayerVector*
>(layer);
280 VectorImage* vectorImage = pLayerVector->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
281 if (vectorImage ==
nullptr) {
return; }
282 vectorImage->
addCurve(curve, mEditor->view()->scaling(),
false);
286 mEditor->deselectAll();
291 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.
bool isAnyCurveSelected()
VectorImage::isAnyCurveSelected.
QHash::iterator insert(const Key &key, const T &value)
qreal length() const const
virtual bool event(QEvent *e)