X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=aa4cd79b70bdaa0d9af645402e6779dd43788e61;hb=450d1bd65c11870d3942a30164518037b9a7503e;hp=84b63cf2835e12c3ccd399b6cd76a872a158983c;hpb=49542ab918c826db5c10abda5be3787937113d94;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 84b63cf28..aa4cd79b7 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -1,14 +1,18 @@ +// 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 #include -#include +#include #include #include @@ -17,77 +21,126 @@ #include -#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData) + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), + //myIsEnterPressedEmitted(false), + myXPosition(-1), myYPosition(-1) { - myEditor = new QLineEdit(0); - myEditor->setWindowFlags(Qt::ToolTip); - myEditor->setFocusPolicy(Qt::StrongFocus); - - connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing())); - connect(myEditor, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesChanged())); } ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { - delete myEditor; } -bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const +void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) { - DataPtr aData = theFeature->data(); - AttributeDoublePtr aReal = aData->real(attributeID()); - bool isOk; - double aValue = myEditor->text().toDouble(&isOk); - if (isOk && aReal->value() != aValue) { - //ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this; - //bool isBlocked = that->blockSignals(true); - aReal->setValue(aValue); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); - //that->blockSignals(isBlocked); - } - return true; -} + QDialog aDlg(QApplication::desktop(), Qt::FramelessWindowHint); + QHBoxLayout* aLay = new QHBoxLayout(&aDlg); + aLay->setContentsMargins(2, 2, 2, 2); -bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature) -{ - boost::shared_ptr aData = theFeature->data(); - AttributeDoublePtr aRef = aData->real(attributeID()); + ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg); + anEditor->enableKeyPressEvent(true); + //if (!myIsEditing) { + // connect(anEditor, SIGNAL(enterPressed()), this, SLOT(onEnterPressed())); + //} - //bool isBlocked = this->blockSignals(true); - myEditor->setText(QString::number(aRef->value())); - //this->blockSignals(isBlocked); - return true; -} + anEditor->setMinimum(0); + anEditor->setMaximum(DBL_MAX); + if (outText.isEmpty()) + anEditor->setValue(outValue); + else + anEditor->setText(outText); -void ModuleBase_WidgetEditor::focusTo() -{ - QPoint aPoint = QCursor::pos(); + aLay->addWidget(anEditor); - myEditor->move(aPoint); - myEditor->show(); + ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue"); + anEditor->selectAll(); + QObject::connect(anEditor, SIGNAL(enterReleased()), &aDlg, SLOT(accept())); - myEditor->selectAll(); - myEditor->setFocus(); + QPoint aPoint = QCursor::pos(); + if (myXPosition >= 0 && myYPosition >= 0) + aPoint = QPoint(myXPosition, myYPosition); + + aDlg.move(aPoint); + aDlg.exec(); + + //if (!myIsEditing) { + // disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onEnterPressed())); + //} + + 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 + } } -QWidget* ModuleBase_WidgetEditor::getControl() const +bool ModuleBase_WidgetEditor::focusTo() { - return 0; + showPopupEditor(); + return true; } -QList ModuleBase_WidgetEditor::getControls() const +void ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals) { - QList aControls; - return aControls; + //myIsEnterPressedEmitted = 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. + 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; + if (mySpinBox->hasVariable()) + aText = mySpinBox->text(); + + editedValue(aValue, aText); + 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); + + //if (myIsEnterPressedEmitted) + if (!myIsEditing) + emit enterClicked(); + } + else + storeValue(); } -void ModuleBase_WidgetEditor::onStopEditing() +/*void ModuleBase_WidgetEditor::onEnterPressed() +{ + myIsEnterPressedEmitted = true; +}*/ + +void ModuleBase_WidgetEditor::setCursorPosition(const int theX, const int theY) { - myEditor->hide(); - emit focusOutWidget(this); + myXPosition = theX; + myYPosition = theY; }