Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Selection-Move-Content-v2

Ricky Ringler2088c592932c
diff --git a/libs/flake/KoToolBase.h b/libs/flake/KoToolBase.h
index d5e664404d..b2b38aa87d 100644
--- a/libs/flake/KoToolBase.h
+++ b/libs/flake/KoToolBase.h
@@ -164,7 +164,7 @@ public:
/**
* @brief explicitUserStrokeEndRequest is called by the input manager
- * when the user presses Enter key or any equivalent. This callback
+ * when the user presses the Enter key or any equivalent key. This callback
* comes before requestStrokeEnd(), which comes from a different source.
*/
virtual void explicitUserStrokeEndRequest();
@@ -362,8 +362,8 @@ public Q_SLOTS:
/**
* Called when the user requested undo while the stroke is
- * active. If you tool supports undo of the part of its actions,
- * override this method and do the needed work there.
+ * active. If your tool supports undoing, override this method
+ * and implement the desired effects there.
*
* NOTE: Default implementation forwards this request to
* requestStrokeCancellation() method, so that the stroke
@@ -379,16 +379,16 @@ public Q_SLOTS:
virtual void requestRedoDuringStroke();
/**
- * Called when the user requested the cancellation of the current
- * stroke. If you tool supports cancelling, override this method
- * and do the needed work there
+ * Called when the user requests cancellation of the current
+ * stroke. If your tool supports cancelling, override this method
+ * and implement the desired effects there.
*/
virtual void requestStrokeCancellation();
/**
* Called when the image decided that the stroke should better be
- * ended. If you tool supports long strokes, override this method
- * and do the needed work there
+ * ended. If your tool supports long strokes, override this method
+ * and implement the desired effects there.
*/
virtual void requestStrokeEnd();
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index 621c09f718..b132cb8828 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -231,6 +231,7 @@ set(kritaui_LIB_SRCS
tool/strokes/KisMaskingBrushRenderer.cpp
tool/strokes/KisMaskingBrushCompositeOpFactory.cpp
tool/strokes/move_stroke_strategy.cpp
+ tool/strokes/move_selection_stroke_strategy.cpp
tool/strokes/KisNodeSelectionRecipe.cpp
tool/KisSelectionToolFactoryBase.cpp
tool/KisToolPaintFactoryBase.cpp
diff --git a/libs/ui/kis_selection_decoration.cc b/libs/ui/kis_selection_decoration.cc
index c104d9673b..747b01fb40 100644
--- a/libs/ui/kis_selection_decoration.cc
+++ b/libs/ui/kis_selection_decoration.cc
@@ -142,7 +142,6 @@ void KisSelectionDecoration::selectionChanged()
view()->canvasBase()->updateCanvas();
}
-
m_selectionActionsPanel->setVisible(true);
} else {
m_signalCompressor.start();
@@ -205,7 +204,7 @@ void KisSelectionDecoration::toggleSelectionVisibility() {
m_selectionVisibility = !m_selectionVisibility;
}
-bool KisSelectionDecoration::selectionVisible() {
+bool KisSelectionDecoration::selectionVisible() const {
return m_selectionVisibility;
}
diff --git a/libs/ui/kis_selection_decoration.h b/libs/ui/kis_selection_decoration.h
index eb40c86d3f..bb0cd1c318 100644
--- a/libs/ui/kis_selection_decoration.h
+++ b/libs/ui/kis_selection_decoration.h
@@ -40,7 +40,7 @@ public:
void setCanvasWidget(KisCanvasWidgetBase* canvas) override;
void toggleSelectionVisibility();
- bool selectionVisible();
+ bool selectionVisible() const;
protected:
void drawDecoration(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter *converter,KisCanvas2* canvas) override;
diff --git a/libs/ui/tests/CMakeLists.txt b/libs/ui/tests/CMakeLists.txt
index 15d97f61c6..753ae9c65a 100644
--- a/libs/ui/tests/CMakeLists.txt
+++ b/libs/ui/tests/CMakeLists.txt
@@ -119,6 +119,10 @@ kis_add_test(
LINK_LIBRARIES kritaui kritalibkis kritatestsdk
)
+kis_add_test(move_selection_stroke_test.cpp ../../../sdk/tests/stroke_testing_utils.cpp
+ TEST_NAME MoveSelectionStrokeTest
+ LINK_LIBRARIES kritadefaulttools_static kritabasicflakes kritaui kritatestsdk
+)
##### Tests that currently fail and should be fixed #####
diff --git a/plugins/tools/basictools/tests/move_selection_stroke_test.cpp b/libs/ui/tests/move_selection_stroke_test.cpp
similarity index 100%
rename from plugins/tools/basictools/tests/move_selection_stroke_test.cpp
rename to libs/ui/tests/move_selection_stroke_test.cpp
diff --git a/plugins/tools/basictools/tests/move_selection_stroke_test.h b/libs/ui/tests/move_selection_stroke_test.h
similarity index 100%
rename from plugins/tools/basictools/tests/move_selection_stroke_test.h
rename to libs/ui/tests/move_selection_stroke_test.h
diff --git a/libs/ui/tool/kis_selection_tool_config_widget_helper.cpp b/libs/ui/tool/kis_selection_tool_config_widget_helper.cpp
index 97eaf13559..f33714815a 100644
--- a/libs/ui/tool/kis_selection_tool_config_widget_helper.cpp
+++ b/libs/ui/tool/kis_selection_tool_config_widget_helper.cpp
@@ -34,6 +34,10 @@ void KisSelectionToolConfigWidgetHelper::createOptionWidget(
&KisSelectionOptions::actionChanged,
this,
&KisSelectionToolConfigWidgetHelper::slotWidgetActionChanged);
+ connect(m_optionsWidget,
+ &KisSelectionOptions::moveSelectedContentChanged,
+ this,
+ &KisSelectionToolConfigWidgetHelper::slotWidgetMoveSelectedContentChanged);
connect(m_optionsWidget, &KisSelectionOptions::antiAliasSelectionChanged,
this, &KisSelectionToolConfigWidgetHelper::slotWidgetAntiAliasChanged);
connect(m_optionsWidget,
@@ -77,6 +81,14 @@ SelectionAction KisSelectionToolConfigWidgetHelper::selectionAction() const
return m_optionsWidget->action();
}
+bool KisSelectionToolConfigWidgetHelper::moveSelectedContent() const
+{
+ if (!m_optionsWidget) {
+ return true;
+ }
+ return m_optionsWidget->moveSelectedContent();
+}
+
bool KisSelectionToolConfigWidgetHelper::antiAliasSelection() const
{
if (!m_optionsWidget) {
@@ -148,6 +160,12 @@ void KisSelectionToolConfigWidgetHelper::slotWidgetActionChanged(
Q_EMIT selectionActionChanged(action);
}
+void KisSelectionToolConfigWidgetHelper::slotWidgetMoveSelectedContentChanged(bool value)
+{
+ KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
+ cfg.writeEntry("moveSelectedContent", value);
+}
+
void KisSelectionToolConfigWidgetHelper::slotWidgetAntiAliasChanged(bool value)
{
KConfigGroup cfg = KSharedConfig::openConfig()->group(m_configGroupForTool);
@@ -272,6 +290,8 @@ void KisSelectionToolConfigWidgetHelper::reloadExactToolConfig()
KConfigGroup cfgToolSpecific =
KSharedConfig::openConfig()->group(m_configGroupForTool);
+ const bool moveSelectedContent =
+ cfgToolSpecific.readEntry("moveSelectedContent", false);
const bool antiAliasSelection =
cfgToolSpecific.readEntry("antiAliasSelection", true);
const int growSelection = cfgToolSpecific.readEntry("growSelection", 0);
@@ -311,6 +331,7 @@ void KisSelectionToolConfigWidgetHelper::reloadExactToolConfig()
}
KisSignalsBlocker b(m_optionsWidget);
+ m_optionsWidget->setMoveSelectedContent(moveSelectedContent);
m_optionsWidget->setAntiAliasSelection(antiAliasSelection);
m_optionsWidget->setGrowSelection(growSelection);
m_optionsWidget->setStopGrowingAtDarkestPixel(stopGrowingAtDarkestPixel);
diff --git a/libs/ui/tool/kis_selection_tool_config_widget_helper.h b/libs/ui/tool/kis_selection_tool_config_widget_helper.h
index b41eaac9ce..2783211d84 100644
--- a/libs/ui/tool/kis_selection_tool_config_widget_helper.h
+++ b/libs/ui/tool/kis_selection_tool_config_widget_helper.h
@@ -29,6 +29,7 @@ public:
SelectionMode selectionMode() const;
SelectionAction selectionAction() const;
+ bool moveSelectedContent() const;
bool antiAliasSelection() const;
int growSelection() const;
bool stopGrowingAtDarkestPixel() const;
@@ -48,6 +49,7 @@ public Q_SLOTS:
void slotWidgetModeChanged(SelectionMode mode);
void slotWidgetActionChanged(SelectionAction action);
+ void slotWidgetMoveSelectedContentChanged(bool value);
void slotWidgetAntiAliasChanged(bool value);
void slotWidgetGrowChanged(int value);
void slotWidgetStopGrowingAtDarkestPixelChanged(bool value);
diff --git a/libs/ui/tool/kis_tool_select_base.h b/libs/ui/tool/kis_tool_select_base.h
index 085799291e..8dfe0f66d8 100644
--- a/libs/ui/tool/kis_tool_select_base.h
+++ b/libs/ui/tool/kis_tool_select_base.h
@@ -1,6 +1,7 @@
/* This file is part of the KDE project
* SPDX-FileCopyrightText: 2009 Boudewijn Rempt <[email protected]>
* SPDX-FileCopyrightText: 2015 Michael Abrahams <[email protected]>
+ * SPDX-FileCopyrightText: 2025 Ricky Ringler <[email protected]>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
@@ -18,6 +19,7 @@
#include "kis_selection_manager.h"
#include "kis_selection_modifier_mapper.h"
#include "strokes/move_stroke_strategy.h"
+#include "strokes/move_selection_stroke_strategy.h"
#include "kis_image.h"
#include "kis_cursor.h"
#include "kis_action_manager.h"
@@ -29,6 +31,17 @@
/**
* This is a basic template to create selection tools from basic path based drawing tools.
+ *
+ * The temmplate implements two principal modes of interaction: the "move selection" interaction and the "move content"
+ * interaction.
+ *
+ * The move selection interaction is a series of actions. The user can create a selection region and move the region, as
+ * well as apply manipulations to the region, like inversion.
+ *
+ * The move content interaction is a single series of actions, infinitely looping until the user explicitly terminates
+ * the interaction by pressing a key or switching tools. This allows for rapidly selecting and moving pixels across the
+ * canvas, but avoids creating numerous transactions each time the user finishes clicking on the canvas.
+ *
* The template overrides the ability to execute alternate actions correctly.
* The default behavior for the modifier keys is as follows:
*
@@ -54,7 +67,7 @@
* 3) Once the user finishes selecting, the selection method is updated to reflect
* the current modifier combination
*
- * 4) If the user is moving the selection, then changing the modifiers
+ * 4) If the user is moving the selection, then changes the modifiers
*/
template <class BaseClass>
@@ -87,6 +100,14 @@ public:
KisSelectionModifierMapper::instance();
}
+ enum CursorHit
+ {
+ CursorHit_None,
+ CursorHit_Border,
+ CursorHit_Inside,
+ CursorHit_Outside
+ };
+
enum SampleLayersMode
{
SampleAllLayers,
@@ -148,6 +169,7 @@ public:
void deactivate() override
{
+ commitMoveSelectionStroke();
BaseClass::deactivate();
m_modeConnections.clear();
}
@@ -191,6 +213,11 @@ public:
return alternateSelectionAction();
}
+ bool moveSelectedContent() const
+ {
+ return m_widgetHelper.moveSelectedContent();
+ }
+
bool antiAliasSelection() const
{
return m_widgetHelper.antiAliasSelection();
@@ -281,6 +308,44 @@ public:
endPrimaryAction(event);
}
+ void explicitUserStrokeEndRequest() override
+ {
+ commitMoveSelectionStroke();
+ }
+
+ void requestStrokeCancellation() override
+ {
+ cancelMoveSelectionStroke();
+ }
+
+ void requestStrokeEnd() override
+ {
+ commitMoveSelectionStroke();
+ }
+
+ void cancelMoveSelectionStroke() {
+ commitMoveSelectionStrokeImpl(true);
+ }
+
+ void commitMoveSelectionStroke() {
+ commitMoveSelectionStrokeImpl(false);
+ }
+
+ void commitMoveSelectionStrokeImpl(bool cancel) {
+ if (m_moveStrokeId && isMovingContent()) {
+ if (!cancel) {
+ this->image()->endStroke(m_moveStrokeId);
+ } else {
+ this->image()->cancelStroke(m_moveStrokeId);
+ }
+ m_moveStrokeId.clear();
+ m_accumulatedOffset = QPoint();
+ m_dragStartOffset = QPoint();
+ this->endMoveContentInteraction();
+ return;
+ }
+ }
+
KisNodeSP locateSelectionMaskUnderCursor(const QPointF &pos, Qt::KeyboardModifiers modifiers) {
if (modifiers != Qt::NoModifier) return 0;
@@ -310,6 +375,12 @@ public:
void keyPressEvent(QKeyEvent *event) override
{
+ /* Moving content is one, continuous stroke. Attempting to manipulate
+ * anything mid-stroke wouldn't make sense. */
+ if (isMovingContent()) {
+ return;
+ }
+
const Qt::Key key = KisExtendedModifiersMapper::workaroundShiftAltMetaHell(event);
// Assume all the modifiers were unpressed...
m_currentModifiers = Qt::NoModifier;
@@ -323,18 +394,15 @@ public:
if (key == Qt::Key_Alt || event->modifiers().testFlag(Qt::AltModifier)) {
m_currentModifiers.setFlag(Qt::AltModifier);
}
-
- // Avoid changing the selection mode and cursor if the user is interacting
+
+ // Avoid changing the cursor if the user is interacting
if (isSelecting()) {
BaseClass::keyPressEvent(event);
return;
}
- if (isMovingSelection()) {
- return;
- }
setAlternateSelectionAction(KisSelectionModifierMapper::map(m_currentModifiers));
- this->resetCursorStyle();
+ updateCursor();
}
void keyReleaseEvent(QKeyEvent *event) override
@@ -364,13 +432,9 @@ public:
setAlternateSelectionAction(KisSelectionModifierMapper::map(m_currentModifiers));
if (m_currentModifiers == Qt::NoModifier) {
- KisNodeSP selectionMask = locateSelectionMaskUnderCursor(m_currentPos, m_currentModifiers);
- if (selectionMask) {
- this->useCursor(KisCursor::moveSelectionCursor());
- } else {
- this->resetCursorStyle();
- }
- } else {
+ updateCursor();
+ }
+ else {
this->resetCursorStyle();
}
}
@@ -378,45 +442,115 @@ public:
void mouseMoveEvent(KoPointerEvent *event) override
{
m_currentPos = this->convertToPixelCoord(event->point);
+ m_currentModifiers = event->modifiers();
+ if (disabledMoveContentWhileMovingContent()) {
+ /* User disabled option while actively moving content? Commit and end */
+ commitMoveSelectionStroke();
+ }
+
+ updateCursor();
+ BaseClass::mouseMoveEvent(event);
+ }
+
+ CursorHit checkCursorHit(const QPointF &pos, Qt::KeyboardModifiers modifiers) const
+ {
+ /* User still drawing selection? Then there's really nothing to "hit" per se */
if (isSelecting()) {
- BaseClass::mouseMoveEvent(event);
- return;
+ return CursorHit_None;
}
- if (isMovingSelection()) {
- return;
+
+ KisCanvas2 *canvas = dynamic_cast<KisCanvas2*>(this->canvas());
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas, CursorHit_Outside);
+ KisSelectionSP selection = canvas->viewManager()->selection();
+
+ if (!selection || !selection->outlineCacheValid()) {
+ return CursorHit_Outside;
}
- KisNodeSP selectionMask = locateSelectionMaskUnderCursor(m_currentPos, event->modifiers());
- if (selectionMask) {
- this->useCursor(KisCursor::moveSelectionCursor());
- } else {
- setAlternateSelectionAction(KisSelectionModifierMapper::map(m_currentModifiers));
- this->resetCursorStyle();
+ const QPainterPath selectionPath = selection->outlineCache();
+
+ if (modifiers == Qt::NoModifier) {
+ const qreal handleRadius = qreal(this->handleRadius()) / canvas->coordinatesConverter()->effectiveZoom();
+
+ QPainterPath samplePath;
+ samplePath.addEllipse(pos, handleRadius, handleRadius);
+
+ if (selectionPath.intersects(samplePath) && !selectionPath.contains(samplePath)) {
+ return CursorHit_Border;
+ }
+ }
+
+ if (selectionPath.contains(pos)) {
+ return CursorHit_Inside;
}
+
+ return CursorHit_Outside;
}
- void beginPrimaryAction(KoPointerEvent *event) override
+ inline bool canBeginNewAction(KoPointerEvent *event, const QPointF &pos, CursorHit hit)
{
+ /* Prevent interrupting while selecting a region */
if (isSelecting()) {
BaseClass::beginPrimaryAction(event);
- return;
+ return false;
}
- if (isMovingSelection()) {
- return;
+
+ /* Prevent interrupting while moving */
+ if (isMovingContent()) {
+ /* We must update the offsets here, so the offset is sane later */
+ m_dragStartPos = pos;
+ m_dragStartOffset = m_accumulatedOffset;
+ /* User clicked outside? Commit changes and start a new stroke */
+ /* This eliminates extra keystrokes to start a new transaction */
+ if (hit == CursorHit_Outside) {
+ commitMoveSelectionStroke();
+ BaseClass::beginPrimaryAction(event);
+ return false;
+ }
}
+ return true;
+ }
+
+ void beginPrimaryAction(KoPointerEvent *event) override
+ {
const QPointF pos = this->convertToPixelCoord(event->point);
+ const CursorHit hit = checkCursorHit(pos, event->modifiers());
+
+ if (!canBeginNewAction(event, pos, hit)) {
+ return;
+ }
+
KisCanvas2* canvas = dynamic_cast<KisCanvas2*>(this->canvas());
KIS_SAFE_ASSERT_RECOVER_RETURN(canvas);
+ if (hit == CursorHit_Inside && this->moveSelectedContent()) {
+ KisSelectionSP selection = canvas->viewManager()->selection();
+ KisPaintLayerSP layer = dynamic_cast<KisPaintLayer*>(this->currentNode().data());
+ if (this->beginMoveContentInteraction() && selection && layer) {
+ KisStrokeStrategy *strategy =
+ new MoveSelectionStrokeStrategy(layer, selection, this->image().data(), this->image().data());
+ initializeStrokeAttributes(pos, strategy, true);
+ updateCursor();
+ }
+ return;
+ }
+
+ if (m_currentInteraction == Interaction_MoveContent &&
+ (hit == CursorHit_Inside || hit == CursorHit_Border)) {
+ // we shouldn't pass the control to the parent tool
+ // when we have the already started the move content action
+ return;
+ }
+
KisNodeSP selectionMask = locateSelectionMaskUnderCursor(pos, event->modifiers());
if (selectionMask) {
if (this->beginMoveSelectionInteraction()) {
- KisStrokeStrategy *strategy = new MoveStrokeStrategy({selectionMask}, this->image().data(), this->image().data());
- m_moveStrokeId = this->image()->startStroke(strategy);
- m_dragStartPos = pos;
- m_didMove = true;
+ KisStrokeStrategy *strategy =
+ new MoveStrokeStrategy({selectionMask}, this->image().data(), this->image().data());
+ initializeStrokeAttributes(pos, strategy, true);
+ updateCursor();
return;
}
}
@@ -427,19 +561,26 @@ public:
void continuePrimaryAction(KoPointerEvent *event) override
{
- if (isMovingSelection()) {
+ if (isMovingSelection() || isMovingContent()) {
const QPointF pos = this->convertToPixelCoord(event->point);
- const QPoint offset((pos - m_dragStartPos).toPoint());
-
+ const QPoint delta = (pos - m_dragStartPos).toPoint();
+ const QPoint offset = m_dragStartOffset + delta;
+ m_accumulatedOffset = offset;
this->image()->addJob(m_moveStrokeId, new MoveStrokeStrategy::Data(offset));
return;
- }
+ }
BaseClass::continuePrimaryAction(event);
}
void endPrimaryAction(KoPointerEvent *event) override
{
+ if (isMovingContent()) {
+ const QPointF pos = this->convertToPixelCoord(event->point);
+ const QPoint delta = (pos - m_dragStartPos).toPoint();
+ m_accumulatedOffset = m_dragStartOffset + delta;
+ return;
+ }
if (isMovingSelection()) {
this->image()->endStroke(m_moveStrokeId);
m_moveStrokeId.clear();
@@ -475,6 +616,14 @@ public:
return nullptr;
}
+ inline void initializeStrokeAttributes(const QPointF &pos, KisStrokeStrategy *strategy, bool moved) {
+ m_moveStrokeId = this->image()->startStroke(strategy);
+ m_dragStartPos = pos;
+ m_didMove = moved;
+ m_accumulatedOffset = QPoint();
+ m_dragStartOffset = QPoint();
+ }
+
bool beginMoveSelectionInteraction() {
if (m_currentInteraction != Interaction_None) {
return false;
@@ -492,6 +641,23 @@ public:
return true;
}
+ bool beginMoveContentInteraction() {
+ if (m_currentInteraction != Interaction_None) {
+ return false;
+ }
+ m_currentInteraction = Interaction_MoveContent;
+ return true;
+ }
+
+ bool endMoveContentInteraction() {
+ if (!isMovingContent()) {
+ return false;
+ }
+ m_currentInteraction = Interaction_None;
+ updateCursorDelayed();
+ return true;
+ }
+
bool beginSelectInteraction() {
if (m_currentInteraction != Interaction_None) {
return false;
@@ -513,22 +679,89 @@ public:
return m_currentInteraction == Interaction_MoveSelection;
}
+ bool isMovingContent() const {
+ return m_currentInteraction == Interaction_MoveContent;
+ }
+
bool isSelecting() const {
return m_currentInteraction == Interaction_Select;
}
+ bool disabledMoveContentWhileMovingContent() const {
+ /* User could disable the option in the middle of an action */
+ return isMovingContent() && !moveSelectedContent();
+ }
+
+ void updateCursor()
+ {
+
+ const Interaction interaction = currentInteraction();
+ const CursorHit hit = checkCursorHit(m_currentPos, m_currentModifiers);
+
+ switch (interaction)
+ {
+ case Interaction_MoveContent:
+ switch (hit)
+ {
+ case CursorHit_Border:
+ this->useCursor(KisCursor::moveCursor());
+ break;
+ case CursorHit_Inside:
+ this->useCursor(KisCursor::moveCursor());
+ break;
+ case CursorHit_Outside:
+ this->resetCursorStyle();
+ break;
+ case CursorHit_None:
+ default:
+ this->resetCursorStyle();
+ break;
+ }
+ break;
+ case Interaction_MoveSelection:
+ switch (hit)
+ {
+ case CursorHit_Border:
+ this->useCursor(KisCursor::moveSelectionCursor());
+ break;
+ case CursorHit_Inside:
+ this->resetCursorStyle();
+ break;
+ case CursorHit_Outside:
+ this->resetCursorStyle();
+ break;
+ case CursorHit_None:
+ default:
+ this->resetCursorStyle();
+ break;
+ }
+ break;
+ case Interaction_Select:
+ this->resetCursorStyle();
+ break;
+ case Interaction_None:
+ if (hit == CursorHit_Border){
+ this->useCursor(KisCursor::moveSelectionCursor());
+ }
+ else if (hit == CursorHit_Inside && this->moveSelectedContent()) {
+ this->useCursor(KisCursor::moveCursor());
+ } else {
+ this->resetCursorStyle();
+ }
+ break;
+ default:
+ this->resetCursorStyle();
+ break;
+ }
+ }
+
void updateCursorDelayed() {
setAlternateSelectionAction(KisSelectionModifierMapper::map(m_currentModifiers));
QTimer::singleShot(100, Qt::CoarseTimer,
this,
[this]()
{
- KisNodeSP selectionMask = locateSelectionMaskUnderCursor(m_currentPos, m_currentModifiers);
- if (selectionMask) {
- this->useCursor(KisCursor::moveSelectionCursor());
- } else {
- this->resetCursorStyle();
- }
+ updateCursor();
}
);
}
@@ -551,15 +784,22 @@ private:
{
Interaction_None,
Interaction_Select,
- Interaction_MoveSelection
+ Interaction_MoveSelection,
+ Interaction_MoveContent
};
Interaction m_currentInteraction{Interaction_None};
+ Interaction currentInteraction() const {
+ return m_currentInteraction;
+ }
+
Qt::KeyboardModifiers m_currentModifiers;
QPointF m_dragStartPos;
QPointF m_currentPos;
+ QPoint m_accumulatedOffset;
+ QPoint m_dragStartOffset;
KisStrokeId m_moveStrokeId;
bool m_didMove = false;
diff --git a/plugins/tools/basictools/strokes/move_selection_stroke_strategy.cpp b/libs/ui/tool/strokes/move_selection_stroke_strategy.cpp
similarity index 98%
rename from plugins/tools/basictools/strokes/move_selection_stroke_strategy.cpp
rename to libs/ui/tool/strokes/move_selection_stroke_strategy.cpp
index 754295906e..3af9a032f7 100644
--- a/plugins/tools/basictools/strokes/move_selection_stroke_strategy.cpp
+++ b/libs/ui/tool/strokes/move_selection_stroke_strategy.cpp
@@ -36,7 +36,7 @@ MoveSelectionStrokeStrategy::MoveSelectionStrokeStrategy(KisPaintLayerSP paintLa
* all of them are completed before we start our stroke.
*/
enableJob(KisSimpleStrokeStrategy::JOB_INIT, true, KisStrokeJobData::BARRIER);
- enableJob(KisSimpleStrokeStrategy::JOB_FINISH);
+ enableJob(KisSimpleStrokeStrategy::JOB_FINISH, true, KisStrokeJobData::BARRIER);
enableJob(KisSimpleStrokeStrategy::JOB_CANCEL);
}
diff --git a/plugins/tools/basictools/strokes/move_selection_stroke_strategy.h b/libs/ui/tool/strokes/move_selection_stroke_strategy.h
similarity index 89%
rename from plugins/tools/basictools/strokes/move_selection_stroke_strategy.h
rename to libs/ui/tool/strokes/move_selection_stroke_strategy.h
index 178d715788..de2dd61279 100644
--- a/plugins/tools/basictools/strokes/move_selection_stroke_strategy.h
+++ b/libs/ui/tool/strokes/move_selection_stroke_strategy.h
@@ -7,6 +7,7 @@
#ifndef __MOVE_SELECTION_STROKE_STRATEGY_H
#define __MOVE_SELECTION_STROKE_STRATEGY_H
+#include "kritaui_export.h"
#include "kis_stroke_strategy_undo_command_based.h"
#include "kis_types.h"
#include "kis_selection.h"
@@ -16,12 +17,12 @@ class KisPostExecutionUndoAdapter;
class KisUpdatesFacade;
-class MoveSelectionStrokeStrategy : public QObject, public KisStrokeStrategyUndoCommandBased
+class KRITAUI_EXPORT MoveSelectionStrokeStrategy : public QObject, public KisStrokeStrategyUndoCommandBased
{
Q_OBJECT
public:
- struct ShowSelectionData : public KisStrokeJobData
+ struct KRITAUI_EXPORT ShowSelectionData : public KisStrokeJobData
{
ShowSelectionData(bool _showSelection)
: KisStrokeJobData(),
diff --git a/libs/ui/widgets/kis_selection_options.cc b/libs/ui/widgets/kis_selection_options.cc
index a9b0b6d255..8f52dbe3eb 100644
--- a/libs/ui/widgets/kis_selection_options.cc
+++ b/libs/ui/widgets/kis_selection_options.cc
@@ -28,6 +28,7 @@ public:
KisSelectionOptions *q;
KisOptionButtonStrip *optionButtonStripMode{nullptr};
KisOptionButtonStrip *optionButtonStripAction{nullptr};
+ QCheckBox *checkBoxMoveSelectedContent{nullptr};
QCheckBox *checkBoxAntiAliasSelection{nullptr};
KisSliderSpinBox *sliderGrowSelection{nullptr};
QToolButton *buttonStopGrowingAtDarkestPixel {nullptr};
@@ -188,6 +189,10 @@ KisSelectionOptions::KisSelectionOptions(QWidget *parent)
m_d->checkBoxSelectionActionsPanel->setCheckState(Qt::CheckState::Unchecked);
}
+ m_d->checkBoxMoveSelectedContent = new QCheckBox(
+ i18nc("The move-selected-content checkbox in selection tool options",
+ "Move Selected Content"));
+
m_d->checkBoxAntiAliasSelection = new QCheckBox(
i18nc("The anti-alias checkbox in fill tool options", "Anti-aliasing"));
KisOptionCollectionWidget *containerGrowSelection = new KisOptionCollectionWidget;
@@ -246,6 +251,9 @@ KisSelectionOptions::KisSelectionOptions(QWidget *parent)
m_d->optionButtonStripAction->button(4)->setToolTip(
i18nc("@info:tooltip", "Symmetric Difference"));
+ m_d->checkBoxMoveSelectedContent->setToolTip(
+ i18nc("@info:tooltip", "Move Selected Content"));
+
m_d->checkBoxAntiAliasSelection->setToolTip(
i18n("Smooths the edges of the selection"));
m_d->sliderGrowSelection->setToolTip(
@@ -292,6 +300,8 @@ KisSelectionOptions::KisSelectionOptions(QWidget *parent)
appendWidget("sapCheckBox", m_d->checkBoxSelectionActionsPanel);
+ appendWidget("checkBoxMoveSelectedContent", m_d->checkBoxMoveSelectedContent);
+
KisOptionCollectionWidgetWithHeader *sectionAdjustments =
new KisOptionCollectionWidgetWithHeader(
i18nc("The 'adjustments' section label in selection tools options",
@@ -317,6 +327,9 @@ KisSelectionOptions::KisSelectionOptions(QWidget *parent)
[this](int i, int c) {
m_d->on_optionButtonStripAction_buttonToggled(i, c);
});
+ connect(m_d->checkBoxMoveSelectedContent,
+ SIGNAL(toggled(bool)),
+ SIGNAL(moveSelectedContentChanged(bool)));
connect(m_d->checkBoxAntiAliasSelection,
SIGNAL(toggled(bool)),
SIGNAL(antiAliasSelectionChanged(bool)));
@@ -361,6 +374,11 @@ SelectionAction KisSelectionOptions::action() const
m_d->optionButtonStripAction->checkedButtonIndex());
}
+bool KisSelectionOptions::moveSelectedContent() const
+{
+ return m_d->checkBoxMoveSelectedContent->isChecked();
+}
+
bool KisSelectionOptions::antiAliasSelection() const
{
return m_d->checkBoxAntiAliasSelection->isChecked();
@@ -411,6 +429,11 @@ void KisSelectionOptions::setAction(SelectionAction newAction)
button->setChecked(true);
}
+void KisSelectionOptions::setMoveSelectedContent(bool newMoveSelectedContent)
+{
+ m_d->checkBoxMoveSelectedContent->setChecked(newMoveSelectedContent);
+}
+
void KisSelectionOptions::setAntiAliasSelection(bool newAntiAliasSelection)
{
m_d->checkBoxAntiAliasSelection->setChecked(newAntiAliasSelection);
diff --git a/libs/ui/widgets/kis_selection_options.h b/libs/ui/widgets/kis_selection_options.h
index 53163a49ea..e73e49fe47 100644
--- a/libs/ui/widgets/kis_selection_options.h
+++ b/libs/ui/widgets/kis_selection_options.h
@@ -26,6 +26,7 @@ public:
SelectionMode mode() const;
SelectionAction action() const;
+ bool moveSelectedContent() const;
bool antiAliasSelection() const;
int growSelection() const;
bool stopGrowingAtDarkestPixel() const;
@@ -35,6 +36,7 @@ public:
void setMode(SelectionMode newMode);
void setAction(SelectionAction newAction);
+ void setMoveSelectedContent(bool newMoveSelectedContent);
void setAntiAliasSelection(bool newAntiAliasSelection);
void setGrowSelection(int newGrowSelection);
void setStopGrowingAtDarkestPixel(bool newStopGrowingAtDarkestPixel);
@@ -54,6 +56,7 @@ public:
Q_SIGNALS:
void modeChanged(SelectionMode mode);
void actionChanged(SelectionAction action);
+ void moveSelectedContentChanged(bool moveSelectedContent);
void antiAliasSelectionChanged(bool antiAliasSelection);
void growSelectionChanged(int growSelection);
void stopGrowingAtDarkestPixelChanged(bool stopGrowingAtDarkestPixel);
diff --git a/plugins/tools/basictools/CMakeLists.txt b/plugins/tools/basictools/CMakeLists.txt
index 733a0488cf..b639f29ae4 100644
--- a/plugins/tools/basictools/CMakeLists.txt
+++ b/plugins/tools/basictools/CMakeLists.txt
@@ -13,7 +13,6 @@ set(kritadefaulttools_static_SRCS
kis_tool_path.cc
kis_tool_move.cc
kis_tool_movetooloptionswidget.cpp
- strokes/move_selection_stroke_strategy.cpp
KisMoveBoundsCalculationJob.cpp
kis_tool_multihand.cpp
kis_tool_multihand_config.cpp
diff --git a/plugins/tools/basictools/tests/CMakeLists.txt b/plugins/tools/basictools/tests/CMakeLists.txt
index 56c8f6d842..edc404dcff 100644
--- a/plugins/tools/basictools/tests/CMakeLists.txt
+++ b/plugins/tools/basictools/tests/CMakeLists.txt
@@ -3,11 +3,4 @@
krita_add_broken_unit_test(move_stroke_test.cpp $<TARGET_PROPERTY:kritatestsdk,SOURCE_DIR>/stroke_testing_utils.cpp
TEST_NAME MoveStrokeTest
LINK_LIBRARIES kritadefaulttools_static kritabasicflakes kritaui kritatestsdk
- )
-
-########### next target ###############
-
-kis_add_test(move_selection_stroke_test.cpp $<TARGET_PROPERTY:kritatestsdk,SOURCE_DIR>/stroke_testing_utils.cpp ../strokes/move_selection_stroke_strategy.cpp
- TEST_NAME MoveSelectionStrokeTest
- LINK_LIBRARIES kritadefaulttools_static kritabasicflakes kritaui kritatestsdk
- )
+ )
\ No newline at end of file