X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=334c50492d4eff3a9bbeb042f8eb1fc206517318;hb=c24c2f94491145b9c2cbd0be6c6bc3d157bca9bb;hp=b42e8401797c260b8450242e57db5a550f19b9a7;hpb=8dc74f82810d5f597b78633b457efb0ef4f89f9f;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index b42e84017..334c50492 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -1,8 +1,12 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: ModuleBase_WidgetEditor.cpp // Created: 25 Apr 2014 // Author: Natalia ERMOLAEVA #include +#include +#include #include #include @@ -17,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, @@ -31,65 +39,79 @@ ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, { } -ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, - const std::string& theAttribute) - : ModuleBase_WidgetDoubleValue(theParent, 0, "") +ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { - setAttributeID(theAttribute); } -ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() +void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) { + 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 + } } -double editedValue(double theValue, bool& isDone) +bool ModuleBase_WidgetEditor::focusTo() { - QDialog aDlg; - aDlg.setWindowFlags(Qt::FramelessWindowHint); - QHBoxLayout* aLay = new QHBoxLayout(&aDlg); - aLay->setContentsMargins(0, 0, 0, 0); + // nds: it seems, that the timer is not necessary anymore - QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg); - aEditor->setValidator(new QDoubleValidator(aEditor)); - QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept())); - aLay->addWidget(aEditor); + // We can not launch here modal process for value editing because + // it can be called on other focusOutWidget event and will block it + //QTimer::singleShot(1, this, SLOT(showPopupEditor())); - QPoint aPoint = QCursor::pos(); - aDlg.move(aPoint); + showPopupEditor(); - isDone = aDlg.exec() == QDialog::Accepted; - double aValue = theValue; - if (isDone) - aValue = aEditor->text().toDouble(); - return aValue; + return true; } -bool ModuleBase_WidgetEditor::focusTo() +void ModuleBase_WidgetEditor::showPopupEditor() { + // 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. + emit focusInWidget(this); + + // nds: it seems, that the envents processing is not necessary anymore + // White while all events will be processed + //QApplication::processEvents(); double aValue = mySpinBox->value(); - bool isDone; - aValue = editedValue(aValue, isDone); - - if (isDone) { - bool isBlocked = mySpinBox->blockSignals(true); - mySpinBox->setValue(aValue); - mySpinBox->blockSignals(isBlocked); + QString aText; + if (mySpinBox->hasVariable()) + aText = mySpinBox->text(); + + editedValue(aValue, aText); + if (aText.isEmpty()) { + ModuleBase_Tools::setSpinValue(mySpinBox, aValue); + } else { + ModuleBase_Tools::setSpinText(mySpinBox, aText); } emit valuesChanged(); - emit focusOutWidget(this); - - return false; -} - -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); + // the focus leaves the control automatically by the Enter/Esc event + // it is processed in operation manager + //emit focusOutWidget(this); }