Salome HOME
Merge branch 'Dev_1.5.0' of salome:modules/shaper into Dev_1.5.0
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
index 1c26b11ebf3b0aa43ee8ac060a66976cfa7c160a..334c50492d4eff3a9bbeb042f8eb1fc206517318 100644 (file)
@@ -28,6 +28,9 @@
 #include <QWidgetAction>
 #include <QRegExp>
 #include <QRegExpValidator>
+#include <QDesktopWidget>
+#include <QDialog>
+#include <QLayout>
 
 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
                                                  const Config_WidgetAPI* theData,
@@ -40,31 +43,37 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
 {
 }
 
-void editedValue(double& outValue, QString& outText)
+void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
 {
-  QMenu* aPopup = new QMenu();
-
-  QLineEdit* aEditor = new QLineEdit(QString::number(outValue), aPopup);
-  QWidgetAction* aLineEditAction = new QWidgetAction(aPopup);
-  aLineEditAction->setDefaultWidget(aEditor);
-  aPopup->addAction(aLineEditAction);
-
-  aEditor->setFocus();
-  aEditor->selectAll();
-  QString anExpression("([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)|([_a-zA-Z][a-zA-Z0-9_]*)");
-  aEditor->setValidator(new QRegExpValidator(QRegExp(anExpression), aEditor));
-  QObject::connect(aEditor, SIGNAL(returnPressed()), aLineEditAction, SIGNAL(triggered()));
-  QObject::connect(aLineEditAction, SIGNAL(triggered()), aPopup, SLOT(hide()));
-
-  QAction* aResult = aPopup->exec(QCursor::pos());
-  outText = aEditor->text();
+  QDialog aDlg(QApplication::desktop(), Qt::FramelessWindowHint);
+  QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
+  aLay->setContentsMargins(2, 2, 2, 2);
+
+  ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg);
+  anEditor->enableKeyPressEvent(true);
+
+  anEditor->setMinimum(0);
+  anEditor->setMaximum(DBL_MAX);
+  if (outText.isEmpty())
+    anEditor->setValue(outValue);
+  else
+    anEditor->setText(outText);
+
+  aLay->addWidget(anEditor);
+
+  anEditor->setFocus();
+  anEditor->selectAll();
+  QObject::connect(anEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept()));
+
+  aDlg.move(QCursor::pos());
+  aDlg.exec();
+  outText = anEditor->text();
   bool isDouble;
   double aValue = outText.toDouble(&isDouble);
   if (isDouble) {
     outValue = aValue;
-  //  outText = ""; // return empty string, if it's can be converted to a double
+    outText = ""; // return empty string, if it's can be converted to a double
   }
-  aPopup->deleteLater();
 }
 
 bool ModuleBase_WidgetEditor::focusTo()
@@ -92,6 +101,9 @@ void ModuleBase_WidgetEditor::showPopupEditor()
   //QApplication::processEvents();
   double aValue = mySpinBox->value();
   QString aText;
+  if (mySpinBox->hasVariable())
+    aText = mySpinBox->text();
+
   editedValue(aValue, aText);
   if (aText.isEmpty()) {
     ModuleBase_Tools::setSpinValue(mySpinBox, aValue);
@@ -99,5 +111,7 @@ void ModuleBase_WidgetEditor::showPopupEditor()
     ModuleBase_Tools::setSpinText(mySpinBox, aText);
   }
   emit valuesChanged();
-  emit focusOutWidget(this);
+  // the focus leaves the control automatically by the Enter/Esc event
+  // it is processed in operation manager
+  //emit focusOutWidget(this);
 }