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"
32void SelectTool::loadSettings()
34 properties.width = -1;
35 properties.feather = -1;
36 properties.stabilizerLevel = -1;
37 properties.useAA = -1;
39 properties.showSelectionInfo = settings.value(
"ShowSelectionInfo").toBool();
40 mPropertyEnabled[SHOWSELECTIONINFO] =
true;
46 if (mScribbleArea->isPointerInUse()) {
return QCursor(mCursorPixmap); }
48 mEditor->select()->setMoveModeForAnchorInRange(getCurrentPoint());
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)
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(getCurrentPoint().x(), getCurrentPoint().y(), 1, 1), mEditor->layers()->currentLayer()->type() == Layer::BITMAP);
115 mAnchorOriginPoint = getLastPoint();
123 Layer* currentLayer = mEditor->layers()->currentLayer();
124 if (currentLayer ==
nullptr)
return;
125 if (!currentLayer->isPaintable()) {
return; }
127 auto selectMan = mEditor->select();
129 selectMan->setMoveModeForAnchorInRange(getCurrentPoint());
130 mMoveMode = selectMan->getMoveMode();
131 mStartMoveMode = mMoveMode;
133 beginSelection(currentLayer);
138 Layer* currentLayer = mEditor->layers()->currentLayer();
139 if (currentLayer ==
nullptr) {
return; }
140 if (!currentLayer->isPaintable()) {
return; }
141 auto selectMan = mEditor->select();
143 if (!selectMan->somethingSelected()) {
return; }
145 selectMan->setMoveModeForAnchorInRange(getCurrentPoint());
146 mMoveMode = selectMan->getMoveMode();
147 mScribbleArea->updateToolCursor();
149 if (mScribbleArea->isPointerInUse())
151 controlOffsetOrigin(getCurrentPoint(), mAnchorOriginPoint);
153 if (currentLayer->type() == Layer::VECTOR)
155 VectorImage* vectorImage =
static_cast<LayerVector*
>(currentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
156 if (vectorImage !=
nullptr) {
157 vectorImage->select(selectMan->mapToSelection(
QPolygonF(selectMan->mySelectionRect())).boundingRect());
165void SelectTool::pointerReleaseEvent(
PointerEvent* event)
167 Layer* currentLayer = mEditor->layers()->currentLayer();
168 if (currentLayer ==
nullptr)
return;
174 if (
QLineF(mAnchorOriginPoint, getCurrentPoint()).length() < 5.0)
176 mEditor->deselectAll();
180 mEditor->deselectAll();
187 mStartMoveMode = MoveMode::NONE;
188 mSelectionRect = mEditor->select()->mapToSelection(mEditor->select()->mySelectionRect()).boundingRect();
190 mScribbleArea->updateToolCursor();
194bool SelectTool::maybeDeselect()
196 return (!isSelectionPointValid() && mEditor->select()->getMoveMode() == MoveMode::NONE);
205 auto selectMan = mEditor->select();
206 if (currentLayer->type() == Layer::VECTOR)
208 VectorImage* vectorImage =
static_cast<LayerVector*
>(currentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
209 if (vectorImage ==
nullptr) {
return; }
210 selectMan->setSelection(vectorImage->getSelectionRect(),
false);
214void SelectTool::controlOffsetOrigin(
QPointF currentPoint,
QPointF anchorPoint)
217 if (mStartMoveMode != MoveMode::NONE) {
218 QRectF rect = mSelectionRect;
220 QPointF offset = offsetFromPressPos();
221 if (mStartMoveMode == MoveMode::TOPLEFT) {
222 rect.
adjust(offset.
x(), offset.
y(), 0, 0);
223 }
else if (mStartMoveMode == MoveMode::TOPRIGHT) {
224 rect.
adjust(0, offset.
y(), offset.
x(), 0);
225 }
else if (mStartMoveMode == MoveMode::BOTTOMRIGHT) {
226 rect.
adjust(0, 0, offset.
x(), offset.
y());
227 }
else if (mStartMoveMode == MoveMode::BOTTOMLEFT) {
228 rect.
adjust(offset.
x(), 0, 0, offset.
y());
235 mEditor->select()->setSelection(rect,
true);
248 qreal mouseX = currentPoint.
x();
249 qreal mouseY = currentPoint.
y();
251 QRectF selectRect = mSelectionRect;
253 if (mouseX <= originPoint.
x())
260 selectRect.
setLeft(originPoint.
x());
264 if (mouseY <= originPoint.
y())
266 selectRect.
setTop(mouseY);
271 selectRect.
setTop(originPoint.
y());
275 if (selectRect.
width() <= 0) {
278 if (selectRect.
height() <= 0) {
282 editor()->select()->setSelection(selectRect);
285bool SelectTool::keyPressEvent(
QKeyEvent* event)
287 switch (
event->key())
300 return BaseTool::keyPressEvent(
event);
303QPointF SelectTool::offsetFromPressPos()
305 return getCurrentPoint() - getCurrentPressPoint();
void updateFrame()
Update frame.
void deselectAll()
VectorImage::deselectAll.
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