18#include "polylinetool.h"
22#include "scribblearea.h"
24#include "layermanager.h"
25#include "colormanager.h"
26#include "viewmanager.h"
27#include "pointerevent.h"
28#include "layervector.h"
29#include "layerbitmap.h"
30#include "vectorimage.h"
37ToolType PolylineTool::type()
42void PolylineTool::loadSettings()
46 mPropertyEnabled[WIDTH] =
true;
47 mPropertyEnabled[BEZIER] =
true;
48 mPropertyEnabled[ANTI_ALIASING] =
true;
52 properties.width = settings.value(
"polyLineWidth", 8.0).toDouble();
53 properties.feather = -1;
54 properties.pressure =
false;
55 properties.invisibility = OFF;
56 properties.preserveAlpha = OFF;
57 properties.useAA = settings.value(
"brushAA").toBool();
58 properties.stabilizerLevel = -1;
63void PolylineTool::resetToDefault()
69void PolylineTool::setWidth(
const qreal width)
72 properties.width = width;
76 settings.setValue(
"polyLineWidth", width);
80void PolylineTool::setFeather(
const qreal feather)
83 properties.feather = -1;
86void PolylineTool::setAA(
const int AA)
89 properties.useAA = AA;
93 settings.setValue(
"brushAA", AA);
100 if (mPoints.
size() > 0)
117void PolylineTool::clearToolData()
119 if (mPoints.
empty()) {
124 emit isActiveChanged(POLYLINE,
false);
127 mScribbleArea->clearDrawingBuffer();
131void PolylineTool::pointerPressEvent(
PointerEvent* event)
133 mInterpolator.pointerPressEvent(event);
134 if (handleQuickSizing(event)) {
138 Layer* layer = mEditor->layers()->currentLayer();
142 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
146 if (layer->type() == Layer::VECTOR)
148 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
149 Q_CHECK_PTR(vectorImage);
151 if (mScribbleArea->makeInvisible() && !mEditor->preference()->isOn(SETTING::INVISIBLE_LINES))
153 mScribbleArea->toggleThinLines();
156 mPoints << getCurrentPoint();
157 emit isActiveChanged(POLYLINE,
true);
161 StrokeTool::pointerPressEvent(event);
166 mInterpolator.pointerMoveEvent(event);
167 if (handleQuickSizing(event)) {
171 Layer* layer = mEditor->layers()->currentLayer();
172 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
174 drawPolyline(mPoints, getCurrentPoint());
177 StrokeTool::pointerMoveEvent(event);
180void PolylineTool::pointerReleaseEvent(
PointerEvent* event)
182 mInterpolator.pointerReleaseEvent(event);
183 if (handleQuickSizing(event)) {
187 StrokeTool::pointerReleaseEvent(event);
190void PolylineTool::pointerDoubleClickEvent(
PointerEvent* event)
192 mInterpolator.pointerPressEvent(event);
194 mPoints << getCurrentPoint();
196 mEditor->backup(typeName());
198 endPolyline(mPoints);
202bool PolylineTool::keyPressEvent(
QKeyEvent* event)
204 switch (event->
key())
207 if (mPoints.
size() > 0)
209 endPolyline(mPoints);
215 if (mPoints.
size() > 0)
226 return BaseTool::keyPressEvent(event);
231 if (points.
size() > 0)
238 Layer* layer = mEditor->layers()->currentLayer();
242 if (properties.bezier_state)
250 tempPath.
lineTo(endPoint);
253 if (layer->type() == Layer::VECTOR)
255 if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR)
257 if (mScribbleArea->makeInvisible() ==
true)
264 pen.setWidth(properties.width);
269 mScribbleArea->drawPolyline(tempPath, pen, properties.useAA);
274void PolylineTool::cancelPolyline()
281 Layer* layer = mEditor->layers()->currentLayer();
283 if (layer->type() == Layer::VECTOR)
286 if (mScribbleArea->makeInvisible() ==
true)
292 curve.setWidth(properties.width);
294 curve.setColorNumber(mEditor->color()->frontColorNumber());
295 curve.setVariableWidth(
false);
296 curve.setInvisibility(mScribbleArea->makeInvisible());
298 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
299 if (vectorImage ==
nullptr) {
return; }
300 vectorImage->
addCurve(curve, mEditor->view()->scaling());
302 if (layer->type() == Layer::BITMAP)
304 drawPolyline(points, points.
last());
306 mScribbleArea->endStroke();
307 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
QColor frontColor(bool useIndexedColor=true)
frontColor
Qt::MouseButton button() const
Returns Qt::MouseButton()
void updateFrame()
Update frame.
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
void deselectAll()
VectorImage::deselectAll.
void addCurve(BezierCurve &newCurve, qreal factor, bool interacts=true)
VectorImage::addCurve.
QHash::iterator insert(const Key &key, const T &value)
bool isEmpty() const const
void lineTo(const QPointF &endPoint)