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()
const
47void BrushTool::loadSettings()
51 mPropertyUsed[StrokeToolProperties::WIDTH_VALUE] = { Layer::BITMAP, Layer::VECTOR };
52 mPropertyUsed[StrokeToolProperties::FEATHER_VALUE] = { Layer::BITMAP };
53 mPropertyUsed[StrokeToolProperties::PRESSURE_ENABLED] = { Layer::BITMAP, Layer::VECTOR };
54 mPropertyUsed[StrokeToolProperties::INVISIBILITY_ENABLED] = { Layer::VECTOR };
55 mPropertyUsed[StrokeToolProperties::STABILIZATION_VALUE] = { Layer::BITMAP, Layer::VECTOR };
57 QSettings pencilSettings(PENCIL2D, PENCIL2D);
60 info[StrokeToolProperties::WIDTH_VALUE] = { WIDTH_MIN, WIDTH_MAX, 24.0 };
61 info[StrokeToolProperties::FEATHER_VALUE] = { FEATHER_MIN, FEATHER_MAX, 48.0 };
62 info[StrokeToolProperties::FEATHER_ENABLED] =
true;
63 info[StrokeToolProperties::PRESSURE_ENABLED] =
true;
64 info[StrokeToolProperties::INVISIBILITY_ENABLED] =
false;
65 info[StrokeToolProperties::STABILIZATION_VALUE] = { StabilizationLevel::NONE, StabilizationLevel::STRONG, StabilizationLevel::STRONG } ;
67 toolProperties().insertProperties(info);
68 toolProperties().loadFrom(typeName(), pencilSettings);
70 if (toolProperties().requireMigration(pencilSettings, ToolProperties::VERSION_1)) {
71 toolProperties().setBaseValue(StrokeToolProperties::WIDTH_VALUE, pencilSettings.
value(
"brushWidth", 24.0).
toReal());
72 toolProperties().setBaseValue(StrokeToolProperties::FEATHER_VALUE, pencilSettings.
value(
"brushFeather", 48.0).
toReal());
73 toolProperties().setBaseValue(StrokeToolProperties::PRESSURE_ENABLED, pencilSettings.
value(
"brushPressure",
true).
toBool());
74 toolProperties().setBaseValue(StrokeToolProperties::INVISIBILITY_ENABLED, pencilSettings.
value(
"brushInvisibility",
false).
toBool());
75 toolProperties().setBaseValue(StrokeToolProperties::STABILIZATION_VALUE, pencilSettings.
value(
"brushLineStabilization", StabilizationLevel::STRONG).
toInt());
77 pencilSettings.
remove(
"brushWidth");
78 pencilSettings.
remove(
"brushFeather");
79 pencilSettings.
remove(
"brushPressure");
80 pencilSettings.
remove(
"brushInvisibility");
81 pencilSettings.
remove(
"brushLineStabilization");
90 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
99 mInterpolator.pointerPressEvent(
event);
100 if (handleQuickSizing(
event)) {
104 mMouseDownPoint = getCurrentPoint();
105 mLastBrushPoint = getCurrentPoint();
107 startStroke(
event->inputType());
109 StrokeTool::pointerPressEvent(
event);
114 mInterpolator.pointerMoveEvent(
event);
115 if (handleQuickSizing(
event)) {
121 mCurrentPressure = mInterpolator.getPressure();
123 if (mSettings.stabilizerLevel() != mInterpolator.getStabilizerLevel())
125 mInterpolator.setStabilizerLevel(mSettings.stabilizerLevel());
129 StrokeTool::pointerMoveEvent(
event);
134 mInterpolator.pointerReleaseEvent(
event);
135 if (handleQuickSizing(
event)) {
139 if (
event->inputType() != mCurrentInputType)
return;
141 Layer* layer = mEditor->layers()->currentLayer();
142 mEditor->backup(typeName());
144 qreal distance =
QLineF(getCurrentPoint(), mMouseDownPoint).
length();
147 paintAt(mMouseDownPoint);
154 if (layer->type() == Layer::VECTOR) {
155 paintVectorStroke(layer);
160 StrokeTool::pointerReleaseEvent(
event);
164void BrushTool::paintAt(
QPointF point)
167 Layer* layer = mEditor->layers()->currentLayer();
168 if (layer->type() == Layer::BITMAP)
170 qreal pressure = (mSettings.pressureEnabled()) ? mCurrentPressure : 1.0;
171 qreal opacity = (mSettings.pressureEnabled()) ? (mCurrentPressure * 0.5) : 1.0;
172 qreal brushWidth = mSettings.width() * pressure;
173 mCurrentWidth = brushWidth;
174 mScribbleArea->drawBrush(point,
184void BrushTool::drawStroke()
186 StrokeTool::drawStroke();
189 Layer* layer = mEditor->layers()->currentLayer();
191 if (layer->type() == Layer::BITMAP)
193 qreal pressure = (mSettings.pressureEnabled()) ? mCurrentPressure : 1.0;
194 qreal opacity = (mSettings.pressureEnabled()) ? (mCurrentPressure * 0.5) : 1.0;
195 qreal brushWidth = mSettings.width() * pressure;
196 mCurrentWidth = brushWidth;
198 qreal brushStep = (0.5 * brushWidth);
199 brushStep = qMax(1.0, brushStep);
205 int steps = qRound(distance / brushStep);
207 for (
int i = 0; i < steps; i++)
209 QPointF point = mLastBrushPoint + (i + 1) * brushStep * (getCurrentPoint() - mLastBrushPoint) / distance;
211 mScribbleArea->drawBrush(point,
218 if (i == (steps - 1))
220 mLastBrushPoint = getCurrentPoint();
240 else if (layer->type() == Layer::VECTOR)
242 qreal pressure = (mSettings.pressureEnabled()) ? mCurrentPressure : 1;
243 qreal brushWidth = mSettings.width() * pressure;
254 path.cubicTo(p[1], p[2], p[3]);
263void BrushTool::paintVectorStroke(
Layer* layer)
265 if (mStrokePoints.
empty())
268 if (layer->type() == Layer::VECTOR && mStrokePoints.
size() > -1)
271 mScribbleArea->clearDrawingBuffer();
272 qreal tol = mScribbleArea->getCurveSmoothing() / mEditor->view()->scaling();
274 BezierCurve curve(mStrokePoints, mStrokePressures, tol);
275 curve.setWidth(mSettings.width());
276 curve.setFeather(mSettings.feather());
277 curve.setFilled(
false);
278 curve.setInvisibility(mSettings.invisibilityEnabled());
279 curve.setVariableWidth(mSettings.pressureEnabled());
280 curve.setColorNumber(mEditor->color()->frontColorNumber());
282 VectorImage* vectorImage =
static_cast<VectorImage*
>(layer->getLastKeyFrameAtPosition(mEditor->currentFrame()));
283 vectorImage->
addCurve(curve, mEditor->view()->scaling(),
false);
287 mEditor->deselectAll();
292 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
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