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