X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=aa73fd1a169ca71eadf5ea832d78f22907280b03;hb=63d86e00e1e6a482fcad527ae0b883deccceed11;hp=e70fcbb8137fecfcc11e867a21897812bb7ca5b2;hpb=8e3a78ec70078f64c13e86b719c82dc6ca3e7e7f;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index e70fcbb81..aa73fd1a1 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include @@ -36,6 +35,7 @@ #include #include +#include #include #include #include @@ -46,6 +46,27 @@ #include #include +// Dialog is redefined to avoid Escape key processing +class ModuleBase_EditorDialog : public QDialog +{ +public: + ModuleBase_EditorDialog(QWidget* theParent, Qt::WindowFlags theFlags) + : QDialog(theParent, theFlags) + { + setObjectName("ModuleBase_EditorDialog"); + setMinimumWidth(100); + } + ~ModuleBase_EditorDialog() {} + +protected: + // Do nothing if key pressed because it is processing on operation manager level + virtual void keyPressEvent(QKeyEvent* theEvent) { + if (theEvent->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(theEvent); + } +}; + ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData) : ModuleBase_WidgetDoubleValue(theParent, theData), @@ -57,18 +78,24 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { } -bool ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) +bool ModuleBase_WidgetEditor::editedValue(double theSpinMinValue, double theSpinMaxValue, + double& outValue, QString& outText) { bool isValueAccepted = false; - myEditorDialog = new QDialog(QApplication::desktop(), Qt::FramelessWindowHint); + myEditorDialog = new ModuleBase_EditorDialog(QApplication::desktop(), Qt::FramelessWindowHint); QHBoxLayout* aLay = new QHBoxLayout(myEditorDialog); aLay->setContentsMargins(2, 2, 2, 2); ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(myEditorDialog); - anEditor->setMinimum(0); - anEditor->setMaximum(DBL_MAX); + anEditor->setMinimum(theSpinMinValue); + anEditor->setMaximum(theSpinMaxValue); + + QStringList aParameters; + ModuleBase_Tools::getParameters(aParameters); + anEditor->setCompletionList(aParameters); + if (outText.isEmpty()) anEditor->setValue(outValue); else @@ -123,7 +150,7 @@ bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals) if (mySpinBox->hasVariable()) aText = mySpinBox->text(); - isValueAccepted = editedValue(aValue, aText); + isValueAccepted = editedValue(mySpinBox->minimum(), mySpinBox->maximum(), aValue, aText); if (isValueAccepted) { if (aText.isEmpty()) { if (mySpinBox->hasVariable()) { @@ -146,9 +173,9 @@ bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals) } ModuleBase_Tools::setFocus(mySpinBox, "ModuleBase_WidgetEditor::editedValue"); mySpinBox->selectAll(); - - if (theSendSignals && !myIsEditing) - emit enterClicked(this); + // enter is processed, so we need not anymore emit clicked signal + //if (theSendSignals && !myIsEditing && isValueAccepted) + // emit enterClicked(this); return isValueAccepted; } @@ -168,3 +195,13 @@ bool ModuleBase_WidgetEditor::processEnter() return ModuleBase_WidgetDoubleValue::processEnter(); } + +bool ModuleBase_WidgetEditor::processEscape() +{ + if (myEditorDialog) { + myEditorDialog->reject(); + return true; + } + + return ModuleBase_WidgetDoubleValue::processEscape(); +}