17#include "selecttool.h"
19#include "pointerevent.h"
20#include "vectorimage.h"
22#include "layervector.h"
23#include "scribblearea.h"
24#include "layermanager.h"
25#include "toolmanager.h"
26#include "selectionmanager.h"
27#include "undoredomanager.h"
33void SelectTool::loadSettings()
35 properties.width = -1;
36 properties.feather = -1;
37 properties.stabilizerLevel = -1;
38 properties.useAA = -1;
40 properties.showSelectionInfo = settings.value(
"ShowSelectionInfo").toBool();
41 mPropertyEnabled[SHOWSELECTIONINFO] =
true;
47 if (mScribbleArea->isPointerInUse()) {
return QCursor(mCursorPixmap); }
49 MoveMode mode = mEditor->select()->getMoveMode();
52 QPainter cursorPainter(&mCursorPixmap);
57 case MoveMode::TOPLEFT:
58 case MoveMode::BOTTOMRIGHT:
60 cursorPainter.drawPixmap(
QPoint(6,6),
QPixmap(
"://icons/general/cursor-diagonal-left.svg"));
63 case MoveMode::TOPRIGHT:
64 case MoveMode::BOTTOMLEFT:
66 cursorPainter.drawPixmap(
QPoint(6,6),
QPixmap(
"://icons/general/cursor-diagonal-right.svg"));
69 case MoveMode::MIDDLE:
71 cursorPainter.drawPixmap(
QPoint(6,6),
QPixmap(
"://icons/general/cursor-move.svg"));
75 cursorPainter.drawPixmap(
QPoint(3,3),
QPixmap(
":icons/general/cross.png"));
84void SelectTool::resetToDefault()
86 setShowSelectionInfo(
false);
89void SelectTool::setShowSelectionInfo(
const bool b)
91 properties.showSelectionInfo = b;
94 settings.setValue(
"ShowSelectionInfo", b);
97void SelectTool::beginSelection(
Layer* currentLayer,
const QPointF& pos)
99 auto selectMan = mEditor->select();
101 if (selectMan->somethingSelected() && mMoveMode != MoveMode::NONE)
103 if (currentLayer->type() == Layer::VECTOR)
105 VectorImage* vectorImage =
static_cast<LayerVector*
>(currentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
106 if (vectorImage !=
nullptr) {
110 mSelectionRect = mEditor->select()->mapToSelection(mEditor->select()->mySelectionRect()).boundingRect();
114 selectMan->setSelection(
QRectF(pos.
x(), pos.
y(), 1, 1), mEditor->layers()->currentLayer()->type() == Layer::BITMAP);
115 mAnchorOriginPoint = pos;
123 Layer* currentLayer = mEditor->layers()->currentLayer();
124 if (currentLayer ==
nullptr)
return;
125 if (!currentLayer->isPaintable()) {
return; }
127 auto selectMan = mEditor->select();
129 mUndoState = mEditor->undoRedo()->
state(UndoRedoRecordType::KEYFRAME_MODIFY);
131 mPressPoint =
event->canvasPos();
132 selectMan->setMoveModeForAnchorInRange(mPressPoint);
133 mMoveMode = selectMan->getMoveMode();
134 mStartMoveMode = mMoveMode;
136 beginSelection(currentLayer, mPressPoint);
141 Layer* currentLayer = mEditor->layers()->currentLayer();
142 if (currentLayer ==
nullptr) {
return; }
143 if (!currentLayer->isPaintable()) {
return; }
144 auto selectMan = mEditor->select();
146 if (!selectMan->somethingSelected()) {
return; }
148 selectMan->setMoveModeForAnchorInRange(
event->canvasPos());
149 mMoveMode = selectMan->getMoveMode();
150 mScribbleArea->updateToolCursor();
152 if (mScribbleArea->isPointerInUse())
154 controlOffsetOrigin(
event->canvasPos(), mAnchorOriginPoint);
156 if (currentLayer->type() == Layer::VECTOR)
158 VectorImage* vectorImage =
static_cast<LayerVector*
>(currentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
159 if (vectorImage !=
nullptr) {
160 vectorImage->select(selectMan->mapToSelection(
QPolygonF(selectMan->mySelectionRect())).boundingRect());
168void SelectTool::pointerReleaseEvent(
PointerEvent* event)
170 Layer* currentLayer = mEditor->layers()->currentLayer();
171 if (currentLayer ==
nullptr)
return;
179 mEditor->deselectAll();
181 if (maybeDeselect(
event->canvasPos()))
183 mEditor->deselectAll();
190 mEditor->undoRedo()->
record(mUndoState, typeName());
192 mStartMoveMode = MoveMode::NONE;
193 mSelectionRect = mEditor->select()->mapToSelection(mEditor->select()->mySelectionRect()).boundingRect();
195 mScribbleArea->updateToolCursor();
199bool SelectTool::maybeDeselect(
const QPointF& pos)
201 return (!isSelectionPointValid(pos) && mEditor->select()->getMoveMode() == MoveMode::NONE);
210 if (currentLayer->type() == Layer::VECTOR)
212 VectorImage* vectorImage =
static_cast<LayerVector*
>(currentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
213 if (vectorImage ==
nullptr) {
return; }
214 auto selectMan = mEditor->select();
215 selectMan->setSelection(vectorImage->getSelectionRect(),
false);
219void SelectTool::controlOffsetOrigin(
QPointF currentPoint,
QPointF anchorPoint)
222 if (mStartMoveMode != MoveMode::NONE) {
223 QRectF rect = mSelectionRect;
225 QPointF offset = offsetFromPressPos(currentPoint);
226 if (mStartMoveMode == MoveMode::TOPLEFT) {
227 rect.
adjust(offset.
x(), offset.
y(), 0, 0);
228 }
else if (mStartMoveMode == MoveMode::TOPRIGHT) {
229 rect.
adjust(0, offset.
y(), offset.
x(), 0);
230 }
else if (mStartMoveMode == MoveMode::BOTTOMRIGHT) {
231 rect.
adjust(0, 0, offset.
x(), offset.
y());
232 }
else if (mStartMoveMode == MoveMode::BOTTOMLEFT) {
233 rect.
adjust(offset.
x(), 0, 0, offset.
y());
240 mEditor->select()->setSelection(rect,
true);
253 qreal mouseX = currentPoint.
x();
254 qreal mouseY = currentPoint.
y();
256 QRectF selectRect = mSelectionRect;
258 if (mouseX <= originPoint.
x())
265 selectRect.
setLeft(originPoint.
x());
269 if (mouseY <= originPoint.
y())
271 selectRect.
setTop(mouseY);
276 selectRect.
setTop(originPoint.
y());
280 if (selectRect.
width() <= 0) {
283 if (selectRect.
height() <= 0) {
287 editor()->select()->setSelection(selectRect);
290bool SelectTool::keyPressEvent(
QKeyEvent* event)
292 switch (
event->key())
305 return BaseTool::keyPressEvent(
event);
310 return pos - mPressPoint;
void updateFrame()
Update frame.
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.
qreal length() const const
virtual bool event(QEvent *e)
void fill(const QColor &color)
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
qreal height() const const
bool isValid() const const
QRectF normalized() const const
void setHeight(qreal height)
void setWidth(qreal width)
void translate(qreal dx, qreal dy)
qreal width() const const