17#include "buckettool.h"
22#include "pointerevent.h"
25#include "layervector.h"
26#include "layerbitmap.h"
27#include "layercamera.h"
28#include "layermanager.h"
29#include "colormanager.h"
30#include "viewmanager.h"
31#include "vectorimage.h"
33#include "scribblearea.h"
40ToolType BucketTool::type()
45void BucketTool::loadSettings()
47 mPropertyEnabled[TOLERANCE] =
true;
48 mPropertyEnabled[WIDTH] =
true;
49 mPropertyEnabled[FILL_MODE] =
true;
53 properties.width = settings.value(
"fillThickness", 4.0).toDouble();
54 properties.feather = 10;
55 properties.stabilizerLevel = StabilizationLevel::NONE;
56 properties.useAA = DISABLED;
57 properties.tolerance = settings.value(SETTING_BUCKET_TOLERANCE, 32.0).toDouble();
58 properties.toleranceEnabled = settings.value(SETTING_BUCKET_TOLERANCE_ON,
false).toBool();
60 properties.bucketFillExpand = settings.value(SETTING_BUCKET_FILL_EXPAND, 2.0).toInt();
61 properties.bucketFillExpandEnabled = settings.value(SETTING_BUCKET_FILL_EXPAND_ON,
true).toBool();
62 properties.bucketFillReferenceMode = settings.value(SETTING_BUCKET_FILL_REFERENCE_MODE, 0).toInt();
63 properties.fillMode = settings.value(SETTING_FILL_MODE, 0).toInt();
66void BucketTool::resetToDefault()
72 setFillExpandEnabled(
true);
73 setToleranceEnabled(
false);
74 setFillReferenceMode(0);
79 if (mEditor->preference()->isOn(SETTING::TOOL_CURSOR))
81 return QCursor(
QPixmap(
":icons/general/cursor-bucket.svg"), -1, 17);
89void BucketTool::setTolerance(
const int tolerance)
92 properties.tolerance = tolerance;
96 settings.setValue(SETTING_BUCKET_TOLERANCE, tolerance);
108 properties.width = width;
112 settings.
setValue(
"fillThickness", width);
116void BucketTool::setFillMode(
int mode)
119 properties.fillMode = mode;
123 settings.setValue(SETTING_FILL_MODE, mode);
127void BucketTool::setToleranceEnabled(
const bool enabled)
129 properties.toleranceEnabled = enabled;
133 settings.setValue(SETTING_BUCKET_TOLERANCE_ON, enabled);
137void BucketTool::setFillExpandEnabled(
const bool enabled)
139 properties.bucketFillExpandEnabled = enabled;
143 settings.setValue(SETTING_BUCKET_FILL_EXPAND_ON, enabled);
147void BucketTool::setFillExpand(
const int fillExpandValue)
149 properties.bucketFillExpand = fillExpandValue;
153 settings.setValue(SETTING_BUCKET_FILL_EXPAND, fillExpandValue);
157void BucketTool::setFillReferenceMode(
int referenceMode)
159 properties.bucketFillReferenceMode = referenceMode;
163 settings.setValue(SETTING_BUCKET_FILL_REFERENCE_MODE, referenceMode);
169 mInterpolator.pointerPressEvent(
event);
170 startStroke(
event->inputType());
172 Layer* targetLayer = mEditor->layers()->currentLayer();
174 if (targetLayer->type() != Layer::BITMAP) {
return; }
176 LayerCamera* layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex());
180 layerCam ? layerCam->getViewAtFrame(mEditor->currentFrame()).
inverted().
mapRect(layerCam->getViewRect()) :
QRect(),
192 mInterpolator.pointerMoveEvent(
event);
195 Layer* layer = mEditor->layers()->currentLayer();
196 if (layer->type() == Layer::VECTOR)
200 else if (layer->type() == Layer::BITMAP)
203 mFilledOnMove =
true;
208void BucketTool::pointerReleaseEvent(
PointerEvent* event)
210 mInterpolator.pointerReleaseEvent(
event);
211 if (
event->inputType() != mCurrentInputType)
return;
213 Layer* layer = editor()->layers()->currentLayer();
214 if (layer ==
nullptr) {
return; }
219 if (layer->type() == Layer::VECTOR) {
220 mEditor->backup(typeName());
223 else if (layer->type() == Layer::BITMAP && !mFilledOnMove)
228 mFilledOnMove =
false;
233void BucketTool::paintBitmap()
235 mBitmapBucket.
paint(getCurrentPoint(), [
this](BucketState progress,
int layerIndex,
int frameIndex)
237 if (progress == BucketState::WillFillTarget)
239 mEditor->backup(layerIndex, frameIndex, typeName());
241 else if (progress == BucketState::DidFillTarget)
243 mEditor->setModified(layerIndex, frameIndex);
248void BucketTool::paintVector(
Layer* layer)
250 mScribbleArea->clearDrawingBuffer();
252 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
253 if (vectorImage ==
nullptr) {
return; }
266 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
269void BucketTool::applyChanges()
271 mScribbleArea->applyTransformedSelection();
274void BucketTool::drawStroke()
276 StrokeTool::drawStroke();
278 if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
280 mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
285 Layer* layer = mEditor->layers()->currentLayer();
287 if (layer->type() == Layer::VECTOR)
293 mCurrentWidth * mEditor->view()->scaling(),
301 path.cubicTo(p[1], p[2], p[3]);
void paint(const QPointF &updatedPoint, std::function< void(BucketState, int, int)> progress)
Will paint at the given point, given that it makes sense.
QColor frontColor(bool useIndexedColor=true)
frontColor
void invalidatePainterCaches()
Invalidate the layer pixmap and camera painter caches.
void applyColorToSelectedArea(int colorNumber)
VectorImage::applyColorToSelectedArea.
void fillSelectedPath(int color)
VectorImage::fillSelectedPath.
bool isPathFilled()
VectorImage::isPathFilled.
void applyColorToSelectedCurve(int colorNumber)
VectorImage::applyColorToSelectedCurve.
void applyWidthToSelection(qreal width)
VectorImage::applyWidthToSelection.
virtual bool event(QEvent *e)
void setValue(const QString &key, const QVariant &value)