Salome HOME
ModuleBase_ViewerPrs is wrapped into shared_ptr.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSwitch.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_WidgetSwitch.cpp
5  *
6  *  Created on: Apr 16, 2014
7  *      Author: sbh
8  */
9
10 #include <ModuleBase_WidgetSwitch.h>
11 #include <ModuleBase_ModelWidget.h>
12 #include <ModuleBase_PageBase.h>
13 #include <ModuleBase_Tools.h>
14
15 #include <QComboBox>
16 #include <QFrame>
17 #include <QSpacerItem>
18 #include <QStackedLayout>
19 #include <QVBoxLayout>
20
21 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData)
22 : ModuleBase_PagedContainer(theParent, theData)
23 {
24   QVBoxLayout*  aMainLay = new QVBoxLayout(this);
25   //aMainLay->setContentsMargins(2, 4, 2, 2);
26   ModuleBase_Tools::adjustMargins(aMainLay);
27   myCombo = new QComboBox(this);
28   myCombo->hide();
29   myPagesLayout = new QStackedLayout(this);
30   aMainLay->addWidget(myCombo);
31   aMainLay->addLayout(myPagesLayout, 1);
32   setLayout(aMainLay);
33
34   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageChanged()));
35   connect(myCombo, SIGNAL(activated(int)), myPagesLayout, SLOT(setCurrentIndex(int)));
36 }
37
38 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
39 {
40 }
41
42
43 int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName,
44                                                                    const QString& theCaseId,
45                                                                    const QPixmap& theIcon )
46 {
47   int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon);
48   myCombo->addItem(theName);
49   int aResultCount = myCombo->count();
50   if (aResultCount == 2)
51     myCombo->show();
52   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
53   aFrame->setFrameShape(QFrame::Box);
54   aFrame->setFrameStyle(QFrame::Sunken);
55   myPagesLayout->addWidget(aFrame);
56   return aResultCount;
57 }
58
59 int ModuleBase_WidgetSwitch::currentPageIndex() const
60 {
61   int aComboIndex = myCombo->currentIndex();
62   return aComboIndex;
63 }
64
65
66 void ModuleBase_WidgetSwitch::setCurrentPageIndex(int theIndex)
67 {
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);
74 }