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