X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=334c50492d4eff3a9bbeb042f8eb1fc206517318;hb=c24c2f94491145b9c2cbd0be6c6bc3d157bca9bb;hp=1c26b11ebf3b0aa43ee8ac060a66976cfa7c160a;hpb=e2c1d6fb594fe1234fa7a0786801d8c1c92d7ac6;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 1c26b11eb..334c50492 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include 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); }