Salome HOME
Merge branch 'Dev_GroupsRevision'
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
index 854d451a8d59f3a95519a2807975420eaa702f32..be60db9d3b503a620ba69118b8e50af10ef2be79 100644 (file)
@@ -14,7 +14,8 @@
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
 //
 
 #include <ModuleBase_WidgetEditor.h>
@@ -35,6 +36,7 @@
 #include <GeomDataAPI_Point2D.h>
 
 #include <QApplication>
+#include <QKeyEvent>
 #include <QLineEdit>
 #include <QMenu>
 #include <QWidget>
 #include <QDialog>
 #include <QLayout>
 
+// Dialog is redefined to avoid Escape key processing
+class ModuleBase_EditorDialog : public QDialog
+{
+public:
+  ModuleBase_EditorDialog(QWidget* theParent, Qt::WindowFlags theFlags)
+    : QDialog(theParent, theFlags) {}
+  ~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),
@@ -56,18 +75,19 @@ 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);
   if (outText.isEmpty())
     anEditor->setValue(outValue);
   else
@@ -101,7 +121,7 @@ bool ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
 bool ModuleBase_WidgetEditor::focusTo()
 {
   showPopupEditor();
-  return true;
+  return false;
 }
 
 bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
@@ -109,9 +129,10 @@ bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
   bool isValueAccepted = false;
   // we need to emit the focus in event manually in order to save the widget as an active
   // in the property panel before the mouse leave event happens in the viewer. The module
-  // ask an active widget and change the feature visualization if the widget is not the current one.
-  if (theSendSignals)
-    emitFocusInWidget();
+  // ask an active widget and change the feature visualization if the widget is not the current
+  // one.  Also we need this widget as active to provide call of processEnter() applyed
+  // by operation manager to the current widget. If not, the myEditorDialog will stay opened
+  emitFocusInWidget();
 
   // nds: it seems, that the envents processing is not necessary anymore
   // White while all events will be processed
@@ -121,7 +142,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()) {
@@ -144,9 +165,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;
 }
@@ -166,3 +187,13 @@ bool ModuleBase_WidgetEditor::processEnter()
 
   return ModuleBase_WidgetDoubleValue::processEnter();
 }
+
+bool ModuleBase_WidgetEditor::processEscape()
+{
+  if (myEditorDialog) {
+    myEditorDialog->reject();
+    return true;
+  }
+
+  return ModuleBase_WidgetDoubleValue::processEscape();
+}