Commit 9efd1d13 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Show selection outline when moving with move-selection-stroke

That might be a bit more logical for people not expecting move selection
to trigger when they try to move after paste.

CCBUG:407160
parent 0ffed8a5
......@@ -426,7 +426,7 @@ void KisToolMove::paint(QPainter& gc, const KoViewConverter &converter)
{
Q_UNUSED(converter);
if (m_strokeId && !m_handlesRect.isEmpty()) {
if (m_strokeId && !m_handlesRect.isEmpty() && !m_currentlyUsingSelection) {
QPainterPath handles;
handles.addRect(m_handlesRect.translated(currentOffset()));
......@@ -533,6 +533,13 @@ void KisToolMove::startAction(KoPointerEvent *event, MoveToolMode mode)
if (startStrokeImpl(mode, &pos)) {
setMode(KisTool::PAINT_MODE);
if (m_currentlyUsingSelection) {
KisImageSP image = currentImage();
image->addJob(m_strokeId,
new MoveSelectionStrokeStrategy::ShowSelectionData(false));
}
} else {
event->ignore();
m_dragPos = QPoint();
......@@ -572,6 +579,12 @@ void KisToolMove::endAction(KoPointerEvent *event)
m_dragPos = QPoint();
commitChanges();
if (m_currentlyUsingSelection) {
KisImageSP image = currentImage();
image->addJob(m_strokeId,
new MoveSelectionStrokeStrategy::ShowSelectionData(true));
}
notifyGuiAfterMove();
qobject_cast<KisCanvas2*>(canvas())->updateCanvas();
......@@ -579,7 +592,7 @@ void KisToolMove::endAction(KoPointerEvent *event)
void KisToolMove::drag(const QPoint& newPos)
{
KisImageWSP image = currentImage();
KisImageSP image = currentImage();
QPoint offset = m_accumulatedOffset + newPos - m_dragStart;
......
......@@ -86,8 +86,7 @@ void MoveSelectionStrokeStrategy::initStrokeCallback()
indirect->setTemporaryChannelFlags(QBitArray());
m_initialDeviceOffset = QPoint(movedDevice->x(), movedDevice->y());
m_selection->setVisible(false);
m_initialSelectionOffset = QPoint(m_selection->x(), m_selection->y());
{
QRect handlesRect = movedDevice->exactBounds();
......@@ -117,12 +116,12 @@ void MoveSelectionStrokeStrategy::finishStrokeCallback()
indirect->setTemporaryTarget(0);
QPoint selectionOffset(m_selection->x(), m_selection->y());
m_updatesFacade->blockUpdates();
KUndo2CommandSP moveSelectionCommand(
new KisSelectionMoveCommand2(m_selection, selectionOffset, selectionOffset + m_finalOffset));
new KisSelectionMoveCommand2(m_selection,
m_initialSelectionOffset,
m_initialSelectionOffset + m_finalOffset));
runAndSaveCommand(
moveSelectionCommand,
......@@ -148,9 +147,12 @@ void MoveSelectionStrokeStrategy::cancelStrokeCallback()
indirect->setTemporaryTarget(0);
m_selection->setVisible(true);
m_paintLayer->setDirty(dirtyRegion);
m_selection->setX(m_initialSelectionOffset.x());
m_selection->setY(m_initialSelectionOffset.y());
m_selection->setVisible(true);
m_selection->notifySelectionChanged();
}
}
KisStrokeStrategyUndoCommandBased::cancelStrokeCallback();
......@@ -161,6 +163,7 @@ void MoveSelectionStrokeStrategy::cancelStrokeCallback()
void MoveSelectionStrokeStrategy::doStrokeCallback(KisStrokeJobData *data)
{
MoveStrokeStrategy::Data *d = dynamic_cast<MoveStrokeStrategy::Data*>(data);
ShowSelectionData *ssd = dynamic_cast<ShowSelectionData*>(data);
if (d) {
KisIndirectPaintingSupport *indirect =
......@@ -180,6 +183,16 @@ void MoveSelectionStrokeStrategy::doStrokeCallback(KisStrokeJobData *data)
m_finalOffset = d->offset;
m_paintLayer->setDirty(KisRegion::fromQRegion(dirtyRegion));
m_selection->setX((m_initialSelectionOffset + d->offset).x());
m_selection->setY((m_initialSelectionOffset + d->offset).y());
if (m_selection->isVisible()) {
m_selection->notifySelectionChanged();
}
} else if (ssd) {
m_selection->setVisible(ssd->showSelection);
} else {
KisStrokeStrategyUndoCommandBased::doStrokeCallback(data);
}
......
......@@ -32,6 +32,17 @@ class MoveSelectionStrokeStrategy : public QObject, public KisStrokeStrategyUndo
{
Q_OBJECT
public:
struct ShowSelectionData : public KisStrokeJobData
{
ShowSelectionData(bool _showSelection)
: KisStrokeJobData(),
showSelection(_showSelection)
{}
bool showSelection = false;
};
public:
MoveSelectionStrokeStrategy(KisPaintLayerSP paintLayer,
KisSelectionSP selection,
......@@ -58,6 +69,7 @@ private:
KisUpdatesFacade *m_updatesFacade;
QPoint m_finalOffset;
QPoint m_initialDeviceOffset;
QPoint m_initialSelectionOffset;
};
#endif /* __MOVE_SELECTION_STROKE_STRATEGY_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment