Salome HOME
6a16aa3d2647d6d4057e6352971f686ad02e1a06
[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
13 #include <ModelAPI_AttributeString.h>
14
15 #include <QWidget>
16 #include <QList>
17 #include <QVBoxLayout>
18
19 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
20                                                    const std::string& theParentId)
21 : ModuleBase_PagedContainer(theParent, theData, theParentId)
22 {
23   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
24   ModuleBase_Tools::zeroMargins(aMainLayout);
25   myToolBox = new QToolBox(this);
26   // Dark-grey rounded tabs with button-like border #and bold font
27   QString css = "QToolBox::tab{background-color:#c8c8c8;"
28                               "border-radius:5px;"
29                               "border:1px inset;"
30                               //"font-weight:700;"
31                               "border-color:#fff #505050 #505050 #fff;}";
32   myToolBox->setStyleSheet(css);
33   // default vertical size policy is preferred
34   aMainLayout->addWidget(myToolBox);
35
36   connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
37 }
38
39 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
40 {
41 }
42
43 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
44                                       const QString& theName, const QString& theCaseId)
45 {
46   ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId);
47   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
48   aFrame->setFrameShape(QFrame::Box);
49   aFrame->setFrameStyle(QFrame::Sunken);
50   myToolBox->addItem(aFrame, theName);
51   return myToolBox->count();
52 }
53
54 int ModuleBase_WidgetToolbox::currentPageIndex() const
55 {
56   return myToolBox->currentIndex();
57 }
58
59 void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
60 {
61   bool isSignalsBlocked = myToolBox->blockSignals(true);
62   myToolBox->setCurrentIndex(theIndex);
63   myToolBox->blockSignals(isSignalsBlocked);
64 }
65
66