Salome HOME
Spell-checking
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
index 1c26b11ebf3b0aa43ee8ac060a66976cfa7c160a..5aa9aa24f8e3f11b456ad62a086e6f6e34077c93 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,
@@ -42,29 +45,33 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
 
 void editedValue(double& outValue, QString& outText)
 {
-  QMenu* aPopup = new QMenu();
+  QDialog aDlg(QApplication::desktop(), Qt::Popup/* | Qt::FramelessWindowHint*/);
+  QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
+  aLay->setContentsMargins(2, 2, 2, 2);
 
-  QLineEdit* aEditor = new QLineEdit(QString::number(outValue), aPopup);
-  QWidgetAction* aLineEditAction = new QWidgetAction(aPopup);
-  aLineEditAction->setDefaultWidget(aEditor);
-  aPopup->addAction(aLineEditAction);
+  ModuleBase_ParamSpinBox* aEditor = new ModuleBase_ParamSpinBox(&aDlg);
+  aEditor->setMinimum(0);
+  aEditor->setMaximum(DBL_MAX);
+  if (outText.isEmpty())
+    aEditor->setValue(outValue);
+  else
+    aEditor->setText(outText);
+
+  aLay->addWidget(aEditor);
 
   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()));
+  QObject::connect(aEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept()));
 
-  QAction* aResult = aPopup->exec(QCursor::pos());
+  aDlg.move(QCursor::pos());
+  aDlg.exec();
   outText = aEditor->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 +99,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);