18 #include "polylinetool.h"
22 #include "scribblearea.h"
24 #include "strokemanager.h"
25 #include "layermanager.h"
26 #include "colormanager.h"
27 #include "viewmanager.h"
28 #include "pointerevent.h"
29 #include "layervector.h"
30 #include "layerbitmap.h"
31 #include "vectorimage.h"
38 ToolType PolylineTool::type()
43 void PolylineTool::loadSettings()
45 mPropertyEnabled[WIDTH] =
true;
46 mPropertyEnabled[BEZIER] =
true;
47 mPropertyEnabled[ANTI_ALIASING] =
true;
51 properties.width = settings.value(
"polyLineWidth", 8.0).toDouble();
52 properties.feather = -1;
53 properties.pressure =
false;
54 properties.invisibility = OFF;
55 properties.preserveAlpha = OFF;
56 properties.useAA = settings.value(
"brushAA").toBool();
57 properties.stabilizerLevel = -1;
60 void PolylineTool::resetToDefault()
66 void PolylineTool::setWidth(
const qreal width)
69 properties.width = width;
73 settings.setValue(
"polyLineWidth", width);
77 void PolylineTool::setFeather(
const qreal feather)
80 properties.feather = -1;
83 void PolylineTool::setAA(
const int AA)
86 properties.useAA = AA;
90 settings.setValue(
"brushAA", AA);
104 void PolylineTool::clearToolData()
109 void PolylineTool::pointerPressEvent(
PointerEvent* event)
111 Layer* layer = mEditor->layers()->currentLayer();
115 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
119 if (layer->type() == Layer::VECTOR)
121 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
122 Q_CHECK_PTR(vectorImage);
124 if (mScribbleArea->makeInvisible() && !mEditor->preference()->isOn(SETTING::INVISIBLE_LINES))
126 mScribbleArea->toggleThinLines();
129 mPoints << getCurrentPoint();
130 mScribbleArea->setAllDirty();
137 Layer* layer = mEditor->layers()->currentLayer();
138 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
140 drawPolyline(mPoints, getCurrentPoint());
147 void PolylineTool::pointerDoubleClickEvent(
PointerEvent*)
150 mPoints << getCurrentPoint();
152 mEditor->backup(typeName());
154 endPolyline(mPoints);
159 bool PolylineTool::keyPressEvent(
QKeyEvent* event)
161 switch (event->
key())
164 if (mPoints.
size() > 0)
166 endPolyline(mPoints);
173 if (mPoints.
size() > 0)
190 if (points.
size() > 0)
192 QPen pen(mEditor->color()->frontColor(),
197 Layer* layer = mEditor->layers()->currentLayer();
201 if (properties.bezier_state)
209 tempPath.
lineTo(endPoint);
212 if (layer->type() == Layer::VECTOR)
214 if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR)
216 tempPath = mEditor->view()->mapCanvasToScreen(tempPath);
217 if (mScribbleArea->makeInvisible() ==
true)
224 pen.setWidth(properties.width * mEditor->view()->scaling());
229 mScribbleArea->drawPolyline(tempPath, pen, properties.useAA);
234 void PolylineTool::cancelPolyline()
237 mScribbleArea->clearBitmapBuffer();
238 mScribbleArea->updateCurrentFrame();
243 Layer* layer = mEditor->layers()->currentLayer();
244 mScribbleArea->clearBitmapBuffer();
246 if (layer->type() == Layer::VECTOR)
249 if (mScribbleArea->makeInvisible() ==
true)
255 curve.setWidth(properties.width);
257 curve.setColorNumber(mEditor->color()->frontColorNumber());
258 curve.setVariableWidth(
false);
259 curve.setInvisibility(mScribbleArea->makeInvisible());
261 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
262 if (vectorImage ==
nullptr) {
return; }
263 vectorImage->
addCurve(curve, mEditor->view()->scaling());
265 if (layer->type() == Layer::BITMAP)
267 drawPolyline(points, points.
last());
268 BitmapImage *bitmapImage =
static_cast<LayerBitmap*
>(layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0);
269 if (bitmapImage ==
nullptr) {
return; }
270 bitmapImage->paste(mScribbleArea->mBufferImg);
273 mScribbleArea->setAllDirty();
274 mScribbleArea->clearBitmapBuffer();
275 mScribbleArea->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
void deselectAll()
VectorImage::deselectAll.
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
void lineTo(const QPointF &endPoint)
bool isEmpty() const const
void addCurve(BezierCurve &newCurve, qreal factor, bool interacts=true)
VectorImage::addCurve.
Qt::MouseButton button() const
Returns Qt::MouseButton()