#include <QWidgetAction>
#include <QRegExp>
#include <QRegExpValidator>
+#include <QDesktopWidget>
+#include <QDialog>
+#include <QLayout>
ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
const Config_WidgetAPI* theData,
{
}
-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
}
- aPopup->deleteLater();
}
bool ModuleBase_WidgetEditor::focusTo()
//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);
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);
}