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 : ModuleBase_PagedContainer(theParent, theData)
24 QVBoxLayout* aMainLay = new QVBoxLayout(this);
25 //aMainLay->setContentsMargins(2, 4, 2, 2);
26 ModuleBase_Tools::adjustMargins(aMainLay);
27 myCombo = new QComboBox(this);
29 myPagesLayout = new QStackedLayout(this);
30 aMainLay->addWidget(myCombo);
31 aMainLay->addLayout(myPagesLayout, 1);
34 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageChanged()));
35 connect(myCombo, SIGNAL(activated(int)), myPagesLayout, SLOT(setCurrentIndex(int)));
38 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
43 int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName,
44 const QString& theCaseId,
45 const QPixmap& theIcon )
47 int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon);
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);