1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 * ModuleBase_WidgetToolbox.cpp
5 * Created on: Feb 27, 2015
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>
15 #include <ModelAPI_AttributeString.h>
19 #include <QVBoxLayout>
22 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent,
23 const Config_WidgetAPI* theData)
24 : ModuleBase_PagedContainer(theParent, theData)
26 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
27 ModuleBase_Tools::zeroMargins(aMainLayout);
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());
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;"
43 "border-color:#fff #505050 #505050 #fff;}";
44 myToolBox->setStyleSheet(css);
45 // default vertical size policy is preferred
46 aMainLayout->addWidget(myToolBox);
48 connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
51 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
55 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
56 const QString& theName,
57 const QString& theCaseId,
58 const QPixmap& theIcon )
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();
66 int ModuleBase_WidgetToolbox::currentPageIndex() const
68 return myToolBox->currentIndex();
71 void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
73 bool isSignalsBlocked = myToolBox->blockSignals(true);
74 myToolBox->setCurrentIndex(theIndex);
75 myToolBox->blockSignals(isSignalsBlocked);