Salome HOME
Pass focus to children widgets (pages)
authorsbh <sergey.belash@opencascade.com>
Fri, 6 Mar 2015 18:45:14 +0000 (21:45 +0300)
committersbh <sergey.belash@opencascade.com>
Fri, 6 Mar 2015 18:45:14 +0000 (21:45 +0300)
src/ModuleBase/ModuleBase_PageBase.cpp
src/ModuleBase/ModuleBase_PageBase.h
src/ModuleBase/ModuleBase_PageGroupBox.cpp
src/ModuleBase/ModuleBase_PageGroupBox.h
src/ModuleBase/ModuleBase_PageWidget.cpp
src/ModuleBase/ModuleBase_PageWidget.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetToolbox.cpp
src/ModuleBase/ModuleBase_WidgetToolbox.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_Workshop.cpp

index 5adaebf34b668d7f365c883dae5cdeaef8d90488..dac665edd3fbb0fd089e2c90e43ca7c14156d3b2 100644 (file)
@@ -22,6 +22,11 @@ ModuleBase_PageBase::~ModuleBase_PageBase()
 
 }
 
+QWidget* ModuleBase_PageBase::pageWidget()
+{
+  return dynamic_cast<QWidget*>(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_ModelWidget*> ModuleBase_PageBase::modelWidgets()
 {
   return myWidgetList;
 }
+
+void ModuleBase_PageBase::alignToTop()
+{
+  bool hasExpanding = false;
+  QList<QWidget *> 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();
+  }
+}
index 3b8bdf35225652ae1d973a1fd1e04d397bc5e9bb..7f8f054ca822a143c30b25beff11a25f9335224d 100644 (file)
@@ -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<ModuleBase_ModelWidget*> 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<ModuleBase_ModelWidget*> myWidgetList;
index 1043a02fb35623f181835357bec29666f381fc88..f16e4d728b2ef247f4afeaf3140dad314b8003bf 100644 (file)
@@ -23,6 +23,10 @@ ModuleBase_PageGroupBox::~ModuleBase_PageGroupBox()
 {
 }
 
+void ModuleBase_PageGroupBox::addPageStretch()
+{
+}
+
 void ModuleBase_PageGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
 {
   const int kCol = 0;
index dfc1adae1755f46fda48b6fea32722381759227f..fd10f001b23ec99f5185488d7c6e7c0790d78f67 100644 (file)
@@ -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;
index a75a6cfba22b3dc5ca8ba4057730b7cca8a0bc73..f49e53eea1fed66f299c38036c746a983ba82af2 100644 (file)
@@ -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()
index a39d66021de96667fbb31d8017cbde7ca12650e5..eb21a6daac9dab25ecc7ce56a3682db78bdd714a 100644 (file)
@@ -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;
index 25f3c1979f87c9ecbfb1ddf35c780104317705a8..023c728a9820d246da78e29c69444f4a470fbdb3 100644 (file)
@@ -73,26 +73,19 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
   if (!myWidgetApi->toChildWidget())
     return;
 
-  //bool isStretchLayout = false;
-  QWidget* aPageWidget = dynamic_cast<QWidget*>(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<ModuleBase_WidgetToolbox*>(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<QWidget *> aListToCheck;
-  aListToCheck << theParent;
-  ModuleBase_ModelWidget* aModelWidget = qobject_cast<ModuleBase_ModelWidget*>(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
index aeab11bbb0738f6402ea3fe7e44f5f6ca9224a2f..616a5c357972c3468911cdf69d6017799ec64d66 100644 (file)
@@ -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<QFrame*>(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<QWidget*> 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();
 }
index 867623105adabfda81f8439cef0b90e85841df58..2e106a720903b35294ad6a48600260e28b3ca633 100644 (file)
@@ -26,9 +26,11 @@ class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget
   virtual QList<QWidget*> 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<ModuleBase_PageBase*> myPages;
 };
 
 #endif /* MODULEBASE_WIDGETTOOLBOX_H_ */
index 0f02c5d933d964f5d5358477f45e01a29814dada..0e5fcdf6008302f0de157cacc66a63239eea714c 100644 (file)
@@ -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();
   }
index 805b3b1bd78decb4b0f13e63efcc8332bceeefc4..b50412cc798ec06e62fd5e15a12fd5c3bd87b9ab 100644 (file)
@@ -53,6 +53,7 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_IViewer.h>
 #include<ModuleBase_FilterFactory.h>
+#include <ModuleBase_PageBase.h>
 
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>