1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
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>
27 #include <ModelAPI_AttributeString.h>
31 #include <QVBoxLayout>
34 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent,
35 const Config_WidgetAPI* theData)
36 : ModuleBase_PagedContainer(theParent, theData)
38 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
39 ModuleBase_Tools::zeroMargins(aMainLayout);
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());
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;"
55 "border-color:#fff #505050 #505050 #fff;}";
56 myToolBox->setStyleSheet(css);
57 // default vertical size policy is preferred
58 aMainLayout->addWidget(myToolBox);
60 connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
63 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
67 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
68 const QString& theName,
69 const QString& theCaseId,
70 const QPixmap& theIcon )
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();
78 int ModuleBase_WidgetToolbox::currentPageIndex() const
80 return myToolBox->currentIndex();
83 void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
85 bool isSignalsBlocked = myToolBox->blockSignals(true);
86 myToolBox->setCurrentIndex(theIndex);
87 myToolBox->blockSignals(isSignalsBlocked);