From: sbh Date: Fri, 6 Mar 2015 18:45:14 +0000 (+0300) Subject: Pass focus to children widgets (pages) X-Git-Tag: V_1.1.0~146 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=806d6cb3a4f7980426bc63d7c6f1d9c87be260a4;p=modules%2Fshaper.git Pass focus to children widgets (pages) --- diff --git a/src/ModuleBase/ModuleBase_PageBase.cpp b/src/ModuleBase/ModuleBase_PageBase.cpp index 5adaebf34..dac665edd 100644 --- a/src/ModuleBase/ModuleBase_PageBase.cpp +++ b/src/ModuleBase/ModuleBase_PageBase.cpp @@ -22,6 +22,11 @@ ModuleBase_PageBase::~ModuleBase_PageBase() } +QWidget* ModuleBase_PageBase::pageWidget() +{ + return dynamic_cast(this); +} + void ModuleBase_PageBase::addModelWidget(ModuleBase_ModelWidget* theWidget) { placeModelWidget(theWidget); @@ -35,7 +40,14 @@ void ModuleBase_PageBase::addPageWidget(ModuleBase_PageBase* thePage) void ModuleBase_PageBase::clearPage() { - qDeleteAll(pageLayout()->children()); + QLayoutItem *aChild; + while ((aChild = pageLayout()->takeAt(0)) != 0) { + if(aChild->widget()) { + aChild->widget()->deleteLater(); + } else { + delete aChild; + } + } myWidgetList.clear(); } @@ -52,3 +64,23 @@ QList ModuleBase_PageBase::modelWidgets() { return myWidgetList; } + +void ModuleBase_PageBase::alignToTop() +{ + bool hasExpanding = false; + QList aListToCheck; + ModuleBase_ModelWidget* aModelWidget; + foreach(aModelWidget, myWidgetList) { + aListToCheck << aModelWidget->getControls(); + } + foreach(QWidget* eachWidget, aListToCheck) { + QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy(); + if(aVPolicy & QSizePolicy::ExpandFlag) { + hasExpanding = true; + break; + } + } + if(!hasExpanding) { + addPageStretch(); + } +} diff --git a/src/ModuleBase/ModuleBase_PageBase.h b/src/ModuleBase/ModuleBase_PageBase.h index 3b8bdf352..7f8f054ca 100644 --- a/src/ModuleBase/ModuleBase_PageBase.h +++ b/src/ModuleBase/ModuleBase_PageBase.h @@ -23,6 +23,7 @@ class MODULEBASE_EXPORT ModuleBase_PageBase public: ModuleBase_PageBase(); virtual ~ModuleBase_PageBase(); + QWidget* pageWidget(); void addModelWidget(ModuleBase_ModelWidget* theWidget); void addPageWidget(ModuleBase_PageBase* theWidget); @@ -30,11 +31,13 @@ class MODULEBASE_EXPORT ModuleBase_PageBase void clearPage(); void takeFocus(); QList modelWidgets(); + void alignToTop(); protected: virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget) = 0; virtual void placePageWidget(ModuleBase_PageBase* theWidget) = 0; virtual QLayout* pageLayout() = 0; + virtual void addPageStretch() = 0; private: QList myWidgetList; diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.cpp b/src/ModuleBase/ModuleBase_PageGroupBox.cpp index 1043a02fb..f16e4d728 100644 --- a/src/ModuleBase/ModuleBase_PageGroupBox.cpp +++ b/src/ModuleBase/ModuleBase_PageGroupBox.cpp @@ -23,6 +23,10 @@ ModuleBase_PageGroupBox::~ModuleBase_PageGroupBox() { } +void ModuleBase_PageGroupBox::addPageStretch() +{ +} + void ModuleBase_PageGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget) { const int kCol = 0; diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.h b/src/ModuleBase/ModuleBase_PageGroupBox.h index dfc1adae1..fd10f001b 100644 --- a/src/ModuleBase/ModuleBase_PageGroupBox.h +++ b/src/ModuleBase/ModuleBase_PageGroupBox.h @@ -31,6 +31,7 @@ class MODULEBASE_EXPORT ModuleBase_PageGroupBox : public QGroupBox, public Modul virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget); virtual void placePageWidget(ModuleBase_PageBase* theWidget); virtual QLayout* pageLayout(); + virtual void addPageStretch(); private: QGridLayout* myMainLayout; diff --git a/src/ModuleBase/ModuleBase_PageWidget.cpp b/src/ModuleBase/ModuleBase_PageWidget.cpp index a75a6cfba..f49e53eea 100644 --- a/src/ModuleBase/ModuleBase_PageWidget.cpp +++ b/src/ModuleBase/ModuleBase_PageWidget.cpp @@ -23,11 +23,16 @@ ModuleBase_PageWidget::~ModuleBase_PageWidget() { } +void ModuleBase_PageWidget::addPageStretch() +{ + myMainLayout->setRowStretch(myMainLayout->rowCount(), 1); +} + void ModuleBase_PageWidget::placeModelWidget(ModuleBase_ModelWidget* theWidget) { const int kCol = 0; const int kRow = myMainLayout->count(); - myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft); + myMainLayout->addWidget(theWidget, kRow, kCol); } void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget) @@ -41,7 +46,7 @@ void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget) } const int kCol = 0; const int kRow = myMainLayout->count(); - myMainLayout->addWidget(aWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft); + myMainLayout->addWidget(aWidget, kRow, kCol);//, Qt::AlignTop | Qt::AlignLeft); } QLayout* ModuleBase_PageWidget::pageLayout() diff --git a/src/ModuleBase/ModuleBase_PageWidget.h b/src/ModuleBase/ModuleBase_PageWidget.h index a39d66021..eb21a6daa 100644 --- a/src/ModuleBase/ModuleBase_PageWidget.h +++ b/src/ModuleBase/ModuleBase_PageWidget.h @@ -30,6 +30,7 @@ class MODULEBASE_EXPORT ModuleBase_PageWidget : public QFrame, public ModuleBase virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget); virtual void placePageWidget(ModuleBase_PageBase* theWidget); virtual QLayout* pageLayout(); + virtual void addPageStretch(); private: QGridLayout* myMainLayout; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 25f3c1979..023c728a9 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -73,26 +73,19 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage) if (!myWidgetApi->toChildWidget()) return; - //bool isStretchLayout = false; - QWidget* aPageWidget = dynamic_cast(thePage); - if(!aPageWidget) { - #ifdef _DEBUG - std::cout << "ModuleBase_WidgetFactory::createWidget: can not reinterpret_cast thePage" << std::endl; - #endif - } do { //Iterate over each node std::string aWdgType = myWidgetApi->widgetType(); // Create PageGroup TODO: extract if (myWidgetApi->isGroupBoxWidget()) { //if current widget is groupbox (container) process it's children recursively QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); - ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(aPageWidget); + ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(thePage->pageWidget()); aPage->setTitle(aGroupName); createWidget(aPage); thePage->addPageWidget(aPage); } else { // Create a ModelWidget - ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, aPageWidget); + ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, thePage->pageWidget()); if (aWidget) { if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) { thePage->addModelWidget(aWidget); @@ -116,36 +109,14 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage) aSwitch->addPage(aCasePageWidget, aPageName); } else if (aWdgType == WDG_TOOLBOX) { ModuleBase_WidgetToolbox* aToolbox = qobject_cast(aWidget); - aToolbox->addPage(aCasePageWidget, aPageName, aCaseId); + aToolbox->addPage(aPage, aPageName, aCaseId); } } while (myWidgetApi->toNextWidget()); } } -// if (aWidget && !isStretchLayout) { -// isStretchLayout = !hasExpandingControls(aWidget); -// } } while (myWidgetApi->toNextWidget()); -// if (isStretchLayout) { -// aWidgetLay->addStretch(1); -// } -} -bool ModuleBase_WidgetFactory::hasExpandingControls(QWidget* theParent) -{ - bool result = false; - QList aListToCheck; - aListToCheck << theParent; - ModuleBase_ModelWidget* aModelWidget = qobject_cast(theParent); - if(aModelWidget) { - aListToCheck << aModelWidget->getControls(); - } - foreach(QWidget* eachWidget, aListToCheck) { - QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy(); - if(aVPolicy & QSizePolicy::ExpandFlag) { - result = true; - } - } - return result; + thePage->alignToTop(); } ModuleBase_ModelWidget* ModuleBase_WidgetFactory diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp index aeab11bbb..616a5c357 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp @@ -29,9 +29,6 @@ ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Con "border-color:#fff #505050 #505050 #fff;}"; myToolBox->setStyleSheet(css); // default vertical size policy is preferred - QSizePolicy aSizePolicy = myToolBox->sizePolicy(); - aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding); - myToolBox->setSizePolicy(aSizePolicy); aMainLayout->addWidget(myToolBox); connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged())); @@ -41,11 +38,15 @@ ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox() { } -int ModuleBase_WidgetToolbox::addPage(QWidget* theWidget, +int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage, const QString& theName, const QString& theCaseId) { myCaseIds << theCaseId; - return myToolBox->addItem(theWidget, theName); + myPages << thePage; + QFrame* aFrame = dynamic_cast(thePage); + aFrame->setFrameShape(QFrame::Box); + aFrame->setFrameStyle(QFrame::Sunken); + return myToolBox->addItem(aFrame, theName); } bool ModuleBase_WidgetToolbox::restoreValue() @@ -62,6 +63,7 @@ bool ModuleBase_WidgetToolbox::restoreValue() bool isSignalsBlocked = myToolBox->blockSignals(true); myToolBox->setCurrentIndex(idx); myToolBox->blockSignals(isSignalsBlocked); + focusTo(); return true; } @@ -74,7 +76,16 @@ QList ModuleBase_WidgetToolbox::getControls() const bool ModuleBase_WidgetToolbox::focusTo() { - return false; + int idx = myToolBox->currentIndex(); + if (idx > myPages.count()) + return false; + myPages[idx]->takeFocus(); + repaint(); + return true; +} + +void ModuleBase_WidgetToolbox::activateCustom() +{ } bool ModuleBase_WidgetToolbox::storeValueCustom() const @@ -92,4 +103,5 @@ bool ModuleBase_WidgetToolbox::storeValueCustom() const void ModuleBase_WidgetToolbox::onPageChanged() { storeValue(); + focusTo(); } diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.h b/src/ModuleBase/ModuleBase_WidgetToolbox.h index 867623105..2e106a720 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.h +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.h @@ -26,9 +26,11 @@ class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget virtual QList getControls() const; virtual bool focusTo(); - int addPage(QWidget* theWidget, const QString& theName, const QString& theCaseId); + int addPage(ModuleBase_PageBase* theWidget, + const QString& theName, const QString& theCaseId); protected: + virtual void activateCustom(); virtual bool storeValueCustom() const; protected slots: @@ -37,6 +39,7 @@ class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget private: QToolBox* myToolBox; QStringList myCaseIds; + QList myPages; }; #endif /* MODULEBASE_WIDGETTOOLBOX_H_ */ diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 0f02c5d93..0e5fcdf60 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -131,8 +131,7 @@ void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) return; if (theFeature->isAction() || !theFeature->data()) return; - foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) - { + foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) { eachWidget->setFeature(theFeature); eachWidget->restoreValue(); } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 805b3b1bd..b50412cc7 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include