X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_PropertyPanel.cpp;h=762bde305e20d92063faad3d91103046076213a0;hb=59a007784d1e103bcb352c515eb6feafa170f1ff;hp=89cc82a2718e69d6f46a992c05067d643a40fe76;hpb=b2671a2abbd0c3101a3b963c91dd9dbc5b6018bb;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp old mode 100644 new mode 100755 index 89cc82a27..762bde305 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -9,12 +9,16 @@ #include #include +#include //#include #include #include #include #include +#include +#include + #include #include #include @@ -31,11 +35,12 @@ #include #endif -XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) +XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent, XGUI_OperationMgr* theMgr) : ModuleBase_IPropertyPanel(theParent), myActiveWidget(NULL), myPreselectionWidget(NULL), - myPanelPage(NULL) + myPanelPage(NULL), + myOperationMgr(theMgr) { this->setWindowTitle(tr("Property Panel")); QAction* aViewAct = this->toggleViewAction(); @@ -84,14 +89,19 @@ void XGUI_PropertyPanel::cleanContent() if (myActiveWidget) myActiveWidget->deactivate(); - // as the widgets are deleted later, it is important that the signals - // of these widgets are not processed. An example of the error is issue 986. + /// as the widgets are deleted later, it is important that the signals + /// of these widgets are not processed. An example of the error is issue 986. + /// In the given case, the property panel is firstly filled by new widgets + /// of restarted operation and after that the mouse release signal come from + /// the widget of the previous operation (Point2d widget about mouse is released + /// and focus is out of this widget) QList::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end(); for (; anIt != aLast; anIt++) { QWidget* aWidget = *anIt; - if (aWidget) + if (aWidget) { aWidget->blockSignals(true); + } } myWidgets.clear(); @@ -111,19 +121,9 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& t this, SLOT(activateNextWidget(ModuleBase_ModelWidget*))); connect(aWidget, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*))); - } - ModuleBase_ModelWidget* aLastWidget = theWidgets.last(); - if (aLastWidget) { - QList aControls = aLastWidget->getControls(); - if (!aControls.empty()) { - QWidget* aLastControl = aControls.last(); + connect(aWidget, SIGNAL(enterClicked()), + this, SIGNAL(enterClicked())); - QToolButton* anOkBtn = findChild(PROP_PANEL_OK); - QToolButton* aCancelBtn = findChild(PROP_PANEL_CANCEL); - - setTabOrder(aLastControl, anOkBtn); - setTabOrder(anOkBtn, aCancelBtn); - } } } @@ -134,7 +134,6 @@ const QList& XGUI_PropertyPanel::modelWidgets() const ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget() { - return static_cast(myPanelPage); } @@ -161,23 +160,83 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) activateWidget(NULL); return; } - ModuleBase_ModelWidget* aNextWidget = 0; + ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); + QList::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end(); bool isFoundWidget = false; - activateWindow(); - for (; anIt != aLast && !aNextWidget; anIt++) { + ModuleBase_Tools::activateWindow(this, "XGUI_PropertyPanel::activateNextWidget()"); + for (; anIt != aLast; anIt++) { + ModuleBase_ModelWidget* aCurrentWidget = *anIt; if (isFoundWidget || !theWidget) { - if ((*anIt)->focusTo()) { - aNextWidget = *anIt; + + if (!aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID())) + continue; // this attribute is not participated in the current case + + if (aCurrentWidget->focusTo()) { + return; + } + } + isFoundWidget = isFoundWidget || (*anIt) == theWidget; + } + activateWidget(NULL); +} + +bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext) +{ + // it wraps the Tabs clicking to follow in the chain: + // controls, last control, Apply, Cancel, first control, controls + + bool isChangedFocus = false; + if (theIsNext) { // forward by Tab + QToolButton* aCancelBtn = findChild(PROP_PANEL_CANCEL); + if (aCancelBtn->hasFocus()) { + // after cancel, the first control should be focused + QWidget* aFirstControl = 0; + for (int i = 0, aSize = myWidgets.size(); i < aSize && !aFirstControl; i++) + aFirstControl = myWidgets[i]->getControlAcceptingFocus(true); + if (aFirstControl) + ModuleBase_Tools::setFocus(aFirstControl, "XGUI_PropertyPanel::focusNextPrevChild()"); + isChangedFocus = true; + } + else { + // after the last control, the Apply button should be focused + QWidget* aLastControl = 0; + for (int i = myWidgets.size()-1; i >= 0 && !aLastControl; i--) + aLastControl = myWidgets[i]->getControlAcceptingFocus(false); + if (aLastControl && aLastControl->hasFocus()) { + setFocusOnOkButton(); + isChangedFocus = true; } } - isFoundWidget = (*anIt) == theWidget; } - // Normaly focusTo is enough to activate widget - // here is a special case on mouse click in the viewer - if(aNextWidget == NULL) { - activateWidget(aNextWidget); + else { // backward by SHIFT + Tab + QToolButton* anOkBtn = findChild(PROP_PANEL_OK); + if (anOkBtn->hasFocus()) { + // after Apply, the last control should be focused + QWidget* aLastControl = 0; + for (int i = myWidgets.size()-1; i >= 0 && !aLastControl; i--) + aLastControl = myWidgets[i]->getControlAcceptingFocus(false); + if (aLastControl) + ModuleBase_Tools::setFocus(aLastControl, "XGUI_PropertyPanel::focusNextPrevChild()"); + isChangedFocus = true; + } + else { + // after the first control, the Cancel button should be focused + QWidget* aFirstControl = 0; + for (int i = 0, aSize = myWidgets.size(); i < aSize && !aFirstControl; i++) + aFirstControl = myWidgets[i]->getControlAcceptingFocus(true); + if (aFirstControl && aFirstControl->hasFocus()) { + QToolButton* aCancelBtn = findChild(PROP_PANEL_CANCEL); + ModuleBase_Tools::setFocus(aCancelBtn, "XGUI_PropertyPanel::focusNextPrevChild()"); + isChangedFocus = true; + } + } } + + if (!isChangedFocus) + isChangedFocus = ModuleBase_IPropertyPanel::focusNextPrevChild(theIsNext); + + return isChangedFocus; } void XGUI_PropertyPanel::activateNextWidget() @@ -186,12 +245,29 @@ void XGUI_PropertyPanel::activateNextWidget() } void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget) +{ + std::string aPreviosAttributeID; + if(myActiveWidget) + aPreviosAttributeID = myActiveWidget->attributeID(); + + // Avoid activation of already actve widget. It could happen on focusIn event many times + if (setActiveWidget(theWidget)) { + emit widgetActivated(myActiveWidget); + if (!myActiveWidget && !isEditingMode()) { + emit noMoreWidgets(aPreviosAttributeID); + } + } +} + +bool XGUI_PropertyPanel::setActiveWidget(ModuleBase_ModelWidget* theWidget) { // Avoid activation of already actve widget. It could happen on focusIn event many times if (theWidget == myActiveWidget) { - return; + return false; } + std::string aPreviosAttributeID; if(myActiveWidget) { + aPreviosAttributeID = myActiveWidget->attributeID(); myActiveWidget->deactivate(); myActiveWidget->setHighlighted(false); } @@ -201,17 +277,13 @@ void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget) theWidget->activate(); } myActiveWidget = theWidget; - if (myActiveWidget) { - emit widgetActivated(theWidget); - } else if (!isEditingMode()) { - emit noMoreWidgets(); - } + return true; } void XGUI_PropertyPanel::setFocusOnOkButton() { QToolButton* anOkBtn = findChild(PROP_PANEL_OK); - anOkBtn->setFocus(); + ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::setFocusOnOkButton()"); } void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled) @@ -256,3 +328,17 @@ void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget { myPreselectionWidget = theWidget; } + + +void XGUI_PropertyPanel::closeEvent(QCloseEvent* theEvent) +{ + ModuleBase_Operation* aOp = myOperationMgr->currentOperation(); + if (aOp) { + if (myOperationMgr->canStopOperation(aOp)) { + myOperationMgr->abortAllOperations(); + theEvent->accept(); + } else + theEvent->ignore(); + } else + ModuleBase_IPropertyPanel::closeEvent(theEvent); +}