Skip to content

Commit

Permalink
pencil2d#1792 Auto-switch to the Move tool
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldgenerator7 committed Oct 6, 2023
1 parent 58eb218 commit 150b253
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/src/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
}
1 change: 1 addition & 0 deletions app/src/toolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions core_lib/src/tool/selecttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions core_lib/src/tool/selecttool.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class SelectTool : public BaseTool
void resetToDefault() override;
void setShowSelectionInfo(const bool b) override;

bool selectChanging();

private:

void pointerPressEvent(PointerEvent*) override;
Expand All @@ -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);
};
Expand Down

0 comments on commit 150b253

Please sign in to comment.