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 "scribblearea.h"
34#include "pointerevent.h"
41ToolType BrushTool::type()
46void BrushTool::loadSettings()
50 mPropertyEnabled[WIDTH] =
true;
51 mPropertyEnabled[FEATHER] =
true;
52 mPropertyEnabled[PRESSURE] =
true;
53 mPropertyEnabled[INVISIBILITY] =
true;
54 mPropertyEnabled[STABILIZATION] =
true;
58 properties.width = settings.value(
"brushWidth", 24.0).toDouble();
59 properties.feather = settings.value(
"brushFeather", 48.0).toDouble();
60 properties.pressure = settings.value(
"brushPressure",
true).toBool();
61 properties.invisibility = settings.value(
"brushInvisibility",
false).toBool();
62 properties.preserveAlpha = OFF;
63 properties.stabilizerLevel = settings.value(
"brushLineStabilization", StabilizationLevel::STRONG).toInt();
64 properties.useAA = DISABLED;
66 if (properties.width <= 0) { setWidth(15); }
67 if (std::isnan(properties.feather)) { setFeather(15); }
73void BrushTool::resetToDefault()
77 setStabilizerLevel(StabilizationLevel::STRONG);
80void BrushTool::setWidth(
const qreal width)
83 properties.width = width;
87 settings.setValue(
"brushWidth", width);
91void BrushTool::setFeather(
const qreal feather)
94 properties.feather = feather;
98 settings.setValue(
"brushFeather", feather);
102void BrushTool::setInvisibility(
const bool invisibility)
105 properties.invisibility = invisibility;
108 settings.setValue(
"brushInvisibility", invisibility);
112void BrushTool::setPressure(
const bool pressure)
115 properties.pressure = pressure;
119 settings.setValue(
"brushPressure", pressure);
123void BrushTool::setStabilizerLevel(
const int level)
125 properties.stabilizerLevel = level;
128 settings.setValue(
"brushLineStabilization", level);
134 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
136 return QCursor(
QPixmap(
":icons/general/cursor-brush.svg"), 4, 14);
143 mInterpolator.pointerPressEvent(event);
144 if (handleQuickSizing(event)) {
148 mMouseDownPoint = getCurrentPoint();
149 mLastBrushPoint = getCurrentPoint();
151 startStroke(event->inputType());
153 StrokeTool::pointerPressEvent(event);
158 mInterpolator.pointerMoveEvent(event);
159 if (handleQuickSizing(event)) {
165 mCurrentPressure = mInterpolator.getPressure();
167 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
169 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
173 StrokeTool::pointerMoveEvent(event);
178 mInterpolator.pointerReleaseEvent(event);
179 if (handleQuickSizing(event)) {
183 if (event->inputType() != mCurrentInputType)
return;
185 Layer* layer = mEditor->layers()->currentLayer();
186 mEditor->backup(typeName());
188 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
191 paintAt(mMouseDownPoint);
198 if (layer->type() == Layer::VECTOR) {
199 paintVectorStroke(layer);
203 StrokeTool::pointerReleaseEvent(event);
207void BrushTool::paintAt(
QPointF point)
210 Layer* layer = mEditor->layers()->currentLayer();
211 if (layer->type() == Layer::BITMAP)
213 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
214 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
215 qreal brushWidth = properties.width * pressure;
216 mCurrentWidth = brushWidth;
217 mScribbleArea->drawBrush(point,
227void BrushTool::drawStroke()
229 StrokeTool::drawStroke();
232 Layer* layer = mEditor->layers()->currentLayer();
234 if (layer->type() == Layer::BITMAP)
236 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
237 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
238 qreal brushWidth = properties.width * pressure;
239 mCurrentWidth = brushWidth;
241 qreal brushStep = (0.5 * brushWidth);
242 brushStep = qMax(1.0, brushStep);
248 int steps = qRound(distance / brushStep);
250 for (
int i = 0; i < steps; i++)
252 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
254 mScribbleArea->drawBrush(point,
261 if (i == (steps - 1))
263 mLastBrushPoint = getCurrentPoint();
283 else if (layer->type() == Layer::VECTOR)
285 qreal pressure = (properties.pressure) ? mCurrentPressure : 1;
286 qreal brushWidth = properties.width * pressure;
297 path.cubicTo(p[1], p[2], p[3]);
306void BrushTool::paintVectorStroke(
Layer* layer)
308 if (mStrokePoints.
empty())
311 if (layer->type() == Layer::VECTOR && mStrokePoints.
size() > -1)
314 mScribbleArea->clearDrawingBuffer();
315 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
317 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
318 curve.setWidth(properties.width);
319 curve.setFeather(properties.feather);
320 curve.setFilled(
false);
321 curve.setInvisibility(properties.invisibility);
322 curve.setVariableWidth(properties.pressure);
323 curve.setColorNumber(mEditor->color()->frontColorNumber());
325 VectorImage* vectorImage =
static_cast<VectorImage*
>(layer->getLastKeyFrameAtPosition(mEditor->currentFrame()));
326 vectorImage->
addCurve(curve, mEditor->view()->scaling(),
false);
330 mEditor->deselectAll();
335 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
QColor frontColor(bool useIndexedColor=true)
frontColor
Qt::MouseButtons buttons() const
Returns Qt::MouseButtons()
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
CompositionMode_SourceOver