Salome HOME
d643e969acb3c2d7dea57f3b9fdeefd5cc3500e5
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetToolbox.cpp
1 // Copyright (C) 2014-2023  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
18 //
19
20 #include <ModuleBase_WidgetToolbox.h>
21 #include <ModuleBase_PageBase.h>
22 #include <ModuleBase_ModelWidget.h>
23 #include <ModuleBase_Tools.h>
24 #include <ModuleBase_ToolBox.h>
25
26 #include <ModelAPI_AttributeString.h>
27
28 #include <QWidget>
29 #include <QList>
30 #include <QVBoxLayout>
31 #include <QIcon>
32
33 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent,
34                                                    const Config_WidgetAPI* theData)
35 : ModuleBase_PagedContainer(theParent, theData)
36 {
37   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
38   ModuleBase_Tools::zeroMargins(aMainLayout);
39
40   bool aHasContainerParent = false;
41   QWidget* aParent = dynamic_cast<QWidget*>(parent());
42   while(aParent && !aHasContainerParent) {
43     ModuleBase_PagedContainer* aPagedContainer = dynamic_cast<ModuleBase_PagedContainer*>(aParent);
44     aHasContainerParent = aPagedContainer;
45     aParent = dynamic_cast<QWidget*>(aParent->parent());
46   }
47   myToolBox = new ModuleBase_ToolBox(this, aHasContainerParent);
48   // Dark-grey rounded tabs with button-like border #and bold font
49   // TODO: apply style to custom widget
50   QString css = "QToolBox::tab{background-color:#c8c8c8;"
51                               "border-radius:5px;"
52                               "border:1px inset;"
53                               //"font-weight:700;"
54                               "border-color:#fff #505050 #505050 #fff;}";
55   myToolBox->setStyleSheet(css);
56   // default vertical size policy is preferred
57   aMainLayout->addWidget(myToolBox);
58
59   connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
60 }
61
62 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
63 {
64 }
65
66 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
67                                       const QString& theName,
68                                       const QString& theCaseId,
69                                       const QPixmap& theIcon,
70                                       const QString& theTooltip)
71 {
72   ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon, theTooltip);
73   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
74   myToolBox->addItem(aFrame, translate(theName.toStdString()), 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