X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=3adc21b0d452e653b5a0c32ed4665bdfb3caca70;hb=397bec888031ab3d5d0578d3094e01f9a052222f;hp=29e07a1f3efb95bb39f6d5c61e9c620b4abc08ac;hpb=a957eead1cbe68a3bcd8903dbf21c74cf8165fd5;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 29e07a1f3..3adc21b0d 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -28,11 +28,14 @@ #include #include #include +#include +#include +#include ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) + const Config_WidgetAPI* theData) +: ModuleBase_WidgetDoubleValue(theParent, theData), + myXPosition(-1), myYPosition(-1) { } @@ -40,64 +43,96 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { } -void editedValue(double& outValue, QString& outText) +bool 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(); - 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 isValueAccepted = false; + + 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); + + ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue"); + anEditor->selectAll(); + QObject::connect(anEditor, SIGNAL(enterReleased()), &aDlg, SLOT(accept())); + + QPoint aPoint = QCursor::pos(); + if (myXPosition >= 0 && myYPosition >= 0) + aPoint = QPoint(myXPosition, myYPosition); + + aDlg.move(aPoint); + isValueAccepted = aDlg.exec() == QDialog::Accepted; + if (isValueAccepted) { + 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(); + return isValueAccepted; } bool ModuleBase_WidgetEditor::focusTo() { - // nds: it seems, that the timer is not necessary anymore - - // 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())); - showPopupEditor(); - return true; } -void ModuleBase_WidgetEditor::showPopupEditor() +bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals) { + bool isValueAccepted = 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. - emit focusInWidget(this); + if (theSendSignals) + 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(); QString aText; - editedValue(aValue, aText); - if (aText.isEmpty()) { - ModuleBase_Tools::setSpinValue(mySpinBox, aValue); - } else { - ModuleBase_Tools::setSpinText(mySpinBox, aText); + if (mySpinBox->hasVariable()) + aText = mySpinBox->text(); + + isValueAccepted = editedValue(aValue, aText); + if (isValueAccepted) { + if (aText.isEmpty()) { + ModuleBase_Tools::setSpinValue(mySpinBox, aValue); + } else { + ModuleBase_Tools::setSpinText(mySpinBox, aText); + } + if (theSendSignals) { + emit valuesChanged(); + // the focus leaves the control automatically by the Enter/Esc event + // it is processed in operation manager + //emit focusOutWidget(this); + } + else + storeValue(); } - emit valuesChanged(); - emit focusOutWidget(this); + + if (theSendSignals && !myIsEditing) + emit enterClicked(this); + + return isValueAccepted; +} + +void ModuleBase_WidgetEditor::setCursorPosition(const int theX, const int theY) +{ + myXPosition = theX; + myYPosition = theY; }