]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetSwitch.cpp
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 /*
21  * ModuleBase_WidgetSwitch.cpp
22  *
23  *  Created on: Apr 16, 2014
24  *      Author: sbh
25  */
26
27 #include <ModuleBase_WidgetSwitch.h>
28 #include <ModuleBase_ModelWidget.h>
29 #include <ModuleBase_PageBase.h>
30 #include <ModuleBase_Tools.h>
31
32 #include <QComboBox>
33 #include <QFrame>
34 #include <QSpacerItem>
35 #include <QStackedLayout>
36 #include <QVBoxLayout>
37
38 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent,
39   const Config_WidgetAPI* theData)
40 : ModuleBase_PagedContainer(theParent, theData)
41 {
42   QVBoxLayout*  aMainLay = new QVBoxLayout(this);
43   //aMainLay->setContentsMargins(2, 4, 2, 2);
44   ModuleBase_Tools::adjustMargins(aMainLay);
45   myCombo = new QComboBox(this);
46   myCombo->hide();
47   myPagesLayout = new QStackedLayout(this);
48   aMainLay->addWidget(myCombo);
49   aMainLay->addLayout(myPagesLayout, 1);
50   setLayout(aMainLay);
51
52   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageChanged()));
53   connect(myCombo, SIGNAL(activated(int)), myPagesLayout, SLOT(setCurrentIndex(int)));
54 }
55
56 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
57 {
58 }
59
60
61 int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName,
62                                                                    const QString& theCaseId,
63                                                                    const QPixmap& theIcon )
64 {
65   int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon);
66   myCombo->addItem(theName);
67   int aResultCount = myCombo->count();
68   if (aResultCount == 2)
69     myCombo->show();
70   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
71   aFrame->setFrameShape(QFrame::Box);
72   aFrame->setFrameStyle(QFrame::Sunken);
73   myPagesLayout->addWidget(aFrame);
74   return aResultCount;
75 }
76
77 int ModuleBase_WidgetSwitch::currentPageIndex() const
78 {
79   int aComboIndex = myCombo->currentIndex();
80   return aComboIndex;
81 }
82
83
84 void ModuleBase_WidgetSwitch::setCurrentPageIndex(int theIndex)
85 {
86   bool isComboSignalsBlocked = myCombo->blockSignals(true);
87   bool isPagesLayoutSignalsBlocked = myPagesLayout->blockSignals(true);
88   myCombo->setCurrentIndex(theIndex);
89   myPagesLayout->setCurrentIndex(theIndex);
90   myCombo->blockSignals(isComboSignalsBlocked);
91   myPagesLayout->blockSignals(isPagesLayoutSignalsBlocked);
92 }