]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_SwitchWidget.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_SwitchWidget.cpp
1 /*
2  * XGUI_SwitchWidget.cpp
3  *
4  *  Created on: Apr 16, 2014
5  *      Author: sbh
6  */
7
8 #include <XGUI_SwitchWidget.h>
9
10 #include <QComboBox>
11 #include <QVBoxLayout>
12 #include <QSpacerItem>
13
14 XGUI_SwitchWidget::XGUI_SwitchWidget(QWidget* parent)
15 : QFrame(parent)
16 {
17   myMainLay = new QVBoxLayout(this);
18   myMainLay->setContentsMargins(2, 4, 2, 2);
19   myCombo = new QComboBox(this);
20   myCombo->hide();
21   myMainLay->addWidget(myCombo);
22   this->setFrameShape(QFrame::StyledPanel);
23   connect(myCombo, SIGNAL(currentIndexChanged(int)),
24           this, SLOT(setCurrentIndex(int)));
25   connect(myCombo, SIGNAL(currentIndexChanged(int)),
26           this, SIGNAL(currentPageChanged(int)));
27
28 }
29
30 XGUI_SwitchWidget::~XGUI_SwitchWidget()
31 {
32 }
33
34 int XGUI_SwitchWidget::addPage(QWidget* theWidget, const QString& theName)
35 {
36   return insertPage(count(), theWidget, theName);
37 }
38
39 int XGUI_SwitchWidget::count() const
40 {
41   return myCombo->count();
42 }
43
44 int XGUI_SwitchWidget::currentIndex() const
45 {
46   return myCombo->currentIndex();
47 }
48
49 QWidget* XGUI_SwitchWidget::currentWidget() const
50 {
51   int idx = currentIndex();
52   return myCases[idx];
53 }
54
55 int XGUI_SwitchWidget::indexOf(QWidget* theWidget) const
56 {
57   return myCases.indexOf(theWidget);
58 }
59
60 int XGUI_SwitchWidget::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
61 {
62   int index = theIndex < count() ? theIndex : count();
63   if(count() == 0)
64     myCombo->show();
65   myCombo->insertItem(index, theName);
66   myCases.insert(index, theWidget);
67   myMainLay->addWidget(theWidget);
68   setCurrentIndex(theIndex);
69   return index;
70 }
71
72 bool XGUI_SwitchWidget::isPageEnabled(int index) const
73 {
74   return myCases[index]->isEnabled();
75 }
76
77 QString XGUI_SwitchWidget::pageText(int index) const
78 {
79   return myCombo->itemText(index);
80 }
81
82 QString XGUI_SwitchWidget::pageToolTip(int index) const
83 {
84   return myCases[index]->toolTip();
85 }
86
87 void XGUI_SwitchWidget::removePage(int index)
88 {
89   myCombo->removeItem(index);
90   myCases.removeAt(index);
91   if (count() == 0) {
92     myCombo->hide();
93   }
94 }
95
96 void XGUI_SwitchWidget::setPageEnabled(int index, bool enabled)
97 {
98   myCases[index]->setEnabled(enabled);
99 }
100
101 void XGUI_SwitchWidget::setPageName(int index, const QString& theName)
102 {
103   myCombo->setItemText(index, theName);
104 }
105
106 void XGUI_SwitchWidget::setPageToolTip(int index, const QString& toolTip)
107 {
108   myCases[index]->setToolTip(toolTip);
109 }
110
111 void XGUI_SwitchWidget::setCurrentIndex(int index)
112 {
113   myCombo->setCurrentIndex(index);
114   refresh();
115 }
116
117 void XGUI_SwitchWidget::refresh()
118 {
119   foreach(QWidget* eachWidget, myCases) {
120     eachWidget->setVisible(false);
121   }
122   if(currentIndex() >= myCases.count())
123     return;
124   myCases[currentIndex()]->setVisible(true);
125 }