Salome HOME
Process tool tip property for radio buttons
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetRadiobox.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <ModuleBase_WidgetRadiobox.h>
22 #include <ModuleBase_PageBase.h>
23
24 #include <QFormLayout>
25 #include <QRadioButton>
26 #include <QFrame>
27 #include <QButtonGroup>
28
29
30 ModuleBase_WidgetRadiobox::ModuleBase_WidgetRadiobox(QWidget* theParent,
31                                                      const Config_WidgetAPI* theData)
32   : ModuleBase_PagedContainer(theParent, theData)
33 {
34   myLayout = new QFormLayout(this);
35   ModuleBase_Tools::adjustMargins(myLayout);
36   myGroup = new QButtonGroup(this);
37   myGroup->setExclusive(true);
38
39   connect(myGroup, SIGNAL(buttonToggled(int, bool)), SLOT(onPageChanged()));
40 }
41
42 ModuleBase_WidgetRadiobox::~ModuleBase_WidgetRadiobox()
43 {
44 }
45
46 int ModuleBase_WidgetRadiobox::addPage(ModuleBase_PageBase* thePage,
47                                         const QString& theName,
48                                         const QString& theCaseId,
49                                         const QPixmap& theIcon,
50                                         const QString& theTooltip)
51 {
52   ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon, theTooltip);
53   QWidget* aWgt = new QWidget(this);
54   QVBoxLayout* aLay = new QVBoxLayout(aWgt);
55   aLay->setContentsMargins(0, 0, 0, 0);
56
57   QRadioButton* aButton;
58   if (theIcon.isNull()) {
59     aButton = new QRadioButton(theName, aWgt);
60     aButton->setToolTip(theTooltip);
61   }
62   else {
63     aButton = new QRadioButton(aWgt);
64     aButton->setToolTip(theName);
65   }
66   aLay->addStretch();
67   aLay->addWidget(aButton);
68   aLay->addStretch();
69
70   //QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
71   QWidget* aPage = thePage->pageWidget();
72   myLayout->addRow(aWgt, aPage);
73   myGroup->addButton(aButton, myGroup->buttons().count());
74
75   bool isDefault = theCaseId.toStdString() == getDefaultValue();
76   aButton->setChecked(isDefault);
77   aPage->setEnabled(isDefault);
78   connect(aButton, SIGNAL(toggled(bool)), aPage, SLOT(setEnabled(bool)));
79
80   return myGroup->buttons().count();
81 }
82
83 int ModuleBase_WidgetRadiobox::currentPageIndex() const
84 {
85   return myGroup->checkedId();
86 }
87
88 void ModuleBase_WidgetRadiobox::setCurrentPageIndex(int theIndex)
89 {
90   bool isSignalsBlocked = myGroup->blockSignals(true);
91   myGroup->button(theIndex)->setChecked(true);
92   myGroup->blockSignals(isSignalsBlocked);
93 }