2 * ModuleBase_WidgetToolbox.cpp
4 * Created on: Feb 27, 2015
8 #include <ModuleBase_WidgetToolbox.h>
9 #include <ModuleBase_PageBase.h>
10 #include <ModuleBase_Tools.h>
12 #include <ModelAPI_AttributeString.h>
15 #include <QVBoxLayout>
17 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
18 const std::string& theParentId)
19 : ModuleBase_ModelWidget(theParent, theData, theParentId)
21 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
22 ModuleBase_Tools::zeroMargins(aMainLayout);
23 myToolBox = new QToolBox(this);
24 // Dark-grey rounded tabs with button-like border #and bold font
25 QString css = "QToolBox::tab{background-color:#c8c8c8;"
29 "border-color:#fff #505050 #505050 #fff;}";
30 myToolBox->setStyleSheet(css);
31 // default vertical size policy is preferred
32 aMainLayout->addWidget(myToolBox);
34 connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
37 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
41 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
42 const QString& theName, const QString& theCaseId)
44 myCaseIds << theCaseId;
46 QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
47 aFrame->setFrameShape(QFrame::Box);
48 aFrame->setFrameStyle(QFrame::Sunken);
49 return myToolBox->addItem(aFrame, theName);
52 bool ModuleBase_WidgetToolbox::restoreValue()
54 // A rare case when plugin was not loaded.
57 DataPtr aData = myFeature->data();
58 AttributeStringPtr aStringAttr = aData->string(attributeID());
59 QString aCaseId = QString::fromStdString(aStringAttr->value());
60 int idx = myCaseIds.indexOf(aCaseId);
63 bool isSignalsBlocked = myToolBox->blockSignals(true);
64 myToolBox->setCurrentIndex(idx);
65 myToolBox->blockSignals(isSignalsBlocked);
70 QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
72 QList<QWidget*> aList;
77 bool ModuleBase_WidgetToolbox::focusTo()
79 int idx = myToolBox->currentIndex();
80 if (idx > myPages.count())
82 myPages[idx]->takeFocus();
87 void ModuleBase_WidgetToolbox::activateCustom()
91 bool ModuleBase_WidgetToolbox::storeValueCustom() const
93 // A rare case when plugin was not loaded.
96 DataPtr aData = myFeature->data();
97 AttributeStringPtr aStringAttr = aData->string(attributeID());
98 QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
99 aStringAttr->setValue(aWidgetValue.toStdString());
103 void ModuleBase_WidgetToolbox::onPageChanged()