Sketcher: add option to disable leaving sketch with Esc button

This commit is contained in:
wmayer
2020-02-09 13:52:09 +01:00
parent b11909185c
commit e1b3ec41b6
7 changed files with 42 additions and 3 deletions

View File

@@ -38,7 +38,7 @@ using namespace Gui::TaskView;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDialog::TaskDialog()
: QObject(0), pos(North)
: QObject(0), pos(North), escapeButton(true)
{
}

View File

@@ -67,6 +67,14 @@ public:
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 @@ protected:
private:
std::string documentName;
bool escapeButton;
};
} //namespace TaskView

View File

@@ -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<QAbstractButton*> list = box->buttons();

View File

@@ -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();
}

View File

@@ -106,9 +106,28 @@ Requires to re-enter edit mode to take effect.</string>
</size>
</property>
<property name="title">
<string>Notifications</string>
<string>General</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxEnableEscape">
<property name="toolTip">
<string>Allow to leave sketch edit mode when pressing Esc button</string>
</property>
<property name="text">
<string>Esc can leave sketch edit mode</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>LeaveSketchWithEscape</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Sketcher</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxNotifyConstraintSubstitutions">
<property name="toolTip">

View File

@@ -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);

View File

@@ -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();