X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=aa4cd79b70bdaa0d9af645402e6779dd43788e61;hb=450d1bd65c11870d3942a30164518037b9a7503e;hp=6f32c7606bba64efe3d4c8b9685bd751c90e83d3;hpb=6d9f778b60206147106c918852c4a9595898f892;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 6f32c7606..aa4cd79b7 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -1,9 +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 #include @@ -18,16 +21,23 @@ #include -#include +#include #include -#include +#include +#include +#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) +: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), + //myIsEnterPressedEmitted(false), + myXPosition(-1), myYPosition(-1) { } @@ -35,54 +45,102 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { } -double editedValue(double theValue, bool& isDone) +void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) { - QDialog aDlg; - aDlg.setWindowFlags(Qt::FramelessWindowHint); + QDialog aDlg(QApplication::desktop(), Qt::FramelessWindowHint); QHBoxLayout* aLay = new QHBoxLayout(&aDlg); - aLay->setContentsMargins(0, 0, 0, 0); + aLay->setContentsMargins(2, 2, 2, 2); + + ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg); + anEditor->enableKeyPressEvent(true); + //if (!myIsEditing) { + // connect(anEditor, SIGNAL(enterPressed()), this, SLOT(onEnterPressed())); + //} + + anEditor->setMinimum(0); + anEditor->setMaximum(DBL_MAX); + if (outText.isEmpty()) + anEditor->setValue(outValue); + else + anEditor->setText(outText); - QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg); - aEditor->setValidator(new QDoubleValidator(aEditor)); - QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept())); - aLay->addWidget(aEditor); + aLay->addWidget(anEditor); + + ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue"); + anEditor->selectAll(); + QObject::connect(anEditor, SIGNAL(enterReleased()), &aDlg, SLOT(accept())); QPoint aPoint = QCursor::pos(); - aDlg.move(aPoint); + if (myXPosition >= 0 && myYPosition >= 0) + aPoint = QPoint(myXPosition, myYPosition); - isDone = aDlg.exec() == QDialog::Accepted; - double aValue = theValue; - if (isDone) - aValue = aEditor->text().toDouble(); - return aValue; + 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 + } } bool ModuleBase_WidgetEditor::focusTo() { - double aValue = mySpinBox->value(); - bool isDone; - aValue = editedValue(aValue, isDone); + showPopupEditor(); + return true; +} - if (isDone) { - bool isBlocked = mySpinBox->blockSignals(true); - mySpinBox->setValue(aValue); - mySpinBox->blockSignals(isBlocked); - } - emit valuesChanged(); - emit focusOutWidget(this); +void ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals) +{ + //myIsEnterPressedEmitted = false; - return 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::editFeatureValue(FeaturePtr theFeature, - const std::string theAttribute) +/*void ModuleBase_WidgetEditor::onEnterPressed() +{ + myIsEnterPressedEmitted = true; +}*/ + +void ModuleBase_WidgetEditor::setCursorPosition(const int theX, const int theY) { - DataPtr aData = theFeature->data(); - AttributeDoublePtr aRef = aData->real(theAttribute); - double aValue = aRef->value(); - - bool isDone; - aValue = editedValue(aValue, isDone); - if (isDone) - aRef->setValue(aValue); + myXPosition = theX; + myYPosition = theY; }