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)
{
}
{
}
-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) {
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.
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;
}