Skip to content

Commit

Permalink
pencil2d#1792 Add option to toggle autoswitching
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldgenerator7 committed Oct 6, 2023
1 parent 709dc99 commit ef9449d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/src/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
10 changes: 10 additions & 0 deletions app/src/tooloptionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; }
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions app/src/tooloptionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public slots:
void setStabilizerLevel(int);
void setFillContour(int);
void setBezier(bool);
void setAutoSwitchTool(bool);
void setShowSelectionInfo(bool);

void disableAllOptions();
Expand Down
10 changes: 10 additions & 0 deletions app/ui/tooloptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@
</widget>
</item>

<item>
<widget class="QCheckBox" name="autoSwitchToolCheckBox">
<property name="text">
<string>Auto-Switch to Move Tool</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showInfoBox">
<property name="text">
Expand Down
5 changes: 5 additions & 0 deletions core_lib/src/managers/toolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/managers/toolmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions core_lib/src/tool/basetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions core_lib/src/tool/basetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions core_lib/src/tool/selecttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/util/pencildef.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum ToolPropertyType
STABILIZATION,
TOLERANCE,
FILLCONTOUR,
AUTOSWITCHTOOL,
SHOWSELECTIONINFO,
USETOLERANCE,
BUCKETFILLEXPAND,
Expand Down

0 comments on commit ef9449d

Please sign in to comment.