X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetEditor.cpp;h=29e07a1f3efb95bb39f6d5c61e9c620b4abc08ac;hb=0cea3be102af7247b2fe2c8035a1bb38b7bf82ae;hp=aa612eb28329f114451a0d1553d679e36701bc3b;hpb=89ae310dae732ef819ebea43b33afd5d44facf73;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index aa612eb28..29e07a1f3 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -21,12 +21,13 @@ #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 +40,31 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { } -double editedValue(double theValue, bool& isDone) +void editedValue(double& outValue, QString& outText) { - QDialog aDlg; - aDlg.setWindowFlags(Qt::FramelessWindowHint); - QHBoxLayout* aLay = new QHBoxLayout(&aDlg); - ModuleBase_Tools::zeroMargins(aLay); + QMenu* aPopup = new QMenu(); + + QLineEdit* aEditor = new QLineEdit(QString::number(outValue), aPopup); + QWidgetAction* aLineEditAction = new QWidgetAction(aPopup); + aLineEditAction->setDefaultWidget(aEditor); + aPopup->addAction(aLineEditAction); - QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg); + aEditor->setFocus(); aEditor->selectAll(); - aEditor->setValidator(new QDoubleValidator(aEditor)); - QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept())); - aLay->addWidget(aEditor); - - QPoint aPoint = QCursor::pos(); - aDlg.move(aPoint); - - isDone = aDlg.exec() == QDialog::Accepted; - double aValue = theValue; - if (isDone) - aValue = aEditor->text().toDouble(); - return aValue; + 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 + } + aPopup->deleteLater(); } bool ModuleBase_WidgetEditor::focusTo() @@ -86,25 +91,13 @@ void ModuleBase_WidgetEditor::showPopupEditor() // White while all events will be processed //QApplication::processEvents(); double aValue = mySpinBox->value(); - bool isDone; - aValue = editedValue(aValue, isDone); - - if (isDone) { + QString aText; + 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); -}