17 #include "selecttool.h"
18 #include "pointerevent.h"
19 #include "vectorimage.h"
21 #include "strokemanager.h"
22 #include "layervector.h"
23 #include "scribblearea.h"
24 #include "layermanager.h"
25 #include "toolmanager.h"
26 #include "selectionmanager.h"
32 void SelectTool::loadSettings()
34 properties.width = -1;
35 properties.feather = -1;
36 properties.stabilizerLevel = -1;
37 properties.useAA = -1;
42 MoveMode mode = mEditor->select()->getMoveModeForSelectionAnchor(getCurrentPoint());
43 return this->selectMoveCursor(mode, type());
46 void SelectTool::beginSelection()
49 mAnchorOriginPoint = getLastPoint();
51 auto selectMan = mEditor->select();
52 selectMan->calculateSelectionTransformation();
55 mScribbleArea->paintTransformedSelection();
56 mScribbleArea->applyTransformedSelection();
57 mMoveMode = selectMan->validateMoveMode(getLastPoint());
59 if (selectMan->somethingSelected() && mMoveMode != MoveMode::NONE)
61 if (mCurrentLayer->type() == Layer::VECTOR)
63 VectorImage* vectorImage =
static_cast<LayerVector*
>(mCurrentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
64 if (vectorImage !=
nullptr) {
69 mAnchorOriginPoint = selectMan->whichAnchorPoint(getLastPoint());
73 selectMan->setSelection(
QRectF(getCurrentPoint().x(), getCurrentPoint().y(), 1, 1), mEditor->layers()->currentLayer()->type() == Layer::BITMAP);
80 mCurrentLayer = mEditor->layers()->currentLayer();
81 if (mCurrentLayer ==
nullptr)
return;
82 if (!mCurrentLayer->isPaintable()) {
return; }
84 auto selectMan = mEditor->select();
86 mMoveMode = selectMan->validateMoveMode(getCurrentPoint());
88 selectMan->updatePolygons();
95 mCurrentLayer = mEditor->layers()->currentLayer();
96 if (mCurrentLayer ==
nullptr) {
return; }
97 if (!mCurrentLayer->isPaintable()) {
return; }
98 auto selectMan = mEditor->select();
100 if (!selectMan->somethingSelected()) {
return; }
102 selectMan->updatePolygons();
104 mScribbleArea->updateToolCursor();
106 if (mScribbleArea->isPointerInUse())
108 controlOffsetOrigin(getCurrentPoint(), mAnchorOriginPoint);
110 if (mCurrentLayer->type() == Layer::VECTOR)
112 VectorImage* vectorImage =
static_cast<LayerVector*
>(mCurrentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
113 if (vectorImage !=
nullptr) {
114 vectorImage->select(selectMan->myTempTransformedSelectionRect());
119 mScribbleArea->updateCurrentFrame();
122 void SelectTool::pointerReleaseEvent(
PointerEvent* event)
124 mCurrentLayer = mEditor->layers()->currentLayer();
125 if (mCurrentLayer ==
nullptr)
return;
127 auto selectMan = mEditor->select();
132 if (
QLineF(mAnchorOriginPoint, getCurrentPoint()).length() < 5.0)
134 mEditor->deselectAll();
138 mEditor->deselectAll();
145 selectMan->updatePolygons();
147 mScribbleArea->updateToolCursor();
148 mScribbleArea->updateCurrentFrame();
152 bool SelectTool::maybeDeselect()
154 return (!isSelectionPointValid() && mEditor->select()->validateMoveMode(getLastPoint()) == MoveMode::NONE);
163 auto selectMan = mEditor->select();
164 if (mCurrentLayer->type() == Layer::BITMAP) {
165 if (!selectMan->myTempTransformedSelectionRect().isValid())
167 selectMan->setSelection(selectMan->myTempTransformedSelectionRect().normalized(),
true);
171 selectMan->setSelection(selectMan->myTempTransformedSelectionRect(),
true);
174 else if (mCurrentLayer->type() == Layer::VECTOR)
176 VectorImage* vectorImage =
static_cast<LayerVector*
>(mCurrentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
177 if (vectorImage ==
nullptr) {
return; }
178 selectMan->setSelection(vectorImage->getSelectionRect(),
false);
182 void SelectTool::controlOffsetOrigin(
QPointF currentPoint,
QPointF anchorPoint)
184 QPointF offset = offsetFromPressPos();
186 if (mMoveMode != MoveMode::NONE)
188 if (editor()->layers()->currentLayer()->type() == Layer::BITMAP) {
192 auto selectMan = mEditor->select();
194 selectMan->adjustSelection(getCurrentPoint(), offset.
x(), offset.
y(), selectMan->myRotation(), 0);
209 qreal mouseX = currentPoint.
x();
210 qreal mouseY = currentPoint.
y();
214 if (mouseX <= originPoint.
x())
221 selectRect.
setLeft(originPoint.
x());
225 if (mouseY <= originPoint.
y())
227 selectRect.
setTop(mouseY);
232 selectRect.
setTop(originPoint.
y());
236 mEditor->select()->setTempTransformedSelectionRect(selectRect);
239 bool SelectTool::keyPressEvent(
QKeyEvent* event)
241 switch (event->
key())
244 mScribbleArea->setTemporaryTool(MOVE);
254 QPointF SelectTool::offsetFromPressPos()
256 return getCurrentPoint() - getCurrentPressPoint();
void deselectAll()
VectorImage::deselectAll.
QPoint toPoint() const const
Qt::MouseButton button() const
Returns Qt::MouseButton()