1 // Copyright (C) 2014-2021 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_WidgetRadiobox.h>
21 #include <ModuleBase_PageBase.h>
23 #include <Config_WidgetAPI.h>
25 #include <QFormLayout>
26 #include <QRadioButton>
28 #include <QButtonGroup>
30 ModuleBase_WidgetRadiobox::ModuleBase_WidgetRadiobox(QWidget* theParent,
31 const Config_WidgetAPI* theData)
32 : ModuleBase_PagedContainer(theParent, theData)
34 myLayout = new QFormLayout(this);
35 ModuleBase_Tools::adjustMargins(myLayout);
36 myGroup = new QButtonGroup(this);
37 myGroup->setExclusive(true);
39 myVerticalAlignment = theData->getProperty("align_subs").find("vert") == 0;
41 connect(myGroup, SIGNAL(buttonToggled(int, bool)), SLOT(onPageChanged()));
44 ModuleBase_WidgetRadiobox::~ModuleBase_WidgetRadiobox()
48 int ModuleBase_WidgetRadiobox::addPage(ModuleBase_PageBase* thePage,
49 const QString& theName,
50 const QString& theCaseId,
51 const QPixmap& theIcon,
52 const QString& theTooltip)
54 ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon, theTooltip);
55 QWidget* aWgt = new QWidget(this);
56 QVBoxLayout* aLay = new QVBoxLayout(aWgt);
57 aLay->setContentsMargins(0, 0, 0, 0);
59 QRadioButton* aButton;
60 if (theIcon.isNull()) {
61 aButton = new QRadioButton(theName, aWgt);
62 aButton->setToolTip(translate(theTooltip.toStdString()));
65 aButton = new QRadioButton(aWgt);
66 aButton->setToolTip(translate(theName.toStdString()));
69 aLay->addWidget(aButton);
72 //QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
73 QWidget* aPage = thePage->pageWidget();
74 if (myVerticalAlignment) {
75 myLayout->addRow(aWgt);
76 myLayout->addRow(aPage);
78 myLayout->addRow(aWgt, aPage);
79 myGroup->addButton(aButton, myGroup->buttons().count());
81 bool isDefault = theCaseId.toStdString() == getDefaultValue();
82 aButton->setChecked(isDefault);
83 aPage->setEnabled(isDefault);
84 connect(aButton, SIGNAL(toggled(bool)), aPage, SLOT(setEnabled(bool)));
86 return myGroup->buttons().count();
89 int ModuleBase_WidgetRadiobox::currentPageIndex() const
91 return myGroup->checkedId();
94 void ModuleBase_WidgetRadiobox::setCurrentPageIndex(int theIndex)
96 bool isSignalsBlocked = myGroup->blockSignals(true);
97 myGroup->button(theIndex)->setChecked(true);
98 myGroup->blockSignals(isSignalsBlocked);