]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetToolbox.cpp
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[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_Tools.h>
10
11 #include <ModelAPI_AttributeString.h>
12
13 #include <QWidget>
14 #include <QVBoxLayout>
15
16 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
17                                                    const std::string& theParentId)
18 : ModuleBase_ModelWidget(theParent, theData, theParentId)
19 {
20   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
21   ModuleBase_Tools::zeroMargins(aMainLayout);
22   myToolBox = new QToolBox(this);
23   // Dark-grey rounded tabs with button-like border #and bold font
24   QString css = "QToolBox::tab{background-color:#c8c8c8;"
25                               "border-radius:5px;"
26                               "border:1px inset;"
27                               //"font-weight:700;"
28                               "border-color:#fff #505050 #505050 #fff;}";
29   myToolBox->setStyleSheet(css);
30   // default vertical size policy is preferred
31   QSizePolicy aSizePolicy = myToolBox->sizePolicy();
32   aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding);
33   myToolBox->setSizePolicy(aSizePolicy);
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(QWidget* theWidget,
44                                       const QString& theName, const QString& theCaseId)
45 {
46   myCaseIds << theCaseId;
47   return myToolBox->addItem(theWidget, theName);
48 }
49
50 bool ModuleBase_WidgetToolbox::restoreValue()
51 {
52   // A rare case when plugin was not loaded.
53   if(!myFeature)
54     return false;
55   DataPtr aData = myFeature->data();
56   AttributeStringPtr aStringAttr = aData->string(attributeID());
57   QString aCaseId = QString::fromStdString(aStringAttr->value());
58   int idx = myCaseIds.indexOf(aCaseId);
59   if (idx == -1)
60     return false;
61   bool isSignalsBlocked = myToolBox->blockSignals(true);
62   myToolBox->setCurrentIndex(idx);
63   myToolBox->blockSignals(isSignalsBlocked);
64   return true;
65 }
66
67 QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
68 {
69   QList<QWidget*> aList;
70   aList << myToolBox;
71   return aList;
72 }
73
74 bool ModuleBase_WidgetToolbox::storeValueCustom() const
75 {
76   // A rare case when plugin was not loaded.
77   if(!myFeature)
78     return false;
79   DataPtr aData = myFeature->data();
80   AttributeStringPtr aStringAttr = aData->string(attributeID());
81   QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
82   aStringAttr->setValue(aWidgetValue.toStdString());
83   return true;
84 }
85
86 void ModuleBase_WidgetToolbox::onPageChanged()
87 {
88   storeValue();
89 }