Salome HOME
Improve multi-selector control to provide items multi-selection and "Delete" context...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
index 5aa9aa24f8e3f11b456ad62a086e6f6e34077c93..aa4cd79b70bdaa0d9af645402e6779dd43788e61 100644 (file)
@@ -35,7 +35,9 @@
 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
                                                  const Config_WidgetAPI* theData,
                                                  const std::string& theParentId)
-    : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
+: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId),
+  //myIsEnterPressedEmitted(false),
+  myXPosition(-1), myYPosition(-1)
 {
 }
 
@@ -43,29 +45,43 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
 {
 }
 
-void editedValue(double& outValue, QString& outText)
+void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
 {
-  QDialog aDlg(QApplication::desktop(), Qt::Popup/* | Qt::FramelessWindowHint*/);
+  QDialog aDlg(QApplication::desktop(), Qt::FramelessWindowHint);
   QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
   aLay->setContentsMargins(2, 2, 2, 2);
 
-  ModuleBase_ParamSpinBox* aEditor = new ModuleBase_ParamSpinBox(&aDlg);
-  aEditor->setMinimum(0);
-  aEditor->setMaximum(DBL_MAX);
+  ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg);
+  anEditor->enableKeyPressEvent(true);
+  //if (!myIsEditing) {
+  //  connect(anEditor, SIGNAL(enterPressed()), this, SLOT(onEnterPressed()));
+  //}
+
+  anEditor->setMinimum(0);
+  anEditor->setMaximum(DBL_MAX);
   if (outText.isEmpty())
-    aEditor->setValue(outValue);
+    anEditor->setValue(outValue);
   else
-    aEditor->setText(outText);
+    anEditor->setText(outText);
+
+  aLay->addWidget(anEditor);
 
-  aLay->addWidget(aEditor);
+  ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue");
+  anEditor->selectAll();
+  QObject::connect(anEditor, SIGNAL(enterReleased()), &aDlg, SLOT(accept()));
 
-  aEditor->setFocus();
-  aEditor->selectAll();
-  QObject::connect(aEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept()));
+  QPoint aPoint = QCursor::pos();
+  if (myXPosition >= 0 && myYPosition >= 0)
+    aPoint = QPoint(myXPosition, myYPosition);
 
-  aDlg.move(QCursor::pos());
+  aDlg.move(aPoint);
   aDlg.exec();
-  outText = aEditor->text();
+
+  //if (!myIsEditing) {
+  //  disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onEnterPressed()));
+  //}
+
+  outText = anEditor->text();
   bool isDouble;
   double aValue = outText.toDouble(&isDouble);
   if (isDouble) {
@@ -76,23 +92,19 @@ void editedValue(double& outValue, QString& outText)
 
 bool ModuleBase_WidgetEditor::focusTo()
 {
-  // nds: it seems, that the timer is not necessary anymore
-
-  // We can not launch here modal process for value editing because 
-  // it can be called on other focusOutWidget event and will block it
-  //QTimer::singleShot(1, this, SLOT(showPopupEditor()));
-
   showPopupEditor();
-
   return true;
 }
 
-void ModuleBase_WidgetEditor::showPopupEditor()
+void ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
 {
+  //myIsEnterPressedEmitted = 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.
-  emit focusInWidget(this);
+  if (theSendSignals)
+    emit focusInWidget(this);
 
   // nds: it seems, that the envents processing is not necessary anymore
   // White while all events will be processed
@@ -108,6 +120,27 @@ void ModuleBase_WidgetEditor::showPopupEditor()
   } else {
     ModuleBase_Tools::setSpinText(mySpinBox, aText);
   }
-  emit valuesChanged();
-  emit focusOutWidget(this);
+  if (theSendSignals) {
+    emit valuesChanged();
+    // the focus leaves the control automatically by the Enter/Esc event
+    // it is processed in operation manager
+    //emit focusOutWidget(this);
+
+    //if (myIsEnterPressedEmitted)
+    if (!myIsEditing)
+      emit enterClicked();
+  }
+  else
+    storeValue();
+}
+
+/*void ModuleBase_WidgetEditor::onEnterPressed()
+{
+  myIsEnterPressedEmitted = true;
+}*/
+
+void ModuleBase_WidgetEditor::setCursorPosition(const int theX, const int theY)
+{
+  myXPosition = theX;
+  myYPosition = theY;
 }