From: vsv Date: Wed, 24 Jun 2015 09:13:18 +0000 (+0300) Subject: Issue #645: Input formula into pop-up dialog editor X-Git-Tag: V_1.3.0~200^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=360e98a896a5487a25c23a0c5f3039751142b15b;p=modules%2Fshaper.git Issue #645: Input formula into pop-up dialog editor --- diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index 34f7bcb6d..4569e2b8f 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -226,14 +226,14 @@ bool ModuleBase_ParamSpinBox::findVariable(const QString& theName, /*! \brief This function is called when the spinbox recieves key press event. */ -void ModuleBase_ParamSpinBox::keyPressEvent(QKeyEvent* e) -{ - if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { - QWidget::keyPressEvent(e); - } else { - ModuleBase_DoubleSpinBox::keyPressEvent(e); - } -} +//void ModuleBase_ParamSpinBox::keyPressEvent(QKeyEvent* e) +//{ +// if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { +// QWidget::keyPressEvent(e); +// } else { +// ModuleBase_DoubleSpinBox::keyPressEvent(e); +// } +//} /*! \brief This function is called when the spinbox recieves show event. diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.h b/src/ModuleBase/ModuleBase_ParamSpinBox.h index 403fc7a29..46af29092 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.h +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.h @@ -33,8 +33,8 @@ public: bool isAcceptVariables() const; bool hasVariable() const; -signals: - void textChanged(const QString&); +//signals: + //void textChanged(const QString&); protected: bool hasVariable(const QString& theText) const; @@ -45,7 +45,7 @@ signals: bool findVariable(const QString&, double&) const; protected: - virtual void keyPressEvent(QKeyEvent*); + //virtual void keyPressEvent(QKeyEvent*); virtual void showEvent(QShowEvent*); protected slots: diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 29e07a1f3..2b77ecafa 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData, @@ -42,21 +45,22 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() void editedValue(double& outValue, QString& outText) { - QMenu* aPopup = new QMenu(); + QDialog aDlg(QApplication::desktop(), Qt::Popup/* | Qt::FramelessWindowHint*/); + QHBoxLayout* aLay = new QHBoxLayout(&aDlg); + aLay->setContentsMargins(2, 2, 2, 2); - QLineEdit* aEditor = new QLineEdit(QString::number(outValue), aPopup); - QWidgetAction* aLineEditAction = new QWidgetAction(aPopup); - aLineEditAction->setDefaultWidget(aEditor); - aPopup->addAction(aLineEditAction); + ModuleBase_ParamSpinBox* aEditor = new ModuleBase_ParamSpinBox(&aDlg); + aEditor->setMinimum(0); + aEditor->setMaximum(DBL_MAX); + aEditor->setValue(outValue); + aLay->addWidget(aEditor); 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())); + QObject::connect(aEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept())); - QAction* aResult = aPopup->exec(QCursor::pos()); + aDlg.move(QCursor::pos()); + aDlg.exec(); outText = aEditor->text(); bool isDouble; double aValue = outText.toDouble(&isDouble); @@ -64,7 +68,6 @@ void editedValue(double& outValue, QString& outText) outValue = aValue; outText = ""; // return empty string, if it's can be converted to a double } - aPopup->deleteLater(); } bool ModuleBase_WidgetEditor::focusTo()