1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_WidgetSwitch.cpp
6 * Created on: Apr 16, 2014
10 #include <ModuleBase_WidgetSwitch.h>
11 #include <ModuleBase_ModelWidget.h>
12 #include <ModuleBase_PageBase.h>
13 #include <ModuleBase_Tools.h>
17 #include <QSpacerItem>
18 #include <QStackedLayout>
19 #include <QVBoxLayout>
21 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData,
22 const std::string& theParentId)
23 : ModuleBase_PagedContainer(theParent, theData, theParentId)
25 QVBoxLayout* aMainLay = new QVBoxLayout(this);
26 //aMainLay->setContentsMargins(2, 4, 2, 2);
27 ModuleBase_Tools::adjustMargins(aMainLay);
28 myCombo = new QComboBox(this);
30 myPagesLayout = new QStackedLayout(this);
31 aMainLay->addWidget(myCombo);
32 aMainLay->addLayout(myPagesLayout, 1);
35 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageChanged()));
36 connect(myCombo, SIGNAL(activated(int)), myPagesLayout, SLOT(setCurrentIndex(int)));
39 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
44 int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName,
45 const QString& theCaseId)
47 int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId);
48 myCombo->addItem(theName);
49 int aResultCount = myCombo->count();
50 if (aResultCount == 2)
52 QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
53 aFrame->setFrameShape(QFrame::Box);
54 aFrame->setFrameStyle(QFrame::Sunken);
55 myPagesLayout->addWidget(aFrame);
59 int ModuleBase_WidgetSwitch::currentPageIndex() const
61 int aComboIndex = myCombo->currentIndex();
66 void ModuleBase_WidgetSwitch::setCurrentPageIndex(int theIndex)
68 bool isComboSignalsBlocked = myCombo->blockSignals(true);
69 bool isPagesLayoutSignalsBlocked = myPagesLayout->blockSignals(true);
70 myCombo->setCurrentIndex(theIndex);
71 myPagesLayout->setCurrentIndex(theIndex);
72 myCombo->blockSignals(isComboSignalsBlocked);
73 myPagesLayout->blockSignals(isPagesLayoutSignalsBlocked);