26#include "beziercurve.h"
27#include "vectorimage.h"
29#include "colormanager.h"
30#include "layermanager.h"
31#include "viewmanager.h"
32#include "selectionmanager.h"
33#include "undoredomanager.h"
34#include "scribblearea.h"
35#include "pointerevent.h"
42ToolType BrushTool::type()
47void BrushTool::loadSettings()
51 mPropertyEnabled[WIDTH] =
true;
52 mPropertyEnabled[FEATHER] =
true;
53 mPropertyEnabled[PRESSURE] =
true;
54 mPropertyEnabled[INVISIBILITY] =
true;
55 mPropertyEnabled[STABILIZATION] =
true;
59 properties.width = settings.value(
"brushWidth", 24.0).toDouble();
60 properties.feather = settings.value(
"brushFeather", 48.0).toDouble();
61 properties.pressure = settings.value(
"brushPressure",
true).toBool();
62 properties.invisibility = settings.value(
"brushInvisibility",
false).toBool();
63 properties.preserveAlpha = OFF;
64 properties.stabilizerLevel = settings.value(
"brushLineStabilization", StabilizationLevel::STRONG).toInt();
65 properties.useAA = DISABLED;
67 if (properties.width <= 0) { setWidth(15); }
68 if (std::isnan(properties.feather)) { setFeather(15); }
74void BrushTool::saveSettings()
78 settings.setValue(
"brushWidth", properties.width);
79 settings.setValue(
"brushFeather", properties.feather);
80 settings.setValue(
"brushPressure", properties.pressure);
81 settings.setValue(
"brushInvisibility", properties.invisibility);
82 settings.setValue(
"brushLineStabilization", properties.stabilizerLevel);
87void BrushTool::resetToDefault()
91 setStabilizerLevel(StabilizationLevel::STRONG);
94void BrushTool::setWidth(
const qreal width)
97 properties.width = width;
100void BrushTool::setFeather(
const qreal feather)
103 properties.feather = feather;
106void BrushTool::setInvisibility(
const bool invisibility)
109 properties.invisibility = invisibility;
112void BrushTool::setPressure(
const bool pressure)
115 properties.pressure = pressure;
118void BrushTool::setStabilizerLevel(
const int level)
120 properties.stabilizerLevel = level;
125 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
127 return QCursor(
QPixmap(
":icons/general/cursor-brush.svg"), 4, 14);
134 mInterpolator.pointerPressEvent(
event);
135 if (handleQuickSizing(
event)) {
139 mMouseDownPoint = getCurrentPoint();
140 mLastBrushPoint = getCurrentPoint();
142 startStroke(
event->inputType());
144 StrokeTool::pointerPressEvent(
event);
149 mInterpolator.pointerMoveEvent(
event);
150 if (handleQuickSizing(
event)) {
156 mCurrentPressure = mInterpolator.getPressure();
158 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
160 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
164 StrokeTool::pointerMoveEvent(
event);
169 mInterpolator.pointerReleaseEvent(
event);
170 if (handleQuickSizing(
event)) {
174 if (
event->inputType() != mCurrentInputType)
return;
176 Layer* layer = mEditor->layers()->currentLayer();
177 mEditor->backup(typeName());
179 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
182 paintAt(mMouseDownPoint);
189 if (layer->type() == Layer::VECTOR) {
190 paintVectorStroke(layer);
195 StrokeTool::pointerReleaseEvent(
event);
199void BrushTool::paintAt(
QPointF point)
202 Layer* layer = mEditor->layers()->currentLayer();
203 if (layer->type() == Layer::BITMAP)
205 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
206 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
207 qreal brushWidth = properties.width * pressure;
208 mCurrentWidth = brushWidth;
209 mScribbleArea->drawBrush(point,
219void BrushTool::drawStroke()
221 StrokeTool::drawStroke();
224 Layer* layer = mEditor->layers()->currentLayer();
226 if (layer->type() == Layer::BITMAP)
228 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
229 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
230 qreal brushWidth = properties.width * pressure;
231 mCurrentWidth = brushWidth;
233 qreal brushStep = (0.5 * brushWidth);
234 brushStep = qMax(1.0, brushStep);
240 int steps = qRound(distance / brushStep);
242 for (
int i = 0; i < steps; i++)
244 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
246 mScribbleArea->drawBrush(point,
253 if (i == (steps - 1))
255 mLastBrushPoint = getCurrentPoint();
275 else if (layer->type() == Layer::VECTOR)
277 qreal pressure = (properties.pressure) ? mCurrentPressure : 1;
278 qreal brushWidth = properties.width * pressure;
289 path.cubicTo(p[1], p[2], p[3]);
298void BrushTool::paintVectorStroke(
Layer* layer)
300 if (mStrokePoints.
empty())
303 if (layer->type() == Layer::VECTOR && mStrokePoints.
size() > -1)
306 mScribbleArea->clearDrawingBuffer();
307 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
309 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
310 curve.setWidth(properties.width);
311 curve.setFeather(properties.feather);
312 curve.setFilled(
false);
313 curve.setInvisibility(properties.invisibility);
314 curve.setVariableWidth(properties.pressure);
315 curve.setColorNumber(mEditor->color()->frontColorNumber());
317 VectorImage* vectorImage =
static_cast<VectorImage*
>(layer->getLastKeyFrameAtPosition(mEditor->currentFrame()));
318 vectorImage->
addCurve(curve, mEditor->view()->scaling(),
false);
322 mEditor->deselectAll();
327 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)
CompositionMode_SourceOver