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::resetToDefault()
78 setStabilizerLevel(StabilizationLevel::STRONG);
81void BrushTool::setWidth(
const qreal width)
84 properties.width = width;
88 settings.setValue(
"brushWidth", width);
92void BrushTool::setFeather(
const qreal feather)
95 properties.feather = feather;
99 settings.setValue(
"brushFeather", feather);
103void BrushTool::setInvisibility(
const bool invisibility)
106 properties.invisibility = invisibility;
109 settings.setValue(
"brushInvisibility", invisibility);
113void BrushTool::setPressure(
const bool pressure)
116 properties.pressure = pressure;
120 settings.setValue(
"brushPressure", pressure);
124void BrushTool::setStabilizerLevel(
const int level)
126 properties.stabilizerLevel = level;
129 settings.setValue(
"brushLineStabilization", level);
135 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
137 return QCursor(
QPixmap(
":icons/general/cursor-brush.svg"), 4, 14);
144 mInterpolator.pointerPressEvent(
event);
145 if (handleQuickSizing(
event)) {
149 mMouseDownPoint = getCurrentPoint();
150 mLastBrushPoint = getCurrentPoint();
152 startStroke(
event->inputType());
154 StrokeTool::pointerPressEvent(
event);
159 mInterpolator.pointerMoveEvent(
event);
160 if (handleQuickSizing(
event)) {
166 mCurrentPressure = mInterpolator.getPressure();
168 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
170 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
174 StrokeTool::pointerMoveEvent(
event);
179 mInterpolator.pointerReleaseEvent(
event);
180 if (handleQuickSizing(
event)) {
184 if (
event->inputType() != mCurrentInputType)
return;
186 Layer* layer = mEditor->layers()->currentLayer();
187 mEditor->backup(typeName());
189 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
192 paintAt(mMouseDownPoint);
199 if (layer->type() == Layer::VECTOR) {
200 paintVectorStroke(layer);
205 StrokeTool::pointerReleaseEvent(
event);
209void BrushTool::paintAt(
QPointF point)
212 Layer* layer = mEditor->layers()->currentLayer();
213 if (layer->type() == Layer::BITMAP)
215 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
216 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
217 qreal brushWidth = properties.width * pressure;
218 mCurrentWidth = brushWidth;
219 mScribbleArea->drawBrush(point,
229void BrushTool::drawStroke()
231 StrokeTool::drawStroke();
234 Layer* layer = mEditor->layers()->currentLayer();
236 if (layer->type() == Layer::BITMAP)
238 qreal pressure = (properties.pressure) ? mCurrentPressure : 1.0;
239 qreal opacity = (properties.pressure) ? (mCurrentPressure * 0.5) : 1.0;
240 qreal brushWidth = properties.width * pressure;
241 mCurrentWidth = brushWidth;
243 qreal brushStep = (0.5 * brushWidth);
244 brushStep = qMax(1.0, brushStep);
250 int steps = qRound(distance / brushStep);
252 for (
int i = 0; i < steps; i++)
254 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
256 mScribbleArea->drawBrush(point,
263 if (i == (steps - 1))
265 mLastBrushPoint = getCurrentPoint();
285 else if (layer->type() == Layer::VECTOR)
287 qreal pressure = (properties.pressure) ? mCurrentPressure : 1;
288 qreal brushWidth = properties.width * pressure;
299 path.cubicTo(p[1], p[2], p[3]);
308void BrushTool::paintVectorStroke(
Layer* layer)
310 if (mStrokePoints.
empty())
313 if (layer->type() == Layer::VECTOR && mStrokePoints.
size() > -1)
316 mScribbleArea->clearDrawingBuffer();
317 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
319 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
320 curve.setWidth(properties.width);
321 curve.setFeather(properties.feather);
322 curve.setFilled(
false);
323 curve.setInvisibility(properties.invisibility);
324 curve.setVariableWidth(properties.pressure);
325 curve.setColorNumber(mEditor->color()->frontColorNumber());
327 VectorImage* vectorImage =
static_cast<VectorImage*
>(layer->getLastKeyFrameAtPosition(mEditor->currentFrame()));
328 vectorImage->
addCurve(curve, mEditor->view()->scaling(),
false);
332 mEditor->deselectAll();
337 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