Salome HOME
Process tool tip property for radio buttons
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSwitch.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_WidgetSwitch.h>
22 #include <ModuleBase_ModelWidget.h>
23 #include <ModuleBase_PageBase.h>
24 #include <ModuleBase_Tools.h>
25
26 #include <QComboBox>
27 #include <QFrame>
28 #include <QSpacerItem>
29 #include <QStackedLayout>
30 #include <QVBoxLayout>
31
32 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent,
33   const Config_WidgetAPI* theData)
34 : ModuleBase_PagedContainer(theParent, theData)
35 {
36   myRemeberChoice = false;
37   QVBoxLayout*  aMainLay = new QVBoxLayout(this);
38   //aMainLay->setContentsMargins(2, 4, 2, 2);
39   ModuleBase_Tools::adjustMargins(aMainLay);
40   myCombo = new QComboBox(this);
41   myCombo->hide();
42   myPagesLayout = new QStackedLayout(this);
43   aMainLay->addWidget(myCombo);
44   aMainLay->addLayout(myPagesLayout, 1);
45   setLayout(aMainLay);
46
47   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageChanged()));
48   connect(myCombo, SIGNAL(activated(int)), myPagesLayout, SLOT(setCurrentIndex(int)));
49 }
50
51 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
52 {
53 }
54
55
56 int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName,
57                                                                    const QString& theCaseId,
58                                                                    const QPixmap& theIcon,
59                                                                    const QString& theTooltip)
60 {
61   int aSuperCount =
62     ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon, theTooltip);
63   myCombo->addItem(theName);
64   int aResultCount = myCombo->count();
65   if (aResultCount == 2)
66     myCombo->show();
67   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
68   aFrame->setFrameShape(QFrame::Box);
69   aFrame->setFrameStyle(QFrame::Sunken);
70   myPagesLayout->addWidget(aFrame);
71   return aResultCount;
72 }
73
74 int ModuleBase_WidgetSwitch::currentPageIndex() const
75 {
76   int aComboIndex = myCombo->currentIndex();
77   return aComboIndex;
78 }
79
80
81 void ModuleBase_WidgetSwitch::setCurrentPageIndex(int theIndex)
82 {
83   bool isComboSignalsBlocked = myCombo->blockSignals(true);
84   bool isPagesLayoutSignalsBlocked = myPagesLayout->blockSignals(true);
85   myCombo->setCurrentIndex(theIndex);
86   myPagesLayout->setCurrentIndex(theIndex);
87   myCombo->blockSignals(isComboSignalsBlocked);
88   myPagesLayout->blockSignals(isPagesLayoutSignalsBlocked);
89 }