2 * ModuleBase_WidgetSwitch.cpp
4 * Created on: Apr 16, 2014
8 #include <ModuleBase_WidgetSwitch.h>
11 #include <QVBoxLayout>
12 #include <QSpacerItem>
14 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* parent)
17 myMainLay = new QVBoxLayout(this);
18 myMainLay->setContentsMargins(2, 4, 2, 2);
19 myCombo = new QComboBox(this);
21 myMainLay->addWidget(myCombo);
22 this->setFrameShape(QFrame::StyledPanel);
23 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
24 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int)));
28 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
32 int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
34 return insertPage(count(), theWidget, theName);
37 int ModuleBase_WidgetSwitch::count() const
39 return myCombo->count();
42 int ModuleBase_WidgetSwitch::currentIndex() const
44 return myCombo->currentIndex();
47 QWidget* ModuleBase_WidgetSwitch::currentWidget() const
49 int idx = currentIndex();
53 int ModuleBase_WidgetSwitch::indexOf(QWidget* theWidget) const
55 return myCases.indexOf(theWidget);
58 int ModuleBase_WidgetSwitch::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
60 int index = theIndex < count() ? theIndex : count();
63 myCombo->insertItem(index, theName);
64 myCases.insert(index, theWidget);
65 myMainLay->addWidget(theWidget);
66 setCurrentIndex(theIndex);
70 bool ModuleBase_WidgetSwitch::isPageEnabled(int index) const
72 return myCases[index]->isEnabled();
75 QString ModuleBase_WidgetSwitch::pageText(int index) const
77 return myCombo->itemText(index);
80 QString ModuleBase_WidgetSwitch::pageToolTip(int index) const
82 return myCases[index]->toolTip();
85 void ModuleBase_WidgetSwitch::removePage(int index)
87 myCombo->removeItem(index);
88 myCases.removeAt(index);
94 void ModuleBase_WidgetSwitch::setPageEnabled(int index, bool enabled)
96 myCases[index]->setEnabled(enabled);
99 void ModuleBase_WidgetSwitch::setPageName(int index, const QString& theName)
101 myCombo->setItemText(index, theName);
104 void ModuleBase_WidgetSwitch::setPageToolTip(int index, const QString& toolTip)
106 myCases[index]->setToolTip(toolTip);
109 void ModuleBase_WidgetSwitch::setCurrentIndex(int index)
111 myCombo->setCurrentIndex(index);
115 void ModuleBase_WidgetSwitch::refresh()
117 foreach(QWidget* eachWidget, myCases)
119 eachWidget->setVisible(false);
121 if (currentIndex() >= myCases.count())
123 myCases[currentIndex()]->setVisible(true);