From 150b25366716a9d033e115aa732250f17924f6e6 Mon Sep 17 00:00:00 2001 From: shieldgenerator7 Date: Fri, 6 Oct 2023 05:06:14 -0400 Subject: [PATCH 1/4] #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); }; From 6b9d87622f69f5f552c264ced88f368bc7a28628 Mon Sep 17 00:00:00 2001 From: shieldgenerator7 Date: Fri, 6 Oct 2023 05:26:42 -0400 Subject: [PATCH 2/4] #1792 Fix bugs --- app/src/toolbox.cpp | 3 ++- core_lib/src/tool/selecttool.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/toolbox.cpp b/app/src/toolbox.cpp index cebe4973b..e923896a4 100644 --- a/app/src/toolbox.cpp +++ b/app/src/toolbox.cpp @@ -313,7 +313,8 @@ void ToolBoxWidget::onSelectionChanged(){ BaseTool* currentTool = editor()->tools()->currentTool(); if (currentTool->type() == SELECT) { - if (!((SelectTool)currentTool).selectChanging()) + SelectTool* selectTool = (SelectTool*) currentTool; + if (!selectTool->selectChanging()) { moveOn(); } diff --git a/core_lib/src/tool/selecttool.cpp b/core_lib/src/tool/selecttool.cpp index 914eb7851..78be42526 100644 --- a/core_lib/src/tool/selecttool.cpp +++ b/core_lib/src/tool/selecttool.cpp @@ -196,6 +196,7 @@ void SelectTool::pointerReleaseEvent(PointerEvent* event) mStartMoveMode = MoveMode::NONE; mSelectionRect = mEditor->select()->mapToSelection(mEditor->select()->mySelectionRect()).boundingRect(); + editor()->select()->setSelection(mSelectionRect); mScribbleArea->updateToolCursor(); mScribbleArea->updateFrame(); From 709dc99ce724f68af387baffa07fd2fb977125fd Mon Sep 17 00:00:00 2001 From: shieldgenerator7 Date: Fri, 6 Oct 2023 14:16:23 -0400 Subject: [PATCH 3/4] #1792 Auto-switch requires something to be selected --- app/src/toolbox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/toolbox.cpp b/app/src/toolbox.cpp index e923896a4..9b515f480 100644 --- a/app/src/toolbox.cpp +++ b/app/src/toolbox.cpp @@ -314,7 +314,7 @@ void ToolBoxWidget::onSelectionChanged(){ if (currentTool->type() == SELECT) { SelectTool* selectTool = (SelectTool*) currentTool; - if (!selectTool->selectChanging()) + if (!selectTool->selectChanging() && editor()->select()->somethingSelected()) { moveOn(); } From ef9449db9cb9b913afc39c6d0ababb495ecfc727 Mon Sep 17 00:00:00 2001 From: shieldgenerator7 Date: Fri, 6 Oct 2023 15:07:30 -0400 Subject: [PATCH 4/4] #1792 Add option to toggle autoswitching --- app/src/toolbox.cpp | 9 ++++++--- app/src/tooloptionwidget.cpp | 10 ++++++++++ app/src/tooloptionwidget.h | 1 + app/ui/tooloptions.ui | 10 ++++++++++ core_lib/src/managers/toolmanager.cpp | 5 +++++ core_lib/src/managers/toolmanager.h | 1 + core_lib/src/tool/basetool.cpp | 5 +++++ core_lib/src/tool/basetool.h | 2 ++ core_lib/src/tool/selecttool.cpp | 2 ++ core_lib/src/util/pencildef.h | 1 + 10 files changed, 43 insertions(+), 3 deletions(-) diff --git a/app/src/toolbox.cpp b/app/src/toolbox.cpp index 9b515f480..18c171ff2 100644 --- a/app/src/toolbox.cpp +++ b/app/src/toolbox.cpp @@ -313,10 +313,13 @@ void ToolBoxWidget::onSelectionChanged(){ BaseTool* currentTool = editor()->tools()->currentTool(); if (currentTool->type() == SELECT) { - SelectTool* selectTool = (SelectTool*) currentTool; - if (!selectTool->selectChanging() && editor()->select()->somethingSelected()) + if (editor()->select()->somethingSelected()) { - moveOn(); + SelectTool* selectTool = (SelectTool*) currentTool; + if (selectTool->properties.autoSwitchTool && !selectTool->selectChanging()) + { + moveOn(); + } } } } diff --git a/app/src/tooloptionwidget.cpp b/app/src/tooloptionwidget.cpp index 5c51c4206..e35e8a440 100644 --- a/app/src/tooloptionwidget.cpp +++ b/app/src/tooloptionwidget.cpp @@ -114,6 +114,8 @@ void ToolOptionWidget::makeConnectionToEditor(Editor* editor) connect(ui->fillContourBox, &QCheckBox::clicked, toolManager, &ToolManager::setUseFillContour); + connect(ui->autoSwitchToolCheckBox, &QCheckBox::clicked, toolManager, &ToolManager::setAutoSwitchTool); + connect(ui->showInfoBox, &QCheckBox::clicked, toolManager, &ToolManager::setShowSelectionInfo); connect(toolManager, &ToolManager::toolChanged, this, &ToolOptionWidget::onToolChanged); @@ -136,6 +138,7 @@ void ToolOptionWidget::onToolPropertyChanged(ToolType, ToolPropertyType ePropert case ANTI_ALIASING: setAA(p.useAA); break; case STABILIZATION: setStabilizerLevel(p.stabilizerLevel); break; case FILLCONTOUR: setFillContour(p.useFillContour); break; + case AUTOSWITCHTOOL: setAutoSwitchTool(p.autoSwitchTool); break; case SHOWSELECTIONINFO: setShowSelectionInfo(p.showSelectionInfo); break; case BEZIER: setBezier(p.bezier_state); break; case CAMERAPATH: { break; } @@ -186,6 +189,7 @@ void ToolOptionWidget::setVisibility(BaseTool* tool) ui->stabilizerLabel->setVisible(tool->isPropertyEnabled(STABILIZATION)); ui->inpolLevelsCombo->setVisible(tool->isPropertyEnabled(STABILIZATION)); ui->fillContourBox->setVisible(tool->isPropertyEnabled(FILLCONTOUR)); + ui->autoSwitchToolCheckBox->setVisible(tool->isPropertyEnabled(AUTOSWITCHTOOL)); ui->showInfoBox->setVisible(tool->isPropertyEnabled(SHOWSELECTIONINFO)); auto currentLayerType = editor()->layers()->currentLayer()->type(); @@ -344,6 +348,12 @@ void ToolOptionWidget::setBezier(bool useBezier) ui->useBezierBox->setChecked(useBezier); } +void ToolOptionWidget::setAutoSwitchTool(bool autoSwitch) +{ + QSignalBlocker b(ui->autoSwitchToolCheckBox); + ui->autoSwitchToolCheckBox->setChecked(autoSwitch); +} + void ToolOptionWidget::setShowSelectionInfo(bool showSelectionInfo) { QSignalBlocker b(ui->showInfoBox); diff --git a/app/src/tooloptionwidget.h b/app/src/tooloptionwidget.h index 1a0426f15..d715afbc5 100644 --- a/app/src/tooloptionwidget.h +++ b/app/src/tooloptionwidget.h @@ -65,6 +65,7 @@ public slots: void setStabilizerLevel(int); void setFillContour(int); void setBezier(bool); + void setAutoSwitchTool(bool); void setShowSelectionInfo(bool); void disableAllOptions(); diff --git a/app/ui/tooloptions.ui b/app/ui/tooloptions.ui index 47d1a4116..eba83d521 100644 --- a/app/ui/tooloptions.ui +++ b/app/ui/tooloptions.ui @@ -130,6 +130,16 @@ + + + + Auto-Switch to Move Tool + + + true + + + diff --git a/core_lib/src/managers/toolmanager.cpp b/core_lib/src/managers/toolmanager.cpp index 14233ec79..05cf9dd1f 100644 --- a/core_lib/src/managers/toolmanager.cpp +++ b/core_lib/src/managers/toolmanager.cpp @@ -266,6 +266,11 @@ void ToolManager::setUseFillContour(bool useFillContour) emit toolPropertyChanged(currentTool()->type(), FILLCONTOUR); } +void ToolManager::setAutoSwitchTool(bool autoSwitch) +{ + currentTool()->setAutoSwitchTool(autoSwitch); +} + void ToolManager::setShowSelectionInfo(bool b) { currentTool()->setShowSelectionInfo(b); diff --git a/core_lib/src/managers/toolmanager.h b/core_lib/src/managers/toolmanager.h index 6ba1cd332..ed151363c 100644 --- a/core_lib/src/managers/toolmanager.h +++ b/core_lib/src/managers/toolmanager.h @@ -80,6 +80,7 @@ public slots: void setBucketFillReferenceMode(int referenceMode); void setBucketFillExpand(int); void setUseFillContour(bool); + void setAutoSwitchTool(bool autoSwitch); void setShowSelectionInfo(bool b); void setShowCameraPath(bool); void resetCameraPath(); diff --git a/core_lib/src/tool/basetool.cpp b/core_lib/src/tool/basetool.cpp index d02496cb4..be203f99f 100644 --- a/core_lib/src/tool/basetool.cpp +++ b/core_lib/src/tool/basetool.cpp @@ -444,6 +444,11 @@ void BaseTool::setUseFillContour(const bool useFillContour) properties.useFillContour = useFillContour; } +void BaseTool::setAutoSwitchTool(const bool autoSwitch) +{ + properties.autoSwitchTool = autoSwitch; +} + void BaseTool::setShowSelectionInfo(const bool b) { properties.showSelectionInfo = b; diff --git a/core_lib/src/tool/basetool.h b/core_lib/src/tool/basetool.h index 533b59491..4be86bf5c 100644 --- a/core_lib/src/tool/basetool.h +++ b/core_lib/src/tool/basetool.h @@ -55,6 +55,7 @@ class Properties bool bucketFillExpandEnabled = 0; int bucketFillReferenceMode = 0; bool useFillContour = false; + bool autoSwitchTool = true; bool showSelectionInfo = true; bool cameraShowPath = true; DotColorType cameraPathDotColorType = DotColorType::RED; @@ -128,6 +129,7 @@ class BaseTool : public QObject virtual void setFillExpandEnabled(const bool enabled); virtual void setFillReferenceMode(int referenceMode); virtual void setUseFillContour(const bool useFillContour); + virtual void setAutoSwitchTool(const bool autoSwitch); virtual void setShowSelectionInfo(const bool b); virtual void setShowCameraPath(const bool showCameraPath); virtual void setPathDotColorType(const DotColorType dotColorType); diff --git a/core_lib/src/tool/selecttool.cpp b/core_lib/src/tool/selecttool.cpp index 78be42526..6efee9c8a 100644 --- a/core_lib/src/tool/selecttool.cpp +++ b/core_lib/src/tool/selecttool.cpp @@ -38,6 +38,8 @@ void SelectTool::loadSettings() QSettings settings(PENCIL2D, PENCIL2D); properties.showSelectionInfo = settings.value("ShowSelectionInfo").toBool(); mPropertyEnabled[SHOWSELECTIONINFO] = true; + properties.autoSwitchTool = true; + mPropertyEnabled[AUTOSWITCHTOOL] = true; } QCursor SelectTool::cursor() diff --git a/core_lib/src/util/pencildef.h b/core_lib/src/util/pencildef.h index e1b9b11ac..20aff72a2 100644 --- a/core_lib/src/util/pencildef.h +++ b/core_lib/src/util/pencildef.h @@ -60,6 +60,7 @@ enum ToolPropertyType STABILIZATION, TOLERANCE, FILLCONTOUR, + AUTOSWITCHTOOL, SHOWSELECTIONINFO, USETOLERANCE, BUCKETFILLEXPAND,