18#include "polylinetool.h"
22#include "scribblearea.h"
24#include "layermanager.h"
25#include "colormanager.h"
26#include "viewmanager.h"
27#include "undoredomanager.h"
28#include "pointerevent.h"
29#include "layervector.h"
30#include "layerbitmap.h"
31#include "vectorimage.h"
38ToolType PolylineTool::type()
43void PolylineTool::loadSettings()
47 mPropertyEnabled[WIDTH] =
true;
48 mPropertyEnabled[BEZIER] =
true;
49 mPropertyEnabled[CLOSEDPATH] =
true;
50 mPropertyEnabled[ANTI_ALIASING] =
true;
54 properties.width = settings.value(
"polyLineWidth", 8.0).toDouble();
55 properties.feather = -1;
56 properties.pressure =
false;
57 properties.invisibility = OFF;
58 properties.preserveAlpha = OFF;
59 properties.closedPolylinePath = settings.value(
"closedPolylinePath").toBool();
60 properties.useAA = settings.value(
"brushAA").toBool();
61 properties.stabilizerLevel = -1;
66void PolylineTool::resetToDefault()
73void PolylineTool::setWidth(
const qreal width)
76 properties.width = width;
80 settings.setValue(
"polyLineWidth", width);
84void PolylineTool::setFeather(
const qreal feather)
87 properties.feather = -1;
90void PolylineTool::setAA(
const int AA)
93 properties.useAA = AA;
97 settings.setValue(
"brushAA", AA);
101void PolylineTool::setClosedPath(
const bool closed)
103 BaseTool::setClosedPath(closed);
107 settings.setValue(
"closedPolylinePath", closed);
114 if (mPoints.
size() > 0)
131void PolylineTool::clearToolData()
133 if (mPoints.
empty()) {
138 emit isActiveChanged(POLYLINE,
false);
141 mScribbleArea->clearDrawingBuffer();
145void PolylineTool::pointerPressEvent(
PointerEvent* event)
147 mInterpolator.pointerPressEvent(
event);
148 if (handleQuickSizing(
event)) {
152 Layer* layer = mEditor->layers()->currentLayer();
156 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
160 if (layer->type() == Layer::VECTOR)
162 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
163 Q_CHECK_PTR(vectorImage);
165 if (mScribbleArea->makeInvisible() && !mEditor->preference()->isOn(SETTING::INVISIBLE_LINES))
167 mScribbleArea->toggleThinLines();
170 mPoints << getCurrentPoint();
171 emit isActiveChanged(POLYLINE,
true);
175 StrokeTool::pointerPressEvent(
event);
180 mInterpolator.pointerMoveEvent(
event);
181 if (handleQuickSizing(
event)) {
185 Layer* layer = mEditor->layers()->currentLayer();
186 if (layer->type() == Layer::BITMAP || layer->type() == Layer::VECTOR)
188 drawPolyline(mPoints, getCurrentPoint());
191 StrokeTool::pointerMoveEvent(
event);
194void PolylineTool::pointerReleaseEvent(
PointerEvent* event)
196 mInterpolator.pointerReleaseEvent(
event);
197 if (handleQuickSizing(
event)) {
201 StrokeTool::pointerReleaseEvent(
event);
204void PolylineTool::pointerDoubleClickEvent(
PointerEvent* event)
206 mInterpolator.pointerPressEvent(
event);
208 mPoints << getCurrentPoint();
210 const UndoSaveState* saveState = mEditor->undoRedo()->
state(UndoRedoRecordType::KEYFRAME_MODIFY);
211 mEditor->backup(typeName());
213 endPolyline(mPoints);
214 mEditor->undoRedo()->
record(saveState, typeName());
217void PolylineTool::removeLastPolylineSegment()
221 if (mPoints.
size() > 1)
224 drawPolyline(mPoints, getCurrentPoint());
226 else if (mPoints.
size() == 1)
233bool PolylineTool::keyPressEvent(
QKeyEvent* event)
235 switch (
event->key())
238 mClosedPathOverrideEnabled =
true;
239 drawPolyline(mPoints, getCurrentPoint());
244 if (mPoints.
size() > 0)
246 const UndoSaveState* saveState = mEditor->undoRedo()->
state(UndoRedoRecordType::KEYFRAME_MODIFY);
247 endPolyline(mPoints);
248 mEditor->undoRedo()->
record(saveState, typeName());
254 if (mPoints.
size() > 0)
265 return BaseTool::keyPressEvent(
event);
268bool PolylineTool::keyReleaseEvent(
QKeyEvent* event)
270 switch (
event->key())
273 mClosedPathOverrideEnabled =
false;
274 drawPolyline(mPoints, getCurrentPoint());
282 return BaseTool::keyReleaseEvent(
event);
287 if (points.
size() > 0)
294 Layer* layer = mEditor->layers()->currentLayer();
298 if (properties.bezier_state)
306 tempPath.
lineTo(endPoint);
309 if ((properties.closedPolylinePath == !mClosedPathOverrideEnabled) && points.
size() > 1)
315 if (layer->type() == Layer::VECTOR)
317 if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR)
319 if (mScribbleArea->makeInvisible() ==
true)
326 pen.setWidth(properties.width);
331 mScribbleArea->drawPolyline(tempPath, pen, properties.useAA);
336void PolylineTool::cancelPolyline()
343 Layer* layer = mEditor->layers()->currentLayer();
345 if (layer->type() == Layer::VECTOR)
348 if (mScribbleArea->makeInvisible() ==
true)
354 curve.setWidth(properties.width);
356 curve.setColorNumber(mEditor->color()->frontColorNumber());
357 curve.setVariableWidth(
false);
358 curve.setInvisibility(mScribbleArea->makeInvisible());
360 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
361 if (vectorImage ==
nullptr) {
return; }
362 vectorImage->
addCurve(curve, mEditor->view()->scaling());
364 if (layer->type() == Layer::BITMAP)
366 drawPolyline(points, points.
last());
369 mScribbleArea->endStroke();
370 mEditor->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame());
QColor frontColor(bool useIndexedColor=true)
frontColor
void updateFrame()
Update frame.
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
void record(const UndoSaveState *&undoState, const QString &description)
Records the given save state.
const UndoSaveState * state(UndoRedoRecordType recordType) const
Prepares and returns a save state with the given scope.
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
virtual bool event(QEvent *e)
void lineTo(const QPointF &endPoint)
This is the main undo/redo state structure which is meant to populate whatever states that needs to b...