X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=5aa9aa24f8e3f11b456ad62a086e6f6e34077c93;hb=b263f22d52ccb191c4fad8f7455d9714a3024514;hp=aa612eb28329f114451a0d1553d679e36701bc3b;hpb=fc1a9c802c59a0e853dc43125362e513b6f6358f;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index aa612eb28..5aa9aa24f 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -21,12 +21,16 @@ #include -#include +#include #include -//#include +#include +#include +#include +#include +#include +#include #include #include -#include ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData, @@ -39,27 +43,35 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { } -double editedValue(double theValue, bool& isDone) +void editedValue(double& outValue, QString& outText) { - QDialog aDlg; - aDlg.setWindowFlags(Qt::FramelessWindowHint); + QDialog aDlg(QApplication::desktop(), Qt::Popup/* | Qt::FramelessWindowHint*/); QHBoxLayout* aLay = new QHBoxLayout(&aDlg); - ModuleBase_Tools::zeroMargins(aLay); + aLay->setContentsMargins(2, 2, 2, 2); - QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg); - aEditor->selectAll(); - aEditor->setValidator(new QDoubleValidator(aEditor)); - QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept())); - aLay->addWidget(aEditor); + ModuleBase_ParamSpinBox* aEditor = new ModuleBase_ParamSpinBox(&aDlg); + aEditor->setMinimum(0); + aEditor->setMaximum(DBL_MAX); + if (outText.isEmpty()) + aEditor->setValue(outValue); + else + aEditor->setText(outText); - QPoint aPoint = QCursor::pos(); - aDlg.move(aPoint); + aLay->addWidget(aEditor); - isDone = aDlg.exec() == QDialog::Accepted; - double aValue = theValue; - if (isDone) - aValue = aEditor->text().toDouble(); - return aValue; + aEditor->setFocus(); + aEditor->selectAll(); + QObject::connect(aEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept())); + + aDlg.move(QCursor::pos()); + aDlg.exec(); + outText = aEditor->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 + } } bool ModuleBase_WidgetEditor::focusTo() @@ -86,25 +98,16 @@ void ModuleBase_WidgetEditor::showPopupEditor() // White while all events will be processed //QApplication::processEvents(); double aValue = mySpinBox->value(); - bool isDone; - aValue = editedValue(aValue, isDone); + QString aText; + if (mySpinBox->hasVariable()) + aText = mySpinBox->text(); - if (isDone) { + editedValue(aValue, aText); + if (aText.isEmpty()) { ModuleBase_Tools::setSpinValue(mySpinBox, aValue); + } else { + ModuleBase_Tools::setSpinText(mySpinBox, aText); } emit valuesChanged(); emit focusOutWidget(this); } - -void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, - const std::string theAttribute) -{ - DataPtr aData = theFeature->data(); - AttributeDoublePtr aRef = aData->real(theAttribute); - double aValue = aRef->value(); - - bool isDone; - aValue = editedValue(aValue, isDone); - if (isDone) - aRef->setValue(aValue); -}