]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetSwitch.cpp
Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[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,
22   const Config_WidgetAPI* theData)
23 : ModuleBase_PagedContainer(theParent, theData)
24 {
25   QVBoxLayout*  aMainLay = new QVBoxLayout(this);
26   //aMainLay->setContentsMargins(2, 4, 2, 2);
27   ModuleBase_Tools::adjustMargins(aMainLay);
28   myCombo = new QComboBox(this);
29   myCombo->hide();
30   myPagesLayout = new QStackedLayout(this);
31   aMainLay->addWidget(myCombo);
32   aMainLay->addLayout(myPagesLayout, 1);
33   setLayout(aMainLay);
34
35   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageChanged()));
36   connect(myCombo, SIGNAL(activated(int)), myPagesLayout, SLOT(setCurrentIndex(int)));
37 }
38
39 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
40 {
41 }
42
43
44 int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName,
45                                                                    const QString& theCaseId,
46                                                                    const QPixmap& theIcon )
47 {
48   int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon);
49   myCombo->addItem(theName);
50   int aResultCount = myCombo->count();
51   if (aResultCount == 2)
52     myCombo->show();
53   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
54   aFrame->setFrameShape(QFrame::Box);
55   aFrame->setFrameStyle(QFrame::Sunken);
56   myPagesLayout->addWidget(aFrame);
57   return aResultCount;
58 }
59
60 int ModuleBase_WidgetSwitch::currentPageIndex() const
61 {
62   int aComboIndex = myCombo->currentIndex();
63   return aComboIndex;
64 }
65
66
67 void ModuleBase_WidgetSwitch::setCurrentPageIndex(int theIndex)
68 {
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);
75 }