From 150b25366716a9d033e115aa732250f17924f6e6 Mon Sep 17 00:00:00 2001 From: shieldgenerator7 Date: Fri, 6 Oct 2023 05:06:14 -0400 Subject: [PATCH] #1792 Auto-switch to the Move tool --- app/src/toolbox.cpp | 15 +++++++++++++++ app/src/toolbox.h | 1 + core_lib/src/tool/selecttool.cpp | 9 +++++++++ core_lib/src/tool/selecttool.h | 3 +++ 4 files changed, 28 insertions(+) diff --git a/app/src/toolbox.cpp b/app/src/toolbox.cpp index 790deb524..cebe4973b 100644 --- a/app/src/toolbox.cpp +++ b/app/src/toolbox.cpp @@ -31,6 +31,8 @@ GNU General Public License for more details. #include "toolmanager.h" #include "layermanager.h" #include "pencilsettings.h" +#include "selectionmanager.h" +#include "selecttool.h" // ---------------------------------------------------------------------------------- QString GetToolTips(QString strCommandName) @@ -137,6 +139,8 @@ void ToolBoxWidget::initUI() connect(editor()->layers(), &LayerManager::currentLayerChanged, this, &ToolBoxWidget::onLayerDidChange); + //switch to move tool when selection changes + connect(editor()->select(), &SelectionManager::selectionChanged, this, &ToolBoxWidget::onSelectionChanged); FlowLayout* flowlayout = new FlowLayout; @@ -304,3 +308,14 @@ void ToolBoxWidget::onLayerDidChange(int) moveOn(); } } + +void ToolBoxWidget::onSelectionChanged(){ + BaseTool* currentTool = editor()->tools()->currentTool(); + if (currentTool->type() == SELECT) + { + if (!((SelectTool)currentTool).selectChanging()) + { + moveOn(); + } + } +} diff --git a/app/src/toolbox.h b/app/src/toolbox.h index ef081bf56..cb39428cb 100644 --- a/app/src/toolbox.h +++ b/app/src/toolbox.h @@ -46,6 +46,7 @@ class ToolBoxWidget : public BaseDockWidget public slots: void onToolSetActive(ToolType toolType); void onLayerDidChange(int index); + void onSelectionChanged(); void pencilOn(); void eraserOn(); void selectOn(); diff --git a/core_lib/src/tool/selecttool.cpp b/core_lib/src/tool/selecttool.cpp index 52d57fa68..914eb7851 100644 --- a/core_lib/src/tool/selecttool.cpp +++ b/core_lib/src/tool/selecttool.cpp @@ -95,6 +95,11 @@ void SelectTool::setShowSelectionInfo(const bool b) settings.setValue("ShowSelectionInfo", b); } +bool SelectTool::selectChanging() +{ + return mSelectChanging; +} + void SelectTool::beginSelection() { auto selectMan = mEditor->select(); @@ -121,6 +126,8 @@ void SelectTool::beginSelection() void SelectTool::pointerPressEvent(PointerEvent* event) { + mSelectChanging = true; + mCurrentLayer = mEditor->layers()->currentLayer(); if (mCurrentLayer == nullptr) return; if (!mCurrentLayer->isPaintable()) { return; } @@ -165,6 +172,8 @@ void SelectTool::pointerMoveEvent(PointerEvent*) void SelectTool::pointerReleaseEvent(PointerEvent* event) { + mSelectChanging = false; + mCurrentLayer = mEditor->layers()->currentLayer(); if (mCurrentLayer == nullptr) return; if (event->button() != Qt::LeftButton) return; diff --git a/core_lib/src/tool/selecttool.h b/core_lib/src/tool/selecttool.h index 5383e8193..adc2dc139 100644 --- a/core_lib/src/tool/selecttool.h +++ b/core_lib/src/tool/selecttool.h @@ -39,6 +39,8 @@ class SelectTool : public BaseTool void resetToDefault() override; void setShowSelectionInfo(const bool b) override; + bool selectChanging(); + private: void pointerPressEvent(PointerEvent*) override; @@ -65,6 +67,7 @@ class SelectTool : public BaseTool MoveMode mStartMoveMode = MoveMode::NONE; QRectF mSelectionRect; Layer* mCurrentLayer = nullptr; + bool mSelectChanging = false; QPixmap mCursorPixmap = QPixmap(24, 24); };