]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Set focus into dimension editor
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 24 Jun 2014 12:54:47 +0000 (16:54 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 24 Jun 2014 12:54:47 +0000 (16:54 +0400)
src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/ModuleBase/ModuleBase_WidgetEditor.h

index 84b63cf2835e12c3ccd399b6cd76a872a158983c..f62eae3d3fbe4085328d8c643146d0e566c83850 100644 (file)
 
 #include <QWidget>
 #include <QLineEdit>
+#include <QTimer>
+#include <QDialog>
+#include <QLayout>
 
 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
                                                  const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData)
+: ModuleBase_ModelWidget(theParent, theData), myValue(0)
 {
-  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;
+  //delete myEditor;
 }
 
 bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
@@ -42,13 +39,9 @@ bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
   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);
+  if (isOk && aReal->value() != myValue) {
+    aReal->setValue(myValue);
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
-    //that->blockSignals(isBlocked);
   }
   return true;
 }
@@ -58,9 +51,7 @@ bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   AttributeDoublePtr aRef = aData->real(attributeID());
 
-  //bool isBlocked = this->blockSignals(true);
-  myEditor->setText(QString::number(aRef->value()));
-  //this->blockSignals(isBlocked);
+  myValue = aRef->value();
   return true;
 }
 
@@ -68,11 +59,22 @@ void ModuleBase_WidgetEditor::focusTo()
 {
   QPoint aPoint = QCursor::pos();
 
-  myEditor->move(aPoint);
-  myEditor->show();
+  QDialog aDlg;
+  aDlg.setWindowFlags(Qt::FramelessWindowHint);
+  QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
+  aLay->setContentsMargins(0,0,0,0);
+
+  QLineEdit* aEditor = new QLineEdit(QString::number(myValue), &aDlg);
+  connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
+  aLay->addWidget(aEditor);
+
+  aDlg.move(aPoint);
+  int aRes = aDlg.exec();
+
+  if (aRes == QDialog::Accepted)
+    myValue = aEditor->text().toDouble();
 
-  myEditor->selectAll();
-  myEditor->setFocus();
+  emit focusOutWidget(this);
 }
 
 QWidget* ModuleBase_WidgetEditor::getControl() const
@@ -86,8 +88,3 @@ QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
   return aControls;
 }
 
-void ModuleBase_WidgetEditor::onStopEditing()
-{
-  myEditor->hide();
-  emit focusOutWidget(this);
-}
index e2f67a0cbbf2ecd2576976f6046d2b0dbf0a76d4..ec670f402cb9deb3e50bb7ad51b29b024f4db1fc 100644 (file)
@@ -48,14 +48,10 @@ public:
   /// \return a control list
   virtual QList<QWidget*> getControls() const;
 
-protected slots:
-  /// Slot to check the editing stop
-  void onStopEditing();
-
 private:
-  QLineEdit* myEditor;
   FeaturePtr myFeature; ///< the current widget feature
   QStringList myFeatureKinds; ///< the kinds of possible features
+  double myValue;
 };
 
 #endif