2 * ModuleBase_WidgetToolbox.cpp
4 * Created on: Feb 27, 2015
8 #include <ModuleBase_WidgetToolbox.h>
9 #include <ModuleBase_PageBase.h>
10 #include <ModuleBase_ModelWidget.h>
11 #include <ModuleBase_Tools.h>
13 #include <ModelAPI_AttributeString.h>
17 #include <QVBoxLayout>
19 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
20 const std::string& theParentId)
21 : ModuleBase_ModelWidget(theParent, theData, theParentId),
22 myIsPassFocusToCurrentPage(false)
24 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
25 ModuleBase_Tools::zeroMargins(aMainLayout);
26 myToolBox = new QToolBox(this);
27 // Dark-grey rounded tabs with button-like border #and bold font
28 QString css = "QToolBox::tab{background-color:#c8c8c8;"
32 "border-color:#fff #505050 #505050 #fff;}";
33 myToolBox->setStyleSheet(css);
34 // default vertical size policy is preferred
35 aMainLayout->addWidget(myToolBox);
37 connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
40 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
44 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
45 const QString& theName, const QString& theCaseId)
47 myCaseIds << theCaseId;
49 QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
50 aFrame->setFrameShape(QFrame::Box);
51 aFrame->setFrameStyle(QFrame::Sunken);
52 return myToolBox->addItem(aFrame, theName);
55 bool ModuleBase_WidgetToolbox::restoreValue()
57 // A rare case when plugin was not loaded.
60 DataPtr aData = myFeature->data();
61 AttributeStringPtr aStringAttr = aData->string(attributeID());
62 QString aCaseId = QString::fromStdString(aStringAttr->value());
63 int idx = myCaseIds.indexOf(aCaseId);
66 bool isSignalsBlocked = myToolBox->blockSignals(true);
67 myToolBox->setCurrentIndex(idx);
68 myToolBox->blockSignals(isSignalsBlocked);
72 QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
74 QList<QWidget*> aResult;
75 int idx = myToolBox->currentIndex();
76 QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[idx]->modelWidgets();
77 foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
78 aResult << eachModelWidget->getControls();
83 bool ModuleBase_WidgetToolbox::focusTo()
85 int idx = myToolBox->currentIndex();
86 if (idx > myPages.count())
88 return myPages[idx]->takeFocus();
91 void ModuleBase_WidgetToolbox::setHighlighted(bool)
93 //page containers sould not be highlighted, do nothing
96 void ModuleBase_WidgetToolbox::enableFocusProcessing()
98 myIsPassFocusToCurrentPage = true;
102 void ModuleBase_WidgetToolbox::activateCustom()
104 // activate current page
108 bool ModuleBase_WidgetToolbox::storeValueCustom() const
110 // A rare case when plugin was not loaded.
113 DataPtr aData = myFeature->data();
114 AttributeStringPtr aStringAttr = aData->string(attributeID());
115 QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
116 aStringAttr->setValue(aWidgetValue.toStdString());
120 void ModuleBase_WidgetToolbox::onPageChanged()
123 if (myIsPassFocusToCurrentPage) focusTo();