1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "ModuleBase_ChoiceCtrl.h"
22 #include "ModuleBase_Tools.h"
23 #include "ModuleBase_IconFactory.h"
29 #include <QButtonGroup>
30 #include <QRadioButton>
31 #include <QToolButton>
33 ModuleBase_ChoiceCtrl::ModuleBase_ChoiceCtrl(QWidget* theParent,
34 const QStringList& theChoiceList,
35 const QStringList& theIconsList,
37 Qt::Orientation theButtonsDir)
38 : QWidget(theParent), myType(theType)
40 QHBoxLayout* aLayout = new QHBoxLayout(this);
41 ModuleBase_Tools::adjustMargins(aLayout);
46 myButtons = new QButtonGroup(this);
47 myGroupBox = new QGroupBox("", this);
48 aLayout->addWidget(myGroupBox);
50 QLayout* aBtnLayout = 0;
51 switch (theButtonsDir) {
53 aBtnLayout = new QHBoxLayout(myGroupBox);
56 aBtnLayout = new QVBoxLayout(myGroupBox);
59 ModuleBase_Tools::adjustMargins(aBtnLayout);
61 if (theIconsList.length() == theChoiceList.length()) {
63 foreach(QString aBtnTxt, theChoiceList) {
64 QToolButton* aBtn = new QToolButton(myGroupBox);
65 aBtn->setFocusPolicy(Qt::StrongFocus);
66 aBtn->setCheckable(true);
67 aBtn->setToolTip(aBtnTxt);
69 QPixmap aIcon = ModuleBase_IconFactory::loadPixmap(theIconsList.at(aId));
71 aBtn->setIconSize(aIcon.size());
73 aBtnLayout->addWidget(aBtn);
74 myButtons->addButton(aBtn, aId++);
78 foreach(QString aBtnTxt, theChoiceList) {
79 QRadioButton* aBtn = new QRadioButton(aBtnTxt, myGroupBox);
80 aBtnLayout->addWidget(aBtn);
81 myButtons->addButton(aBtn, aId++);
84 connect(myButtons, SIGNAL(buttonClicked(int)), this, SIGNAL(valueChanged(int)));
88 myLabel = new QLabel("", this);
89 aLayout->addWidget(myLabel);
91 //std::string aToolstr = theData->widgetTooltip();
92 //if (!aToolstr.empty()) {
93 // myLabel->setToolTip(QString::fromStdString(aToolstr));
96 myCombo = new QComboBox(this);
97 aLayout->addWidget(myCombo, 1);
99 myCombo->addItems(theChoiceList);
100 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valueChanged(int)));
105 void ModuleBase_ChoiceCtrl::setLabel(const QString& theText)
109 myGroupBox->setTitle(theText);
112 myLabel->setText(theText);
117 void ModuleBase_ChoiceCtrl::setLabelIcon(const QString& theIcon)
119 if (myType == ComboBox)
120 myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(theIcon));
123 void ModuleBase_ChoiceCtrl::setValue(int theVal)
127 myButtons->button(theVal)->setChecked(true);
130 myCombo->setCurrentIndex(theVal);
135 void ModuleBase_ChoiceCtrl::setValue(const QString& theVal)
139 foreach (QAbstractButton* aBtn, myButtons->buttons()) {
140 aBtn->setChecked(aBtn->toolTip() == theVal);
144 myCombo->setCurrentText(theVal);
150 void ModuleBase_ChoiceCtrl::setTooltip(QString theTip)
152 if (myType == ComboBox)
153 myLabel->setToolTip(theTip);
156 int ModuleBase_ChoiceCtrl::value() const
160 return myButtons->checkedId();
162 return myCombo->currentIndex();
167 bool ModuleBase_ChoiceCtrl::focusTo()
169 if (myType == ComboBox)
170 ModuleBase_Tools::setFocus(myCombo, "ModuleBase_WidgetChoice::focusTo()");
176 QList<QWidget*> ModuleBase_ChoiceCtrl::getControls() const
178 QList<QWidget*> aControls;
179 if (myType == ComboBox)
180 aControls.append(myCombo);
184 void ModuleBase_ChoiceCtrl::setChoiceList(const QStringList& theChoiceList)
186 if (myType == ComboBox) {
188 myCombo->addItems(theChoiceList);
192 QString ModuleBase_ChoiceCtrl::textValue() const
196 return myButtons->checkedButton()->toolTip();
198 return myCombo->currentText();