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()
219 if (mPoints.
size() > 1)
222 drawPolyline(mPoints, getCurrentPoint());
224 else if (mPoints.
size() == 1)
231bool PolylineTool::keyPressEvent(
QKeyEvent* event)
233 switch (
event->key())
236 mClosedPathOverrideEnabled =
true;
237 drawPolyline(mPoints, getCurrentPoint());
242 if (mPoints.
size() > 0)
244 const UndoSaveState* saveState = mEditor->undoRedo()->
state(UndoRedoRecordType::KEYFRAME_MODIFY);
245 endPolyline(mPoints);
246 mEditor->undoRedo()->
record(saveState, typeName());
251 if (mPoints.
size() > 0)
253 removeLastPolylineSegment();
257 if (mPoints.
size() > 0)
268 return BaseTool::keyPressEvent(
event);
271bool PolylineTool::keyReleaseEvent(
QKeyEvent* event)
273 switch (
event->key())
276 mClosedPathOverrideEnabled =
false;
277 drawPolyline(mPoints, getCurrentPoint());
285 return BaseTool::keyReleaseEvent(
event);
290 if (points.
size() > 0)
297 Layer* layer = mEditor->layers()->currentLayer();
301 if (properties.bezier_state)
309 tempPath.
lineTo(endPoint);
312 if ((properties.closedPolylinePath == !mClosedPathOverrideEnabled) && points.
size() > 1)
318 if (layer->type() == Layer::VECTOR)
320 if (mEditor->layers()->currentLayer()->type() == Layer::VECTOR)
322 if (mScribbleArea->makeInvisible() ==
true)
329 pen.setWidth(properties.width);
334 mScribbleArea->drawPolyline(tempPath, pen, properties.useAA);
339void PolylineTool::cancelPolyline()
346 Layer* layer = mEditor->layers()->currentLayer();
348 if (layer->type() == Layer::VECTOR)
351 if (mScribbleArea->makeInvisible() ==
true)
357 curve.setWidth(properties.width);
359 curve.setColorNumber(mEditor->color()->frontColorNumber());
360 curve.setVariableWidth(
false);
361 curve.setInvisibility(mScribbleArea->makeInvisible());
363 VectorImage* vectorImage =
static_cast<LayerVector*
>(layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
364 if (vectorImage ==
nullptr) {
return; }
365 vectorImage->
addCurve(curve, mEditor->view()->scaling());
367 if (layer->type() == Layer::BITMAP)
369 drawPolyline(points, points.
last());
372 mScribbleArea->endStroke();
373 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...