Skip to content

Commit

Permalink
Sketcher: add option to disable leaving sketch with Esc button
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Feb 9, 2020
1 parent 1e7e459 commit c01c1f7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Gui/TaskView/TaskDialog.cpp
Expand Up @@ -38,7 +38,7 @@ using namespace Gui::TaskView;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

TaskDialog::TaskDialog()
: QObject(0), pos(North)
: QObject(0), pos(North), escapeButton(true)
{

}
Expand Down
9 changes: 9 additions & 0 deletions src/Gui/TaskView/TaskDialog.h
Expand Up @@ -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)
Expand Down Expand Up @@ -118,6 +126,7 @@ class GuiExport TaskDialog : public QObject

private:
std::string documentName;
bool escapeButton;
};

} //namespace TaskView
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/TaskView/TaskView.cpp
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Sketcher/Gui/SketcherSettings.cpp
Expand Up @@ -70,6 +70,7 @@ void SketcherSettings::saveSettings()
// Sketch editing
ui->checkBoxAdvancedSolverTaskBox->onSave();
ui->checkBoxRecalculateInitialSolutionWhileDragging->onSave();
ui->checkBoxEnableEscape->onSave();
ui->checkBoxNotifyConstraintSubstitutions->onSave();
form->saveSettings();
}
Expand All @@ -79,6 +80,7 @@ void SketcherSettings::loadSettings()
// Sketch editing
ui->checkBoxAdvancedSolverTaskBox->onRestore();
ui->checkBoxRecalculateInitialSolutionWhileDragging->onRestore();
ui->checkBoxEnableEscape->onRestore();
ui->checkBoxNotifyConstraintSubstitutions->onRestore();
form->loadSettings();
}
Expand Down
21 changes: 20 additions & 1 deletion src/Mod/Sketcher/Gui/SketcherSettings.ui
Expand Up @@ -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">
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Expand Up @@ -204,6 +204,7 @@ struct EditData {
DrawSketchHandler *sketchHandler;
bool editDatumDialog;
bool buttonPress;
bool handleEscapeButton;

// dragged point
int DragPoint;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c01c1f7

Please sign in to comment.