X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_PropertyPanel.cpp;h=d44c7d1d589f78060a93bb8a1dddd7a12be493d8;hb=7e01af6cfeb76252b3fd062f6a2f35115994a422;hp=1779431f5511a3dc204568139f8b334c7e9f72eb;hpb=5be4a656f7f45e94dc40385cf164a88375e4403b;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 1779431f5..d44c7d1d5 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -9,9 +9,12 @@ #include #include +#include //#include #include #include +#include +#include #include #include @@ -29,9 +32,12 @@ #include #endif -XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) +XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent, XGUI_OperationMgr* theMgr) : ModuleBase_IPropertyPanel(theParent), - myActiveWidget(NULL) + myActiveWidget(NULL), + myPreselectionWidget(NULL), + myPanelPage(NULL), + myOperationMgr(theMgr) { this->setWindowTitle(tr("Property Panel")); QAction* aViewAct = this->toggleViewAction(); @@ -39,10 +45,10 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }"); QWidget* aContent = new QWidget(this); - myMainLayout = new QGridLayout(aContent); + QGridLayout* aMainLayout = new QGridLayout(aContent); const int kPanelColumn = 0; int aPanelRow = 0; - myMainLayout->setContentsMargins(3, 3, 3, 3); + aMainLayout->setContentsMargins(3, 3, 3, 3); this->setWidget(aContent); QFrame* aFrm = new QFrame(aContent); @@ -50,7 +56,9 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) aFrm->setFrameShape(QFrame::Panel); QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); ModuleBase_Tools::zeroMargins(aBtnLay); - myMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn); + aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn); + + myHeaderWidget = aFrm; QStringList aBtnNames; aBtnNames << QString(PROP_PANEL_HELP) @@ -64,10 +72,9 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) } aBtnLay->insertStretch(1, 1); - myCustomWidget = new QWidget(aContent); - myCustomWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); - myMainLayout->addWidget(myCustomWidget, aPanelRow, kPanelColumn); - setStretchEnabled(true); + myPanelPage = new ModuleBase_PageWidget(aContent); + myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); + aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn); } XGUI_PropertyPanel::~XGUI_PropertyPanel() @@ -78,8 +85,24 @@ 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. + /// 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) { + aWidget->blockSignals(true); + } + } + myWidgets.clear(); - qDeleteAll(myCustomWidget->children()); + myPanelPage->clearPage(); myActiveWidget = NULL; setWindowTitle(tr("Property Panel")); } @@ -88,26 +111,13 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& t { myWidgets = theWidgets; if (theWidgets.empty()) return; - QList::const_iterator anIt = theWidgets.begin(); - for (; anIt != theWidgets.end(); anIt++) { - connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*))); - connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), - this, SLOT(activateNextWidget(ModuleBase_ModelWidget*))); - connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)), - this, SLOT(activateWidget(ModuleBase_ModelWidget*))); - } - ModuleBase_ModelWidget* aLastWidget = theWidgets.last(); - if (aLastWidget) { - QList aControls = aLastWidget->getControls(); - if (!aControls.empty()) { - QWidget* aLastControl = aControls.last(); - - QToolButton* anOkBtn = findChild(PROP_PANEL_OK); - QToolButton* aCancelBtn = findChild(PROP_PANEL_CANCEL); - - setTabOrder(aLastControl, anOkBtn); - setTabOrder(anOkBtn, aCancelBtn); - } + foreach (ModuleBase_ModelWidget* aWidget, theWidgets) { + connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)), + this, SLOT(activateWidget(ModuleBase_ModelWidget*))); + connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), + this, SLOT(activateNextWidget(ModuleBase_ModelWidget*))); + connect(aWidget, SIGNAL(keyReleased(QKeyEvent*)), + this, SIGNAL(keyReleased(QKeyEvent*))); } } @@ -116,9 +126,9 @@ const QList& XGUI_PropertyPanel::modelWidgets() const return myWidgets; } -QWidget* XGUI_PropertyPanel::contentWidget() +ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget() { - return myCustomWidget; + return static_cast(myPanelPage); } void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) @@ -128,9 +138,9 @@ void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) return; if (theFeature->isAction() || !theFeature->data()) return; - foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) - { - eachWidget->setFeature(theFeature); + foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) { + if (!eachWidget->feature().get()) + eachWidget->setFeature(theFeature); eachWidget->restoreValue(); } // the repaint is used here to immediately react in GUI to the values change. @@ -144,30 +154,76 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) activateWidget(NULL); return; } - ModuleBase_ModelWidget* aNextWidget = 0; QList::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end(); bool isFoundWidget = false; - for (; anIt != aLast && !aNextWidget; anIt++) { + activateWindow(); + for (; anIt != aLast; anIt++) { if (isFoundWidget || !theWidget) { if ((*anIt)->focusTo()) { - aNextWidget = *anIt; + return; } } - isFoundWidget = (*anIt) == theWidget; + isFoundWidget = 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); - //} + activateWidget(NULL); } -void XGUI_PropertyPanel::setStretchEnabled(bool isEnabled) +bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext) { - int aStretchIdx = myMainLayout->rowCount() - 1; - if (aStretchIdx < 0) - return; - myMainLayout->setRowStretch(aStretchIdx, isEnabled ? 1 : 0); + // 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) + aFirstControl->setFocus(); + 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; + } + } + } + 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) + aLastControl->setFocus(); + 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); + aCancelBtn->setFocus(); + isChangedFocus = true; + } + } + } + + if (!isChangedFocus) + isChangedFocus = ModuleBase_IPropertyPanel::focusNextPrevChild(theIsNext); + + return isChangedFocus; } void XGUI_PropertyPanel::activateNextWidget() @@ -177,24 +233,44 @@ 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 (theWidget == myActiveWidget) - return; + 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 false; + } + std::string aPreviosAttributeID; if(myActiveWidget) { + aPreviosAttributeID = myActiveWidget->attributeID(); myActiveWidget->deactivate(); myActiveWidget->setHighlighted(false); } if(theWidget) { - if (theWidget) - emit beforeWidgetActivated(theWidget); - theWidget->activate(); + emit beforeWidgetActivated(theWidget); theWidget->setHighlighted(true); + 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(); } void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled) @@ -229,3 +305,27 @@ void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr) aBtn->setDefaultAction(anAct); } } + +ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const +{ + return myPreselectionWidget; +} + +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); +}