]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Wed, 25 Jun 2014 16:09:37 +0000 (20:09 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 25 Jun 2014 16:09:37 +0000 (20:09 +0400)
1. Focus processing(focusTo is boolean for a constraint editor, focusOut in eventFilter to start a new line creation in an indepmendent place in case of contour, remove the previous focusActivate functionality of the create operation).

12 files changed:
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/ModuleBase/ModuleBase_WidgetEditor.h
src/ModuleBase/ModuleBase_WidgetPoint2D.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/PartSet/PartSet_OperationFeatureCreate.h
src/PartSet/PartSet_OperationSketchBase.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_PropertyPanel.h

index cd56f06c363d259b3dbbfad4bdaafe1cd2b56da9..720f089331c08703fe22d3a56f2532e62d63c6d8 100644 (file)
@@ -22,12 +22,7 @@ bool ModuleBase_ModelWidget::isInitialized(FeaturePtr theFeature) const
   return theFeature->data()->attribute(attributeID())->isInitialized();
 }
 
-bool ModuleBase_ModelWidget::canFocusTo(const std::string& theAttributeName) const
-{
-  return theAttributeName == attributeID();
-}
-
-void ModuleBase_ModelWidget::focusTo()
+bool ModuleBase_ModelWidget::focusTo()
 {
   QList<QWidget*> aControls = getControls();
   QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
@@ -38,6 +33,7 @@ void ModuleBase_ModelWidget::focusTo()
       break;
     }
   }
+  return true;
 }
 
 std::string ModuleBase_ModelWidget::attributeID() const
index 78680ec3b6347d26ad6ca18d055d0111b25a9f3b..5c8e9da51a8381f0cbac9b22b65841d248d47d9c 100644 (file)
@@ -47,13 +47,10 @@ public:
 
   virtual bool restoreValue(FeaturePtr theFeature) = 0;
 
-  /// Returns whether the widget can accept focus, or if it corresponds to the given attribute
-  /// \param theAttribute name
-  bool canFocusTo(const std::string& theAttributeName) const;
-
   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
   /// If the widget has the NonFocus focus policy, it is skipped.
-  virtual void focusTo();
+  /// \return the state whether the widget can accept the focus
+  virtual bool focusTo();
 
   /// Returns list of widget controls
   /// \return a control list
index e4a2505f31a39ec2f3953f503d91bc11bc092528..ccbb0ad7ebd14a781d8cbee54999d8c636038f65 100644 (file)
@@ -123,6 +123,10 @@ bool ModuleBase_WidgetDoubleValue::eventFilter(QObject *theObject, QEvent *theEv
 {
   if (theObject == mySpinBox) {
     if (theEvent->type() == QEvent::KeyRelease) {
+      QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent;
+      if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) {
+        emit focusOutWidget(this);
+      }
       emit keyReleased(attributeID(), (QKeyEvent*) theEvent);
       return true;
     }
index 694e5a809deb39a7074c0f82b885a31578af6297..dbbe9fd5dbd09d4d8e575a3b8ce5aea6132db054 100644 (file)
@@ -61,7 +61,7 @@ double editedValue(double theValue, bool& isDone)
   return aValue;
 }
 
-void ModuleBase_WidgetEditor::focusTo()
+bool ModuleBase_WidgetEditor::focusTo()
 {
   double aValue = mySpinBox->value();
   bool isDone;
@@ -74,6 +74,8 @@ void ModuleBase_WidgetEditor::focusTo()
   }
   emit valuesChanged();
   emit focusOutWidget(this);
+
+  return false;
 }
 
 void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, const std::string theAttribute)
index e75d4cebda4b7c171b743359b64f6ba3b27d83c4..4585bdbbc110d2cb72aa4ee69083d1bd92d975f1 100644 (file)
@@ -38,7 +38,8 @@ public:
 
   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
   /// If the widget has the NonFocus focus policy, it is skipped.
-  virtual void focusTo();
+  /// \return the state whether the widget can accept the focus
+  virtual bool focusTo();
 
   /// Creates an editor for the real value and set the new value to the feature
   /// \param theFeature the model feature
index 58130a384f6230cb091987d237bfebc85f9a9f19..5f6c1e857cd72ed94b3641ec47214e6f9e6b111d 100644 (file)
@@ -129,6 +129,10 @@ bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
 {
   if (theObject == myXSpin || theObject == myYSpin) {
     if (theEvent->type() == QEvent::KeyRelease) {
+      QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent;
+      if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) {
+        emit focusOutWidget(this);
+      }
       emit keyReleased(attributeID(), (QKeyEvent*) theEvent);
       return true;
     }
index 1266a0cb1e503eba2ada7e35c8823c4d6c2ddd74..2ba50835cf68162c8181daf95dae4bc8f8886ead 100644 (file)
@@ -147,9 +147,6 @@ void PartSet_Module::onOperationStarted()
                                        myWorkshop->operationMgr()->currentOperation());
   if (aPreviewOp) {
     XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
-    connect(aPreviewOp, SIGNAL(focusActivated(const std::string&)),
-            aPropPanel, SLOT(onFocusActivated(const std::string&)));
-
     connect(aPropPanel, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
       this, SLOT(onStorePoint2D(FeaturePtr, const std::string&)), Qt::UniqueConnection);
   }
@@ -162,8 +159,6 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
   if (aPreviewOp) {
     XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
-    disconnect(aPreviewOp, SIGNAL(focusActivated(const std::string&)),
-               aPropPanel, SLOT(onFocusActivated(const std::string&)));
     //disconnect(aPropPanel, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
     //           this, SLOT(onStorePoint2D(FeaturePtr, const std::string&)));
   }
index 05c00f017d361a68d9bf4e49180ed021db3ae2fc..e5a54cb382e6f332335040c2d9afe5bac7e48911 100644 (file)
@@ -149,13 +149,6 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle
       }
     }
   }
-  /*if (feature()->getKind() == SKETCH_ARC_KIND) {
-    boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
-                              boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
-    if (anArcPrs) {
-      anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
-    }
-  }*/
   bool isApplyed = false;
   if (isPointWidget())
     isApplyed = setWidgetPoint(aX, anY);
@@ -183,15 +176,6 @@ void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3
     double aX, anY;
     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
     PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
-    /*if (myPointSelectionMode == SM_ThirdPoint) {
-      if (feature()->getKind() == SKETCH_ARC_KIND) {
-        boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
-                                boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
-        if (anArcPrs) {
-          anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
-        }
-      }
-    }*/
     setWidgetPoint(aX, anY);
     flushUpdated();
   }
@@ -292,19 +276,6 @@ FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMess
   return aNewFeature;
 }
 
-/*void PartSet_OperationFeatureCreate::setPointSelectionMode(const PartSet_SelectionMode& theMode,
-                                                           const bool isToEmitSignal)
-{
-  myPointSelectionMode = theMode;
-  if (isToEmitSignal) {
-    std::string aName = myFeaturePrs->getAttribute(theMode);
-    if (aName.empty() && theMode == SM_DonePoint) {
-      aName = XGUI::PROP_PANEL_OK;
-    }
-    emit focusActivated(aName);
-  }
-}*/
-
 bool PartSet_OperationFeatureCreate::isPointWidget() const
 {
   return dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget) ||
index 606bdc3bfefa98b7e5a45fa9d751076a1f104f84..f4ecd643ac96fb3b7e3bd9918c5a697dd05182ab 100644 (file)
@@ -114,12 +114,6 @@ protected:
   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
 
 protected:
-  ///< Set the point selection mode. Emit signal about focus change if necessary.
-  /// \param theMode a new selection mode
-  /// \param isToEmitSignal the neccessity to emit signal
-  //void setPointSelectionMode(const PartSet_SelectionMode& theMode,
-  //                           const bool isToEmitSignal = true);
-
   /// Returns true if the active widget is the point selector widget
   /// \return the boolean value
   bool isPointWidget() const;
index cb51f46b9ce2827a5308fb17ce0420ab7dc76a61..9e4a72cbab36cf94a28315855387cb7b2a863b68 100644 (file)
@@ -118,10 +118,6 @@ signals:
   /// theName the operation name
   /// theFeature the operation argument
   void launchOperation(std::string theName, FeaturePtr theFeature);
-  /// signal about the focus activated
-  /// theName the attribute name
-  void focusActivated(const std::string& theAttibuteName);
-
   /// Signal about the feature construing is finished
   /// \param theFeature the result feature
   /// \param theMode the mode of the feature modification
index 69d071480327133372d9d3be5282f5f438a8baf1..767e0dfcc8b1682dab0140468572ede859ee1cea 100644 (file)
@@ -97,6 +97,9 @@ void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& t
       connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
               this, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
 
+      connect(*anIt, SIGNAL(activated(ModuleBase_ModelWidget*)),
+              this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)));
+
       ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
       if (aPointWidget)
         connect(aPointWidget, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
@@ -115,10 +118,7 @@ void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& t
         setTabOrder(anOkBtn, aCancelBtn);
       }
     }
-    ModuleBase_ModelWidget* aWidget = theWidgets.first();
-    if (aWidget) {
-      activateWidget(aWidget);
-    }
+    onActivateNextWidget(0);
   }
 }
 
@@ -158,50 +158,20 @@ void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
   repaint();
 }
 
-void XGUI_PropertyPanel::onFocusActivated(const std::string& theAttributeName)
-{
-  if (theAttributeName == XGUI::PROP_PANEL_OK) {
-    QPushButton* aBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
-    aBtn->setFocus();
-  }
-  if (theAttributeName == XGUI::PROP_PANEL_CANCEL) {
-    QPushButton* aBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
-    aBtn->setFocus();
-  }
-  else {
-    foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
-      if (eachWidget->canFocusTo(theAttributeName)) {
-        eachWidget->focusTo();
-        break;
-      }
-    }
-  }
-}
-
 void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
 {
   ModuleBase_ModelWidget* aNextWidget = 0;
-
   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
                                                  aLast = myWidgets.end();
-  for (;anIt != aLast; anIt++)
+  bool isFoundWidget = false;
+  for (;anIt != aLast && !aNextWidget; anIt++)
   {
-    if ((*anIt) == theWidget) {
-      anIt++;
-      if (anIt != aLast)
+    if (isFoundWidget || !theWidget) {
+      if ((*anIt)->focusTo()) {
         aNextWidget = *anIt;
-      break;
+      }
     }
+    isFoundWidget = (*anIt) == theWidget;
   }
-  activateWidget(aNextWidget);
-}
-
-void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
-{
-  emit widgetActivated(theWidget);
-  // it is important that the signal widgetActivated goes before the focusTo() calling
-  // in order to handle next possible signal in the focusTo() method
-  // (e.g. the widget editor sends a signal about the widget deactivation)
-  if (theWidget)
-    theWidget->focusTo();
+  emit widgetActivated(aNextWidget);
 }
index 764575dd89889451eeb7ed50205f3cb1c48541e3..74c3c5fba03fbd2186504843b60f7249686b2ee1 100644 (file)
@@ -36,9 +36,6 @@ protected:
 
 public slots:
   void updateContentWidget(FeaturePtr theFeature);
-  /// slot to set the focus to the widget visualized an attribute with the given name
-  /// \param theAttributteName
-  void onFocusActivated(const std::string& theAttributeName);
   /// slot to activate the next widget in the property panel
   /// \param theWidget a widget. The next widget should be activated
   void onActivateNextWidget(ModuleBase_ModelWidget* theWidget);
@@ -57,12 +54,6 @@ signals:
   /// \param the attribute of the feature
   void storedPoint2D(FeaturePtr theFeature, const std::string& theAttribute);
 
-protected:
-  /// Activate the widget, which means the focus on the widget.
-  /// The signal about the widget activation is emitted
-  /// \param theWidget
-  void activateWidget(ModuleBase_ModelWidget* theWidget);
-
 private:
   QWidget* myCustomWidget;