1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "ModuleBase_ChoiceCtrl.h"
21 #include "ModuleBase_Tools.h"
22 #include "ModuleBase_IconFactory.h"
28 #include <QButtonGroup>
29 #include <QRadioButton>
30 #include <QToolButton>
32 ModuleBase_ChoiceCtrl::ModuleBase_ChoiceCtrl(QWidget* theParent,
33 const QStringList& theChoiceList,
34 const QStringList& theIconsList,
36 Qt::Orientation theButtonsDir)
37 : QWidget(theParent), myType(theType)
39 QHBoxLayout* aLayout = new QHBoxLayout(this);
40 aLayout->setContentsMargins(0, 0, 0, 0);
45 myButtons = new QButtonGroup(this);
46 myGroupBox = new QGroupBox("", this);
47 aLayout->addWidget(myGroupBox);
49 QLayout* aBtnLayout = 0;
50 switch (theButtonsDir) {
52 aBtnLayout = new QHBoxLayout(myGroupBox);
55 aBtnLayout = new QVBoxLayout(myGroupBox);
58 ModuleBase_Tools::adjustMargins(aBtnLayout);
60 if (theIconsList.length() == theChoiceList.length()) {
62 foreach(QString aBtnTxt, theChoiceList) {
63 QToolButton* aBtn = new QToolButton(myGroupBox);
64 aBtn->setFocusPolicy(Qt::StrongFocus);
65 aBtn->setCheckable(true);
66 aBtn->setToolTip(aBtnTxt);
68 QPixmap aIcon = ModuleBase_IconFactory::loadPixmap(theIconsList.at(aId));
70 aBtn->setIconSize(aIcon.size());
72 aBtnLayout->addWidget(aBtn);
73 myButtons->addButton(aBtn, aId++);
77 foreach(QString aBtnTxt, theChoiceList) {
78 QRadioButton* aBtn = new QRadioButton(aBtnTxt, myGroupBox);
79 aBtnLayout->addWidget(aBtn);
80 myButtons->addButton(aBtn, aId++);
83 connect(myButtons, SIGNAL(buttonClicked(int)), this, SIGNAL(valueChanged(int)));
87 myLabel = new QLabel("", this);
88 aLayout->addWidget(myLabel);
90 //std::string aToolstr = theData->widgetTooltip();
91 //if (!aToolstr.empty()) {
92 // myLabel->setToolTip(QString::fromStdString(aToolstr));
95 myCombo = new QComboBox(this);
96 aLayout->addWidget(myCombo, 1);
98 myCombo->addItems(theChoiceList);
99 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valueChanged(int)));
104 void ModuleBase_ChoiceCtrl::setLabel(const QString& theText)
108 myGroupBox->setTitle(theText);
111 myLabel->setText(theText);
116 void ModuleBase_ChoiceCtrl::setLabelIcon(const QString& theIcon)
118 if (myType == ComboBox)
119 myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(theIcon));
122 void ModuleBase_ChoiceCtrl::setValue(int theVal)
126 myButtons->button(theVal)->setChecked(true);
129 myCombo->setCurrentIndex(theVal);
134 void ModuleBase_ChoiceCtrl::setValue(const QString& theVal)
138 foreach (QAbstractButton* aBtn, myButtons->buttons()) {
139 aBtn->setChecked(aBtn->toolTip() == theVal);
143 myCombo->setCurrentText(theVal);
149 void ModuleBase_ChoiceCtrl::setTooltip(QString theTip)
151 if (myType == ComboBox)
152 myLabel->setToolTip(theTip);
155 int ModuleBase_ChoiceCtrl::value() const
159 return myButtons->checkedId();
161 return myCombo->currentIndex();
166 bool ModuleBase_ChoiceCtrl::focusTo()
168 if (myType == ComboBox)
169 ModuleBase_Tools::setFocus(myCombo, "ModuleBase_WidgetChoice::focusTo()");
175 QList<QWidget*> ModuleBase_ChoiceCtrl::getControls() const
177 QList<QWidget*> aControls;
178 if (myType == ComboBox)
179 aControls.append(myCombo);
183 void ModuleBase_ChoiceCtrl::setChoiceList(const QStringList& theChoiceList)
185 if (myType == ComboBox) {
187 myCombo->addItems(theChoiceList);
191 QString ModuleBase_ChoiceCtrl::textValue() const
195 return myButtons->checkedButton()->toolTip();
197 return myCombo->currentText();