]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/ModuleBase/ModuleBase_WidgetEditor.cpp
Salome HOME
Debug information for setFocus/activateWindow methods.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
index 5aa9aa24f8e3f11b456ad62a086e6f6e34077c93..6ef0847abd9c093426fb7d12bebb5a00ce01640e 100644 (file)
@@ -35,7 +35,8 @@
 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
                                                  const Config_WidgetAPI* theData,
                                                  const std::string& theParentId)
-    : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
+: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId),
+  myIsKeyReleasedEmitted(false)
 {
 }
 
@@ -43,29 +44,39 @@ 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(keyReleased(QKeyEvent*)), this, SLOT(onKeyReleased(QKeyEvent*)));
+  }
+
+  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(aEditor);
+  aLay->addWidget(anEditor);
 
-  aEditor->setFocus();
-  aEditor->selectAll();
-  QObject::connect(aEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept()));
+  ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue");
+  anEditor->selectAll();
+  QObject::connect(anEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept()));
 
   aDlg.move(QCursor::pos());
   aDlg.exec();
-  outText = aEditor->text();
+
+  if (!myIsEditing) {
+    disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onKeyReleased(QKeyEvent*)));
+  }
+
+  outText = anEditor->text();
   bool isDouble;
   double aValue = outText.toDouble(&isDouble);
   if (isDouble) {
@@ -89,6 +100,8 @@ bool ModuleBase_WidgetEditor::focusTo()
 
 void ModuleBase_WidgetEditor::showPopupEditor()
 {
+  myIsKeyReleasedEmitted = 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.
@@ -109,5 +122,15 @@ 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);
+
+  if (myIsKeyReleasedEmitted)
+    emit enterClicked();
+}
+
+void ModuleBase_WidgetEditor::onKeyReleased(QKeyEvent* theEvent)
+{
+  myIsKeyReleasedEmitted = true;
 }