]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #645: Input formula into pop-up dialog editor
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 24 Jun 2015 09:13:18 +0000 (12:13 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 24 Jun 2015 09:13:31 +0000 (12:13 +0300)
src/ModuleBase/ModuleBase_ParamSpinBox.cpp
src/ModuleBase/ModuleBase_ParamSpinBox.h
src/ModuleBase/ModuleBase_WidgetEditor.cpp

index 34f7bcb6d25339de0e11febd42a10088db438342..4569e2b8fe351e47b8e1ece1465cceefe6d62e4e 100644 (file)
@@ -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.
index 403fc7a2983d00c185f71f589d2d79014417b562..46af290922d448a1216739cdb1db4184c2171407 100644 (file)
@@ -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:
index 29e07a1f3efb95bb39f6d5c61e9c620b4abc08ac..2b77ecafa7f60737e1410bcf1ad4a74486e97a29 100644 (file)
@@ -28,6 +28,9 @@
 #include <QWidgetAction>
 #include <QRegExp>
 #include <QRegExpValidator>
+#include <QDesktopWidget>
+#include <QDialog>
+#include <QLayout>
 
 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()