Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetToolbox.cpp
1 /*
2  * ModuleBase_WidgetToolbox.cpp
3  *
4  *  Created on: Feb 27, 2015
5  *      Author: sbh
6  */
7
8 #include <ModuleBase_WidgetToolbox.h>
9 #include <ModuleBase_PageBase.h>
10 #include <ModuleBase_ModelWidget.h>
11 #include <ModuleBase_Tools.h>
12 #include <ModuleBase_ToolBox.h>
13
14 #include <ModelAPI_AttributeString.h>
15
16 #include <QWidget>
17 #include <QList>
18 #include <QVBoxLayout>
19 #include <QIcon>
20
21 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData)
22 : ModuleBase_PagedContainer(theParent, theData)
23 {
24   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
25   ModuleBase_Tools::zeroMargins(aMainLayout);
26
27   bool aHasContainerParent = false;
28   QWidget* aParent = dynamic_cast<QWidget*>(parent());
29   while(aParent && !aHasContainerParent) {
30     ModuleBase_PagedContainer* aPagedContainer = dynamic_cast<ModuleBase_PagedContainer*>(aParent);
31     aHasContainerParent = aPagedContainer;
32     aParent = dynamic_cast<QWidget*>(aParent->parent());
33   }
34   myToolBox = new ModuleBase_ToolBox(this, aHasContainerParent);
35   // Dark-grey rounded tabs with button-like border #and bold font
36   // TODO: apply style to custom widget
37   QString css = "QToolBox::tab{background-color:#c8c8c8;"
38                               "border-radius:5px;"
39                               "border:1px inset;"
40                               //"font-weight:700;"
41                               "border-color:#fff #505050 #505050 #fff;}";
42   myToolBox->setStyleSheet(css);
43   // default vertical size policy is preferred
44   aMainLayout->addWidget(myToolBox);
45
46   connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
47 }
48
49 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
50 {
51 }
52
53 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
54                                       const QString& theName,
55                                       const QString& theCaseId,
56                                       const QPixmap& theIcon )
57 {
58   ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon);
59   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
60   myToolBox->addItem(aFrame, theName, theIcon );
61   return myToolBox->count();
62 }
63
64 int ModuleBase_WidgetToolbox::currentPageIndex() const
65 {
66   return myToolBox->currentIndex();
67 }
68
69 void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
70 {
71   bool isSignalsBlocked = myToolBox->blockSignals(true);
72   myToolBox->setCurrentIndex(theIndex);
73   myToolBox->blockSignals(isSignalsBlocked);
74 }
75
76