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>
13 #include <QVBoxLayout>
14 #include <QSpacerItem>
16 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* parent)
19 myMainLay = new QVBoxLayout(this);
20 myMainLay->setContentsMargins(2, 4, 2, 2);
21 myCombo = new QComboBox(this);
23 myMainLay->addWidget(myCombo);
24 this->setFrameShape(QFrame::StyledPanel);
25 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
26 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int)));
30 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
34 int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
36 return insertPage(count(), theWidget, theName);
39 int ModuleBase_WidgetSwitch::count() const
41 return myCombo->count();
44 int ModuleBase_WidgetSwitch::currentIndex() const
46 return myCombo->currentIndex();
49 QWidget* ModuleBase_WidgetSwitch::currentWidget() const
51 int idx = currentIndex();
55 int ModuleBase_WidgetSwitch::indexOf(QWidget* theWidget) const
57 return myCases.indexOf(theWidget);
60 int ModuleBase_WidgetSwitch::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
62 int index = theIndex < count() ? theIndex : count();
65 myCombo->insertItem(index, theName);
66 myCases.insert(index, theWidget);
67 myMainLay->addWidget(theWidget);
68 setCurrentIndex(theIndex);
72 bool ModuleBase_WidgetSwitch::isPageEnabled(int index) const
74 return myCases[index]->isEnabled();
77 QString ModuleBase_WidgetSwitch::pageText(int index) const
79 return myCombo->itemText(index);
82 QString ModuleBase_WidgetSwitch::pageToolTip(int index) const
84 return myCases[index]->toolTip();
87 void ModuleBase_WidgetSwitch::removePage(int index)
89 myCombo->removeItem(index);
90 myCases.removeAt(index);
96 void ModuleBase_WidgetSwitch::setPageEnabled(int index, bool enabled)
98 myCases[index]->setEnabled(enabled);
101 void ModuleBase_WidgetSwitch::setPageName(int index, const QString& theName)
103 myCombo->setItemText(index, theName);
106 void ModuleBase_WidgetSwitch::setPageToolTip(int index, const QString& toolTip)
108 myCases[index]->setToolTip(toolTip);
111 void ModuleBase_WidgetSwitch::setCurrentIndex(int index)
113 myCombo->setCurrentIndex(index);
117 void ModuleBase_WidgetSwitch::refresh()
119 foreach(QWidget* eachWidget, myCases)
121 eachWidget->setVisible(false);
123 if (currentIndex() >= myCases.count())
125 myCases[currentIndex()]->setVisible(true);