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 QSettings pencilSettings(PENCIL2D, PENCIL2D);
45 mPropertyUsed[StrokeToolProperties::WIDTH_VALUE] = { Layer::BITMAP, Layer::VECTOR };
46 mPropertyUsed[StrokeToolProperties::PRESSURE_ENABLED] = { Layer::BITMAP, Layer::VECTOR };
47 mPropertyUsed[StrokeToolProperties::ANTI_ALIASING_ENABLED] = { Layer::BITMAP };
48 mPropertyUsed[StrokeToolProperties::STABILIZATION_VALUE] = { Layer::BITMAP, Layer::VECTOR };
52 info[StrokeToolProperties::WIDTH_VALUE] = { WIDTH_MIN, WIDTH_MAX, 12.0 };
53 info[StrokeToolProperties::PRESSURE_ENABLED] =
true;
54 info[StrokeToolProperties::ANTI_ALIASING_ENABLED] =
true;
55 info[StrokeToolProperties::STABILIZATION_VALUE] = { StabilizationLevel::NONE, StabilizationLevel::STRONG, StabilizationLevel::STRONG };
57 toolProperties().insertProperties(info);
58 toolProperties().loadFrom(typeName(), pencilSettings);
60 if (toolProperties().requireMigration(pencilSettings, ToolProperties::VERSION_1)) {
61 toolProperties().setBaseValue(StrokeToolProperties::WIDTH_VALUE, pencilSettings.
value(
"penWidth", 12.0).
toReal());
62 toolProperties().setBaseValue(StrokeToolProperties::PRESSURE_ENABLED, pencilSettings.
value(
"penPressure",
true).
toBool());
63 toolProperties().setBaseValue(StrokeToolProperties::ANTI_ALIASING_ENABLED, pencilSettings.
value(
"penAA",
true).
toBool());
64 toolProperties().setBaseValue(StrokeToolProperties::STABILIZATION_VALUE, pencilSettings.
value(
"penLineStablization", StabilizationLevel::STRONG).
toInt());
66 pencilSettings.
remove(
"penWidth");
67 pencilSettings.
remove(
"penPressure");
68 pencilSettings.
remove(
"penAA");
69 pencilSettings.
remove(
"penLineStablization");
77 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
86 mInterpolator.pointerPressEvent(
event);
87 if (handleQuickSizing(
event)) {
91 mMouseDownPoint = getCurrentPoint();
92 mLastBrushPoint = getCurrentPoint();
94 startStroke(
event->inputType());
96 StrokeTool::pointerPressEvent(
event);
101 mInterpolator.pointerMoveEvent(
event);
102 if (handleQuickSizing(
event)) {
108 mCurrentPressure = mInterpolator.getPressure();
110 if (mSettings.stabilizerLevel() != mInterpolator.getStabilizerLevel())
112 mInterpolator.setStabilizerLevel(mSettings.stabilizerLevel());
116 StrokeTool::pointerMoveEvent(
event);
121 mInterpolator.pointerReleaseEvent(
event);
122 if (handleQuickSizing(
event)) {
126 if (
event->inputType() != mCurrentInputType)
return;
128 mEditor->backup(typeName());
130 Layer* layer = mEditor->layers()->currentLayer();
132 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
135 paintAt(mMouseDownPoint);
142 if (layer->type() == Layer::VECTOR) {
143 paintVectorStroke(layer);
147 StrokeTool::pointerReleaseEvent(
event);
151void PenTool::paintAt(
QPointF point)
153 Layer* layer = mEditor->layers()->currentLayer();
154 if (layer->type() == Layer::BITMAP)
156 qreal pressure = (mSettings.pressureEnabled()) ? mCurrentPressure : 1.0;
157 qreal brushWidth = mSettings.width() * pressure;
158 mCurrentWidth = brushWidth;
160 mScribbleArea->drawPen(point,
163 mSettings.AntiAliasingEnabled());
167void PenTool::drawStroke()
169 StrokeTool::drawStroke();
172 Layer* layer = mEditor->layers()->currentLayer();
174 if (layer->type() == Layer::BITMAP)
176 qreal pressure = (mSettings.pressureEnabled()) ? mCurrentPressure : 1.0;
177 qreal brushWidth = mSettings.width() * pressure;
178 mCurrentWidth = brushWidth;
182 qreal brushStep = (0.5 * brushWidth);
183 brushStep = qMax(1.0, brushStep);
189 int steps = qRound(distance / brushStep);
191 for (
int i = 0; i < steps; i++)
193 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
194 mScribbleArea->drawPen(point,
197 mSettings.AntiAliasingEnabled());
199 if (i == (steps - 1))
201 mLastBrushPoint = getCurrentPoint();
205 else if (layer->type() == Layer::VECTOR)
207 qreal pressure = (mSettings.pressureEnabled()) ? mCurrentPressure : 1.0;
208 qreal brushWidth = mSettings.width() * pressure;
219 path.cubicTo(p[1], p[2], p[3]);
225void PenTool::paintVectorStroke(
Layer* layer)
227 if (mStrokePoints.
empty())
231 mScribbleArea->clearDrawingBuffer();
232 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
234 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
235 curve.setWidth(mSettings.width());
236 curve.setFeather(mSettings.feather());
237 curve.setFilled(
false);
238 curve.setInvisibility(mSettings.invisibilityEnabled());
239 curve.setVariableWidth(mSettings.pressureEnabled());
240 curve.setColorNumber(mEditor->color()->frontColorNumber());
242 auto pLayerVector =
static_cast<LayerVector*
>(layer);
243 VectorImage* vectorImage = pLayerVector->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
244 if (vectorImage ==
nullptr) {
return; }
245 vectorImage->
addCurve(curve, mEditor->view()->scaling(),
false);
249 mEditor->deselectAll();
254 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)
void remove(const QString &key)
QVariant value(const QString &key, const QVariant &defaultValue) const const
bool toBool() const const
int toInt(bool *ok) const const
qreal toReal(bool *ok) const const