24#include "pointerevent.h"
26#include "toolmanager.h"
27#include "strokeinterpolator.h"
28#include "selectionmanager.h"
29#include "overlaymanager.h"
30#include "undoredomanager.h"
31#include "scribblearea.h"
32#include "layervector.h"
33#include "layermanager.h"
34#include "layercamera.h"
36#include "vectorimage.h"
42ToolType MoveTool::type()
47void MoveTool::loadSettings()
49 properties.width = -1;
50 properties.feather = -1;
51 properties.useFeather =
false;
52 properties.stabilizerLevel = -1;
53 properties.useAA = -1;
54 mRotationIncrement = mEditor->preference()->getInt(SETTING::ROTATION_INCREMENT);
56 properties.showSelectionInfo = settings.value(
"ShowSelectionInfo").toBool();
57 mPropertyEnabled[SHOWSELECTIONINFO] =
true;
59 connect(mEditor->preference(), &PreferenceManager::optionChanged,
this, &MoveTool::updateSettings);
64 MoveMode mode = MoveMode::NONE;
66 if (selectMan->somethingSelected())
68 mode = mEditor->select()->getMoveMode();
70 else if (mEditor->overlays()->anyOverlayEnabled())
78void MoveTool::updateSettings(
const SETTING setting)
82 case SETTING::ROTATION_INCREMENT:
83 mRotationIncrement = mEditor->preference()->getInt(SETTING::ROTATION_INCREMENT);
85 case SETTING::OVERLAY_PERSPECTIVE1:
86 mEditor->overlays()->settingsUpdated(setting, mEditor->preference()->isOn(setting));
88 case SETTING::OVERLAY_PERSPECTIVE2:
89 mEditor->overlays()->settingsUpdated(setting, mEditor->preference()->isOn(setting));
91 case SETTING::OVERLAY_PERSPECTIVE3:
92 mEditor->overlays()->settingsUpdated(setting, mEditor->preference()->isOn(setting));
101 Layer* currentLayer = currentPaintableLayer();
102 if (currentLayer ==
nullptr)
return;
104 if (mEditor->select()->somethingSelected())
106 beginInteraction(
event->canvasPos(),
event->modifiers(), currentLayer);
108 else if (mEditor->overlays()->anyOverlayEnabled())
110 LayerCamera* layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex());
113 mPerspMode = mEditor->overlays()->getMoveModeForPoint(
event->canvasPos(), layerCam->getViewAtFrame(mEditor->currentFrame()));
114 mEditor->overlays()->setMoveMode(mPerspMode);
115 QPoint mapped = layerCam->getViewAtFrame(mEditor->currentFrame()).
map(
event->canvasPos()).toPoint();
116 mEditor->overlays()->updatePerspective(mapped);
124 Layer* currentLayer = currentPaintableLayer();
125 if (currentLayer ==
nullptr)
return;
127 if (mScribbleArea->isPointerInUse())
129 transformSelection(
event->canvasPos(),
event->modifiers());
131 if (mEditor->overlays()->anyOverlayEnabled())
133 LayerCamera* layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex());
135 mEditor->overlays()->updatePerspective(layerCam->getViewAtFrame(mEditor->currentFrame()).
map(
event->canvasPos()));
137 if (mEditor->select()->somethingSelected())
139 transformSelection(
event->canvasPos(),
event->modifiers());
146 mEditor->select()->setMoveModeForAnchorInRange(
event->canvasPos());
147 if (mEditor->overlays()->anyOverlayEnabled())
149 LayerCamera *layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex());
151 mPerspMode = mEditor->overlays()->getMoveModeForPoint(
event->canvasPos(), layerCam->getViewAtFrame(mEditor->currentFrame()));
153 mScribbleArea->updateToolCursor();
155 if (currentLayer->type() == Layer::VECTOR)
165 mEditor->undoRedo()->
record(mUndoSaveState, typeName());
167 if (mEditor->overlays()->anyOverlayEnabled())
169 mEditor->overlays()->setMoveMode(MoveMode::NONE);
170 mPerspMode = MoveMode::NONE;
173 auto selectMan = mEditor->select();
174 if (!selectMan->somethingSelected())
177 mScribbleArea->updateToolCursor();
183 auto selectMan = mEditor->select();
184 if (selectMan->somethingSelected())
186 int rotationIncrement = 0;
187 if (selectMan->getMoveMode() == MoveMode::ROTATION && keyMod &
Qt::ShiftModifier)
189 rotationIncrement = mRotationIncrement;
196 if (selectMan->getMoveMode() == MoveMode::ROTATION) {
197 QPointF anchorPoint = selectMan->currentTransformAnchor();
198 newAngle = selectMan->angleFromPoint(pos, anchorPoint) - mRotatedAngle;
201 selectMan->adjustSelection(pos, mOffset, newAngle, rotationIncrement);
205 selectMan->setMoveMode(MoveMode::NONE);
211 auto selectMan = mEditor->select();
212 QRectF selectionRect = selectMan->mySelectionRect();
213 if (!selectionRect.
isNull())
215 mUndoSaveState = mEditor->undoRedo()->
state(UndoRedoRecordType::KEYFRAME_MODIFY);
216 mEditor->backup(typeName());
221 if (selectMan->isOutsideSelectionArea(pos))
223 applyTransformation();
224 mEditor->deselectAll();
228 if (selectMan->getMoveMode() == MoveMode::MIDDLE)
232 selectMan->setMoveMode(MoveMode::ROTATION);
236 if (layer->type() == Layer::VECTOR)
241 selectMan->setTransformAnchor(selectMan->getSelectionAnchorPoint());
243 mOffset = selectMan->myTranslation();
245 if(selectMan->getMoveMode() == MoveMode::ROTATION) {
246 mRotatedAngle = selectMan->angleFromPoint(pos, selectMan->currentTransformAnchor()) - selectMan->myRotation();
257 assert(layer->type() == Layer::VECTOR);
259 VectorImage* vectorImage = vecLayer->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
260 if (vectorImage ==
nullptr) {
return; }
262 if (!mEditor->select()->closestCurves().
empty())
264 setCurveSelected(vectorImage, keyMod);
268 setAreaSelected(pos, vectorImage, keyMod);
274 auto selectMan = mEditor->select();
275 if (!vectorImage->
isSelected(selectMan->closestCurves()))
279 applyTransformation();
281 vectorImage->
setSelected(selectMan->closestCurves(),
true);
282 selectMan->setSelection(vectorImage->getSelectionRect(),
false);
293 applyTransformation();
296 mEditor->select()->setSelection(vectorImage->getSelectionRect(),
false);
306 auto selectMan = mEditor->select();
307 auto layerVector =
static_cast<LayerVector*
>(layer);
308 VectorImage* pVecImg = layerVector->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
309 if (pVecImg ==
nullptr) {
return; }
310 selectMan->setCurves(pVecImg->
getCurvesCloseTo(pos, selectMan->selectionTolerance()));
313void MoveTool::applyTransformation()
316 mScribbleArea->applyTransformedSelection();
320 selectMan->setSelection(selectMan->mapToSelection(
QPolygonF(selectMan->mySelectionRect())).boundingRect());
328 if (currentPaintableLayer())
330 applyTransformation();
336 return mScribbleArea->isPointerInUse() &&
337 (mEditor->select()->somethingSelected() || mEditor->overlays()->getMoveMode() != MoveMode::NONE);
340void MoveTool::resetToDefault()
342 setShowSelectionInfo(
false);
345void MoveTool::setShowSelectionInfo(
const bool b)
347 properties.showSelectionInfo = b;
350 settings.setValue(
"ShowSelectionInfo", b);
354Layer* MoveTool::currentPaintableLayer()
356 Layer* layer = mEditor->layers()->currentLayer();
357 if (layer ==
nullptr)
359 if (!layer->isPaintable())
364QCursor MoveTool::cursor(MoveMode mode)
const
369 QPainter cursorPainter(&cursorPixmap);
374 case MoveMode::PERSP_LEFT:
375 case MoveMode::PERSP_RIGHT:
376 case MoveMode::PERSP_MIDDLE:
377 case MoveMode::PERSP_SINGLE:
379 cursorPainter.drawImage(
QPoint(6,6),
QImage(
"://icons/general/cursor-move.svg"));
382 case MoveMode::TOPLEFT:
383 case MoveMode::BOTTOMRIGHT:
385 cursorPainter.drawImage(
QPoint(6,6),
QImage(
"://icons/general/cursor-diagonal-left.svg"));
388 case MoveMode::TOPRIGHT:
389 case MoveMode::BOTTOMLEFT:
391 cursorPainter.drawImage(
QPoint(6,6),
QImage(
"://icons/general/cursor-diagonal-right.svg"));
394 case MoveMode::ROTATIONLEFT:
395 case MoveMode::ROTATIONRIGHT:
396 case MoveMode::ROTATION:
398 cursorPainter.drawImage(
QPoint(6,6),
QImage(
"://icons/general/cursor-rotate.svg"));
401 case MoveMode::MIDDLE:
402 case MoveMode::CENTER:
404 cursorPainter.drawImage(
QPoint(6,6),
QImage(
"://icons/general/cursor-move.svg"));
void frameModified(int frameNumber)
This should be emitted after modifying the frame content.
void updateFrame()
Will call update() and update the canvas Only call this directly If you need the cache to be intact a...
void setDragOrigin(const QPointF point)
The point from where the dragging will be based of inside the selection area.
void alignPositionToAxis(bool state)
Locks movement either horizontally or vertically depending on drag direction.
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.
bool isAreaSelected(int areaNumber)
VectorImage::isAreaSelected.
void setSelected(int curveNumber, bool YesOrNo)
VectorImage::setSelected.
int getLastAreaNumber(QPointF point)
VectorImage::getLastAreaNumber.
void setAreaSelected(int areaNumber, bool YesOrNo)
VectorImage::setAreaSelected.
bool isSelected(int curveNumber)
VectorImage::isSelected.
QList< int > getCurvesCloseTo(QPointF thisPoint, qreal maxDistance)
VectorImage::getCurvesCloseTo.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual bool event(QEvent *e)
void fill(const QColor &color)
bool isNull() const const
typedef KeyboardModifiers