21 #include <QMessageBox>
23 #include "pointerevent.h"
25 #include "toolmanager.h"
26 #include "viewmanager.h"
27 #include "strokemanager.h"
28 #include "selectionmanager.h"
29 #include "scribblearea.h"
30 #include "layervector.h"
31 #include "layermanager.h"
32 #include "mathutils.h"
33 #include "vectorimage.h"
40 ToolType MoveTool::type()
45 void MoveTool::loadSettings()
47 properties.width = -1;
48 properties.feather = -1;
49 properties.useFeather =
false;
50 properties.stabilizerLevel = -1;
51 properties.useAA = -1;
52 mRotationIncrement = mEditor->preference()->getInt(SETTING::ROTATION_INCREMENT);
54 connect(mEditor->preference(), &PreferenceManager::optionChanged,
this, &MoveTool::updateSettings);
59 MoveMode mode = mEditor->select()->getMoveModeForSelectionAnchor(getCurrentPoint());
60 return mScribbleArea->currentTool()->selectMoveCursor(mode, type());
63 void MoveTool::updateSettings(
const SETTING setting)
67 case SETTING::ROTATION_INCREMENT:
69 mRotationIncrement = mEditor->preference()->getInt(SETTING::ROTATION_INCREMENT);
80 mCurrentLayer = currentPaintableLayer();
81 if (mCurrentLayer ==
nullptr)
return;
83 mEditor->select()->updatePolygons();
85 setAnchorToLastPoint();
86 beginInteraction(event->
modifiers(), mCurrentLayer);
91 mCurrentLayer = currentPaintableLayer();
92 if (mCurrentLayer ==
nullptr)
return;
94 mEditor->select()->updatePolygons();
96 if (mScribbleArea->isPointerInUse())
98 transformSelection(event->
modifiers(), mCurrentLayer);
104 mScribbleArea->updateToolCursor();
106 if (mCurrentLayer->type() == Layer::VECTOR)
111 mScribbleArea->updateCurrentFrame();
116 auto selectMan = mEditor->select();
117 if (!selectMan->somethingSelected())
120 mRotatedAngle = selectMan->myRotation();
121 updateTransformation();
123 Layer* layer = mEditor->layers()->currentLayer();
124 if (layer->type() == Layer::VECTOR) {
125 applyTransformation();
128 selectMan->updatePolygons();
130 mScribbleArea->updateToolCursor();
131 mScribbleArea->updateCurrentFrame();
134 void MoveTool::updateTransformation()
136 auto selectMan = mEditor->select();
137 selectMan->updateTransformedSelection();
140 selectMan->calculateSelectionTransformation();
143 paintTransformedSelection();
148 auto selectMan = mEditor->select();
149 if (selectMan->somethingSelected())
152 QPointF offset = offsetFromPressPos();
157 offset = selectMan->offsetFromAspectRatio(offset.
x(), offset.
y());
160 int rotationIncrement = 0;
161 if (selectMan->getMoveMode() == MoveMode::ROTATION && keyMod &
Qt::ShiftModifier)
163 rotationIncrement = mRotationIncrement;
166 if(layer->type() == Layer::BITMAP)
171 selectMan->adjustSelection(getCurrentPoint(), offset.
x(), offset.
y(), mRotatedAngle, rotationIncrement);
173 selectMan->calculateSelectionTransformation();
174 paintTransformedSelection();
179 selectMan->setMoveMode(MoveMode::NONE);
185 auto selectMan = mEditor->select();
186 QRectF selectionRect = selectMan->myTransformedSelectionRect();
187 if (!selectionRect.
isNull())
189 mEditor->backup(typeName());
194 if (selectMan->isOutsideSelectionArea(getCurrentPoint()))
196 applyTransformation();
197 mEditor->deselectAll();
201 if (selectMan->validateMoveMode(getLastPoint()) == MoveMode::MIDDLE)
205 selectMan->setMoveMode(MoveMode::ROTATION);
209 if (layer->type() == Layer::VECTOR)
214 if(selectMan->getMoveMode() == MoveMode::ROTATION) {
215 QPointF curPoint = getCurrentPoint();
217 mRotatedAngle = qRadiansToDegrees(MathUtils::getDifferenceAngle(anchorPoint, curPoint)) - selectMan->myRotation();
228 assert(layer->type() == Layer::VECTOR);
230 VectorImage* vectorImage = vecLayer->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
231 if (vectorImage ==
nullptr) {
return; }
233 if (!mEditor->select()->closestCurves().
empty())
235 setCurveSelected(vectorImage, keyMod);
239 setAreaSelected(vectorImage, keyMod);
246 auto selectMan = mEditor->select();
247 if (!vectorImage->
isSelected(selectMan->closestCurves()))
251 applyTransformation();
253 vectorImage->
setSelected(selectMan->closestCurves(),
true);
254 selectMan->setSelection(vectorImage->getSelectionRect(),
false);
265 applyTransformation();
268 mEditor->select()->setSelection(vectorImage->getSelectionRect(),
false);
278 auto selectMan = mEditor->select();
279 auto layerVector =
static_cast<LayerVector*
>(layer);
280 VectorImage* pVecImg = layerVector->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
281 if (pVecImg ==
nullptr) {
return; }
282 selectMan->setCurves(pVecImg->
getCurvesCloseTo(getCurrentPoint(), selectMan->selectionTolerance()));
285 void MoveTool::setAnchorToLastPoint()
287 anchorOriginPoint = getLastPoint();
290 void MoveTool::cancelChanges()
292 auto selectMan = mEditor->select();
293 mScribbleArea->cancelTransformedSelection();
294 selectMan->resetSelectionProperties();
295 mEditor->deselectAll();
298 void MoveTool::applySelectionChanges()
300 mEditor->select()->setRotation(0);
303 mScribbleArea->applySelectionChanges();
306 void MoveTool::applyTransformation()
308 mScribbleArea->applyTransformedSelection();
311 void MoveTool::paintTransformedSelection()
313 mScribbleArea->paintTransformedSelection();
316 bool MoveTool::leavingThisTool()
320 switch (mCurrentLayer->type())
322 case Layer::BITMAP: applySelectionChanges();
break;
323 case Layer::VECTOR: applyTransformation();
break;
330 bool MoveTool::switchingLayer()
332 auto selectMan = mEditor->select();
333 if (!selectMan->transformHasBeenModified())
335 mEditor->deselectAll();
339 int returnValue = showTransformWarning();
343 if (mCurrentLayer->type() == Layer::BITMAP)
345 applySelectionChanges();
347 else if (mCurrentLayer->type() == Layer::VECTOR)
349 applyTransformation();
352 mEditor->deselectAll();
367 int MoveTool::showTransformWarning()
370 tr(
"Layer switch",
"Windows title of layer switch pop-up."),
371 tr(
"You are about to switch away, do you want to apply the transformation?"),
377 Layer* MoveTool::currentPaintableLayer()
379 Layer* layer = mEditor->layers()->currentLayer();
380 if (layer ==
nullptr)
382 if (!layer->isPaintable())
387 QPointF MoveTool::offsetFromPressPos()
389 return getCurrentPoint() - getCurrentPressPoint();
typedef KeyboardModifiers
Qt::KeyboardModifiers modifiers() const
Returns the modifier created by keyboard while a device was in use.
int getLastAreaNumber(QPointF point)
VectorImage::getLastAreaNumber.
QList< int > getCurvesCloseTo(QPointF thisPoint, qreal maxDistance)
VectorImage::getCurvesCloseTo.
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isSelected(int curveNumber)
VectorImage::isSelected.
QPointF center() const const
bool isNull() const const
bool isAreaSelected(int areaNumber)
VectorImage::isAreaSelected.
QPoint toPoint() const const
void setAreaSelected(int areaNumber, bool YesOrNo)
VectorImage::setAreaSelected.
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setSelected(int curveNumber, bool YesOrNo)
VectorImage::setSelected.