From fce68b066f107f70d2d18a2d028e558dcbb1c3f8 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 25 Jun 2014 20:09:37 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc 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). --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 8 +-- src/ModuleBase/ModuleBase_ModelWidget.h | 7 +-- .../ModuleBase_WidgetDoubleValue.cpp | 4 ++ src/ModuleBase/ModuleBase_WidgetEditor.cpp | 4 +- src/ModuleBase/ModuleBase_WidgetEditor.h | 3 +- src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 4 ++ src/PartSet/PartSet_Module.cpp | 5 -- .../PartSet_OperationFeatureCreate.cpp | 29 ----------- src/PartSet/PartSet_OperationFeatureCreate.h | 6 --- src/PartSet/PartSet_OperationSketchBase.h | 4 -- src/XGUI/XGUI_PropertyPanel.cpp | 52 ++++--------------- src/XGUI/XGUI_PropertyPanel.h | 9 ---- 12 files changed, 28 insertions(+), 107 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index cd56f06c3..720f08933 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -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 aControls = getControls(); QList::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 diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 78680ec3b..5c8e9da51 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index e4a2505f3..ccbb0ad7e 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -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; } diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 694e5a809..dbbe9fd5d 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -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) diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.h b/src/ModuleBase/ModuleBase_WidgetEditor.h index e75d4cebd..4585bdbbc 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetEditor.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 58130a384..5f6c1e857 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -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; } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 1266a0cb1..2ba50835c 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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(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&))); } diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 05c00f017..e5a54cb38 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -149,13 +149,6 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle } } } - /*if (feature()->getKind() == SKETCH_ARC_KIND) { - boost::shared_ptr anArcPrs = - boost::dynamic_pointer_cast(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 anArcPrs = - boost::dynamic_pointer_cast(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(myActiveWidget) || diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index 606bdc3bf..f4ecd643a 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -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; diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index cb51f46b9..9e4a72cba 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -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 diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 69d071480..767e0dfcc 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -97,6 +97,9 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& 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(*anIt); if (aPointWidget) connect(aPointWidget, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)), @@ -115,10 +118,7 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& 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(XGUI::PROP_PANEL_OK); - aBtn->setFocus(); - } - if (theAttributeName == XGUI::PROP_PANEL_CANCEL) { - QPushButton* aBtn = findChild(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::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); } diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 764575dd8..74c3c5fba 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -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; -- 2.39.2