]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetSwitch.cpp
Salome HOME
aec77a6b99403faccf2023d2ce21d5c00184cada
[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
14 #include <QComboBox>
15 #include <QVBoxLayout>
16 #include <QSpacerItem>
17
18
19 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData,
20                                                  const std::string& theParentId)
21 : ModuleBase_ModelWidget(theParent, theData, theParentId)
22 {
23   myMainLay = new QVBoxLayout(this);
24   myMainLay->setContentsMargins(2, 4, 2, 2);
25   myCombo = new QComboBox(this);
26   myCombo->hide();
27   myMainLay->addWidget(myCombo);
28   //this->setFrameShape(QFrame::StyledPanel);
29   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
30   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int)));
31
32 }
33
34 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
35 {
36 }
37
38 QList<QWidget*> ModuleBase_WidgetSwitch::getControls() const
39 {
40   QList<QWidget*> aList;
41   aList << myCombo;
42   return aList;
43 }
44
45 int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
46 {
47   return insertPage(count(), theWidget, theName);
48 }
49
50 int ModuleBase_WidgetSwitch::count() const
51 {
52   return myCombo->count();
53 }
54
55 int ModuleBase_WidgetSwitch::currentIndex() const
56 {
57   return myCombo->currentIndex();
58 }
59
60 QWidget* ModuleBase_WidgetSwitch::currentWidget() const
61 {
62   int idx = currentIndex();
63   return myCases[idx];
64 }
65
66 int ModuleBase_WidgetSwitch::indexOf(QWidget* theWidget) const
67 {
68   return myCases.indexOf(theWidget);
69 }
70
71 int ModuleBase_WidgetSwitch::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
72 {
73   int index = theIndex < count() ? theIndex : count();
74   if (count() == 0)
75     myCombo->show();
76   myCombo->insertItem(index, theName);
77   myCases.insert(index, theWidget);
78   myMainLay->addWidget(theWidget);
79   setCurrentIndex(theIndex);
80   return index;
81 }
82
83 bool ModuleBase_WidgetSwitch::isPageEnabled(int index) const
84 {
85   return myCases[index]->isEnabled();
86 }
87
88 QString ModuleBase_WidgetSwitch::pageText(int index) const
89 {
90   return myCombo->itemText(index);
91 }
92
93 QString ModuleBase_WidgetSwitch::pageToolTip(int index) const
94 {
95   return myCases[index]->toolTip();
96 }
97
98 void ModuleBase_WidgetSwitch::removePage(int index)
99 {
100   myCombo->removeItem(index);
101   myCases.removeAt(index);
102   if (count() == 0) {
103     myCombo->hide();
104   }
105 }
106
107 void ModuleBase_WidgetSwitch::setPageEnabled(int index, bool enabled)
108 {
109   myCases[index]->setEnabled(enabled);
110 }
111
112 void ModuleBase_WidgetSwitch::setPageName(int index, const QString& theName)
113 {
114   myCombo->setItemText(index, theName);
115 }
116
117 void ModuleBase_WidgetSwitch::setPageToolTip(int index, const QString& toolTip)
118 {
119   myCases[index]->setToolTip(toolTip);
120 }
121
122 void ModuleBase_WidgetSwitch::setCurrentIndex(int index)
123 {
124   myCombo->setCurrentIndex(index);
125   refresh();
126 }
127
128 void ModuleBase_WidgetSwitch::refresh()
129 {
130   foreach(QWidget* eachWidget, myCases)
131   {
132     eachWidget->setVisible(false);
133   }
134   if (currentIndex() >= myCases.count())
135     return;
136   myCases[currentIndex()]->setVisible(true);
137 }