Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetToolbox.cpp
index 616a5c357972c3468911cdf69d6017799ec64d66..81b92a04469ea5377a18636a6ad5c25e45d268bd 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 /*
  * ModuleBase_WidgetToolbox.cpp
  *
@@ -7,21 +8,34 @@
 
 #include <ModuleBase_WidgetToolbox.h>
 #include <ModuleBase_PageBase.h>
+#include <ModuleBase_ModelWidget.h>
 #include <ModuleBase_Tools.h>
+#include <ModuleBase_ToolBox.h>
 
 #include <ModelAPI_AttributeString.h>
 
 #include <QWidget>
+#include <QList>
 #include <QVBoxLayout>
+#include <QIcon>
 
-ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
-                                                   const std::string& theParentId)
-: ModuleBase_ModelWidget(theParent, theData, theParentId)
+ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, 
+                                                   const Config_WidgetAPI* theData)
+: ModuleBase_PagedContainer(theParent, theData)
 {
   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aMainLayout);
-  myToolBox = new QToolBox(this);
+
+  bool aHasContainerParent = false;
+  QWidget* aParent = dynamic_cast<QWidget*>(parent());
+  while(aParent && !aHasContainerParent) {
+    ModuleBase_PagedContainer* aPagedContainer = dynamic_cast<ModuleBase_PagedContainer*>(aParent);
+    aHasContainerParent = aPagedContainer;
+    aParent = dynamic_cast<QWidget*>(aParent->parent());
+  }
+  myToolBox = new ModuleBase_ToolBox(this, aHasContainerParent);
   // Dark-grey rounded tabs with button-like border #and bold font
+  // TODO: apply style to custom widget
   QString css = "QToolBox::tab{background-color:#c8c8c8;"
                               "border-radius:5px;"
                               "border:1px inset;"
@@ -39,69 +53,26 @@ ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
 }
 
 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
-                                      const QString& theName, const QString& theCaseId)
+                                      const QString& theName,
+                                      const QString& theCaseId,
+                                      const QPixmap& theIcon )
 {
-  myCaseIds << theCaseId;
-  myPages << thePage;
+  ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon);
   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
-  aFrame->setFrameShape(QFrame::Box);
-  aFrame->setFrameStyle(QFrame::Sunken);
-  return myToolBox->addItem(aFrame, theName);
-}
-
-bool ModuleBase_WidgetToolbox::restoreValue()
-{
-  // A rare case when plugin was not loaded.
-  if(!myFeature)
-    return false;
-  DataPtr aData = myFeature->data();
-  AttributeStringPtr aStringAttr = aData->string(attributeID());
-  QString aCaseId = QString::fromStdString(aStringAttr->value());
-  int idx = myCaseIds.indexOf(aCaseId);
-  if (idx == -1)
-    return false;
-  bool isSignalsBlocked = myToolBox->blockSignals(true);
-  myToolBox->setCurrentIndex(idx);
-  myToolBox->blockSignals(isSignalsBlocked);
-  focusTo();
-  return true;
+  myToolBox->addItem(aFrame, theName, theIcon );
+  return myToolBox->count();
 }
 
-QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
+int ModuleBase_WidgetToolbox::currentPageIndex() const
 {
-  QList<QWidget*> aList;
-  aList << myToolBox;
-  return aList;
+  return myToolBox->currentIndex();
 }
 
-bool ModuleBase_WidgetToolbox::focusTo()
-{
-  int idx = myToolBox->currentIndex();
-  if (idx > myPages.count())
-    return false;
-  myPages[idx]->takeFocus();
-  repaint();
-  return true;
-}
-
-void ModuleBase_WidgetToolbox::activateCustom()
+void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
 {
+  bool isSignalsBlocked = myToolBox->blockSignals(true);
+  myToolBox->setCurrentIndex(theIndex);
+  myToolBox->blockSignals(isSignalsBlocked);
 }
 
-bool ModuleBase_WidgetToolbox::storeValueCustom() const
-{
-  // A rare case when plugin was not loaded.
-  if(!myFeature)
-    return false;
-  DataPtr aData = myFeature->data();
-  AttributeStringPtr aStringAttr = aData->string(attributeID());
-  QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
-  aStringAttr->setValue(aWidgetValue.toStdString());
-  return true;
-}
 
-void ModuleBase_WidgetToolbox::onPageChanged()
-{
-  storeValue();
-  focusTo();
-}