- if (myMainLayout->count() == 0)
- return;
- int aStretchIdx = myMainLayout->count() - 1;
- bool hasStretch = myMainLayout->itemAt(aStretchIdx)->spacerItem() != NULL;
- QLayoutItem* aChild;
- if (isEnabled) {
- if (!hasStretch) myMainLayout->addStretch(1);
- } else if (hasStretch) {
- aChild = myMainLayout->takeAt(aStretchIdx);
- delete aChild;
+ // 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<QToolButton*>(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;
+ }
+ }
+ }
+ else { // backward by SHIFT + Tab
+ QToolButton* anOkBtn = findChild<QToolButton*>(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<QToolButton*>(PROP_PANEL_CANCEL);
+ ModuleBase_Tools::setFocus(aCancelBtn, "XGUI_PropertyPanel::focusNextPrevChild()");
+ isChangedFocus = true;
+ }
+ }