Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetToolbox.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_WidgetToolbox.h>
22 #include <ModuleBase_PageBase.h>
23 #include <ModuleBase_ModelWidget.h>
24 #include <ModuleBase_Tools.h>
25 #include <ModuleBase_ToolBox.h>
26
27 #include <ModelAPI_AttributeString.h>
28
29 #include <QWidget>
30 #include <QList>
31 #include <QVBoxLayout>
32 #include <QIcon>
33
34 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent,
35                                                    const Config_WidgetAPI* theData)
36 : ModuleBase_PagedContainer(theParent, theData)
37 {
38   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
39   ModuleBase_Tools::zeroMargins(aMainLayout);
40
41   bool aHasContainerParent = false;
42   QWidget* aParent = dynamic_cast<QWidget*>(parent());
43   while(aParent && !aHasContainerParent) {
44     ModuleBase_PagedContainer* aPagedContainer = dynamic_cast<ModuleBase_PagedContainer*>(aParent);
45     aHasContainerParent = aPagedContainer;
46     aParent = dynamic_cast<QWidget*>(aParent->parent());
47   }
48   myToolBox = new ModuleBase_ToolBox(this, aHasContainerParent);
49   // Dark-grey rounded tabs with button-like border #and bold font
50   // TODO: apply style to custom widget
51   QString css = "QToolBox::tab{background-color:#c8c8c8;"
52                               "border-radius:5px;"
53                               "border:1px inset;"
54                               //"font-weight:700;"
55                               "border-color:#fff #505050 #505050 #fff;}";
56   myToolBox->setStyleSheet(css);
57   // default vertical size policy is preferred
58   aMainLayout->addWidget(myToolBox);
59
60   connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
61 }
62
63 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
64 {
65 }
66
67 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
68                                       const QString& theName,
69                                       const QString& theCaseId,
70                                       const QPixmap& theIcon )
71 {
72   ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon);
73   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
74   myToolBox->addItem(aFrame, theName, theIcon );
75   return myToolBox->count();
76 }
77
78 int ModuleBase_WidgetToolbox::currentPageIndex() const
79 {
80   return myToolBox->currentIndex();
81 }
82
83 void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
84 {
85   bool isSignalsBlocked = myToolBox->blockSignals(true);
86   myToolBox->setCurrentIndex(theIndex);
87   myToolBox->blockSignals(isSignalsBlocked);
88 }
89
90