22 #include "vectorimage.h"
23 #include "layervector.h"
24 #include "colormanager.h"
25 #include "strokemanager.h"
26 #include "layermanager.h"
27 #include "viewmanager.h"
28 #include "selectionmanager.h"
30 #include "scribblearea.h"
32 #include "pointerevent.h"
39 void PenTool::loadSettings()
41 mPropertyEnabled[WIDTH] =
true;
42 mPropertyEnabled[PRESSURE] =
true;
43 mPropertyEnabled[VECTORMERGE] =
true;
44 mPropertyEnabled[ANTI_ALIASING] =
true;
45 mPropertyEnabled[STABILIZATION] =
true;
49 properties.width = settings.value(
"penWidth", 12.0).toDouble();
50 properties.pressure = settings.value(
"penPressure",
true).toBool();
51 properties.invisibility = OFF;
52 properties.preserveAlpha = OFF;
53 properties.useAA = settings.value(
"penAA",
true).toBool();
54 properties.stabilizerLevel = settings.value(
"penLineStabilization", StabilizationLevel::STRONG).toInt();
59 void PenTool::resetToDefault()
64 setStabilizerLevel(StabilizationLevel::STRONG);
68 void PenTool::setWidth(
const qreal width)
71 properties.width = width;
75 settings.setValue(
"penWidth", width);
79 void PenTool::setPressure(
const bool pressure)
82 properties.pressure = pressure;
86 settings.setValue(
"penPressure", pressure);
90 void PenTool::setAA(
const int AA)
93 properties.useAA = AA;
97 settings.setValue(
"penAA", AA);
101 void PenTool::setStabilizerLevel(
const int level)
103 properties.stabilizerLevel = level;
106 settings.setValue(
"penLineStabilization", level);
112 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
121 mScribbleArea->setAllDirty();
123 mMouseDownPoint = getCurrentPoint();
124 mLastBrushPoint = getCurrentPoint();
126 startStroke(event->inputType());
133 mCurrentPressure = strokeManager()->getPressure();
135 if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel())
136 strokeManager()->setStabilizerLevel(properties.stabilizerLevel);
142 if (event->inputType() != mCurrentInputType)
return;
144 mEditor->backup(typeName());
146 Layer* layer = mEditor->layers()->currentLayer();
148 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
151 paintAt(mMouseDownPoint);
158 if (layer->type() == Layer::BITMAP)
160 else if (layer->type() == Layer::VECTOR)
161 paintVectorStroke(layer);
166 void PenTool::paintAt(
QPointF point)
170 Layer* layer = mEditor->layers()->currentLayer();
171 if (layer->type() == Layer::BITMAP)
173 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
174 qreal brushWidth = properties.width * pressure;
175 mCurrentWidth = brushWidth;
177 mScribbleArea->drawPen(point,
179 mEditor->color()->frontColor(),
182 int rad = qRound(brushWidth) / 2 + 2;
185 mScribbleArea->refreshBitmap(rect, rad);
189 void PenTool::drawStroke()
191 StrokeTool::drawStroke();
194 Layer* layer = mEditor->layers()->currentLayer();
196 if (layer->type() == Layer::BITMAP)
198 for (
int i = 0; i < p.
size(); i++)
200 p[i] = mEditor->view()->mapScreenToCanvas(p[i]);
203 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
204 qreal brushWidth = properties.width * pressure;
205 mCurrentWidth = brushWidth;
209 qreal brushStep = (0.5 * brushWidth);
210 brushStep = qMax(1.0, brushStep);
218 int steps = qRound(distance / brushStep);
220 for (
int i = 0; i < steps; i++)
222 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
224 mScribbleArea->drawPen(point,
226 mEditor->color()->frontColor(),
229 if (i == (steps - 1))
231 mLastBrushPoint = getCurrentPoint();
235 int rad = qRound(brushWidth) / 2 + 2;
237 mScribbleArea->paintBitmapBufferRect(rect);
238 mScribbleArea->refreshBitmap(rect, rad);
240 else if (layer->type() == Layer::VECTOR)
242 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
243 qreal brushWidth = properties.width * pressure;
245 int rad = qRound((brushWidth / 2 + 2) * mEditor->view()->scaling());
247 QPen pen(mEditor->color()->frontColor(),
248 brushWidth * mEditor->view()->scaling(),
256 path.cubicTo(p[1], p[2], p[3]);
258 mScribbleArea->refreshVector(path.boundingRect().toRect(), rad);
263 void PenTool::paintBitmapStroke()
265 mScribbleArea->paintBitmapBuffer();
266 mScribbleArea->setAllDirty();
267 mScribbleArea->clearBitmapBuffer();
270 void PenTool::paintVectorStroke(
Layer* layer)
272 if (mStrokePoints.
empty())
276 mScribbleArea->clearBitmapBuffer();
277 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
279 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
280 curve.setWidth(properties.width);
281 curve.setFeather(properties.feather);
282 curve.setFilled(
false);
283 curve.setInvisibility(properties.invisibility);
284 curve.setVariableWidth(properties.pressure);
285 curve.setColorNumber(mEditor->color()->frontColorNumber());
287 auto pLayerVector =
static_cast<LayerVector*
>(layer);
288 VectorImage* vectorImage = pLayerVector->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
289 if (vectorImage ==
nullptr) {
return; }
290 vectorImage->
addCurve(curve, mEditor->view()->scaling(),
false);
294 mEditor->deselectAll();
299 mScribbleArea->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
300 mScribbleArea->setAllDirty();
QHash::iterator insert(const Key &key, const T &value)
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.