diff --git a/src/Gui/TaskView/TaskDialog.cpp b/src/Gui/TaskView/TaskDialog.cpp index 5c784c602eef..75643b18371d 100644 --- a/src/Gui/TaskView/TaskDialog.cpp +++ b/src/Gui/TaskView/TaskDialog.cpp @@ -38,7 +38,7 @@ using namespace Gui::TaskView; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TaskDialog::TaskDialog() - : QObject(0), pos(North) + : QObject(0), pos(North), escapeButton(true) { } diff --git a/src/Gui/TaskView/TaskDialog.h b/src/Gui/TaskView/TaskDialog.h index 39cafc0f6ac4..e26bbc8fb86a 100644 --- a/src/Gui/TaskView/TaskDialog.h +++ b/src/Gui/TaskView/TaskDialog.h @@ -67,6 +67,14 @@ class GuiExport TaskDialog : public QObject virtual void modifyStandardButtons(QDialogButtonBox*) {} + /// Defines whether a task dialog can be rejected by pressing Esc + void setEscapeButtonEnabled(bool on) { + escapeButton = on; + } + bool isEscapeButtonEnabled() const { + return escapeButton; + } + const std::string& getDocumentName() const { return documentName; } void setDocumentName(const std::string& doc) @@ -118,6 +126,7 @@ class GuiExport TaskDialog : public QObject private: std::string documentName; + bool escapeButton; }; } //namespace TaskView diff --git a/src/Gui/TaskView/TaskView.cpp b/src/Gui/TaskView/TaskView.cpp index 09c00650e6ef..8d9904bdf47a 100644 --- a/src/Gui/TaskView/TaskView.cpp +++ b/src/Gui/TaskView/TaskView.cpp @@ -477,7 +477,7 @@ void TaskView::keyPressEvent(QKeyEvent* ke) } } } - else if (ke->key() == Qt::Key_Escape) { + else if (ke->key() == Qt::Key_Escape && ActiveDialog->isEscapeButtonEnabled()) { // get only the buttons of the button box QDialogButtonBox* box = ActiveCtrl->standardButtons(); QList list = box->buttons(); diff --git a/src/Mod/Sketcher/Gui/SketcherSettings.cpp b/src/Mod/Sketcher/Gui/SketcherSettings.cpp index 2b9bae2c831c..eb742b5fec43 100644 --- a/src/Mod/Sketcher/Gui/SketcherSettings.cpp +++ b/src/Mod/Sketcher/Gui/SketcherSettings.cpp @@ -70,6 +70,7 @@ void SketcherSettings::saveSettings() // Sketch editing ui->checkBoxAdvancedSolverTaskBox->onSave(); ui->checkBoxRecalculateInitialSolutionWhileDragging->onSave(); + ui->checkBoxEnableEscape->onSave(); ui->checkBoxNotifyConstraintSubstitutions->onSave(); form->saveSettings(); } @@ -79,6 +80,7 @@ void SketcherSettings::loadSettings() // Sketch editing ui->checkBoxAdvancedSolverTaskBox->onRestore(); ui->checkBoxRecalculateInitialSolutionWhileDragging->onRestore(); + ui->checkBoxEnableEscape->onRestore(); ui->checkBoxNotifyConstraintSubstitutions->onRestore(); form->loadSettings(); } diff --git a/src/Mod/Sketcher/Gui/SketcherSettings.ui b/src/Mod/Sketcher/Gui/SketcherSettings.ui index 0247f18a4cda..f08bbf831980 100644 --- a/src/Mod/Sketcher/Gui/SketcherSettings.ui +++ b/src/Mod/Sketcher/Gui/SketcherSettings.ui @@ -106,9 +106,28 @@ Requires to re-enter edit mode to take effect. - Notifications + General + + + + Allow to leave sketch edit mode when pressing Esc button + + + Esc can leave sketch edit mode + + + true + + + LeaveSketchWithEscape + + + Mod/Sketcher + + + diff --git a/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp b/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp index abfa954a2b71..06d0cb3c9954 100644 --- a/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp +++ b/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp @@ -50,6 +50,7 @@ TaskDlgEditSketch::TaskDlgEditSketch(ViewProviderSketch *sketchView) SolverAdvanced = new TaskSketcherSolverAdvanced(sketchView); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + setEscapeButtonEnabled(hGrp->GetBool("LeaveSketchWithEscape", true)); Content.push_back(Messages); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index a09b0c2df323..7f6c17c0acd6 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -204,6 +204,7 @@ struct EditData { DrawSketchHandler *sketchHandler; bool editDatumDialog; bool buttonPress; + bool handleEscapeButton; // dragged point int DragPoint; @@ -486,6 +487,10 @@ bool ViewProviderSketch::keyPressed(bool pressed, int key) if (!pressed && !edit->buttonPress) return true; edit->buttonPress = pressed; + + // More control over Sketcher edit mode Esc key behavior + // https://forum.freecadweb.org/viewtopic.php?f=3&t=42207 + return edit->handleEscapeButton; } return false; } @@ -5651,6 +5656,9 @@ bool ViewProviderSketch::setEdit(int ModNum) ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); edit->MarkerSize = hGrp->GetInt("MarkerSize", 7); + ParameterGrp::handle hSketch = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + edit->handleEscapeButton = !hSketch->GetBool("LeaveSketchWithEscape", true); + createEditInventorNodes(); auto editDoc = Gui::Application::Instance->editDocument();