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,
22 const Config_WidgetAPI* theData)
23 : ModuleBase_PagedContainer(theParent, theData)
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,
46 const QPixmap& theIcon )
48 int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon);
49 myCombo->addItem(theName);
50 int aResultCount = myCombo->count();
51 if (aResultCount == 2)
53 QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
54 aFrame->setFrameShape(QFrame::Box);
55 aFrame->setFrameStyle(QFrame::Sunken);
56 myPagesLayout->addWidget(aFrame);
60 int ModuleBase_WidgetSwitch::currentPageIndex() const
62 int aComboIndex = myCombo->currentIndex();
67 void ModuleBase_WidgetSwitch::setCurrentPageIndex(int theIndex)
69 bool isComboSignalsBlocked = myCombo->blockSignals(true);
70 bool isPagesLayoutSignalsBlocked = myPagesLayout->blockSignals(true);
71 myCombo->setCurrentIndex(theIndex);
72 myPagesLayout->setCurrentIndex(theIndex);
73 myCombo->blockSignals(isComboSignalsBlocked);
74 myPagesLayout->blockSignals(isPagesLayoutSignalsBlocked);