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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 * ModuleBase_WidgetToolbox.cpp
23 * Created on: Feb 27, 2015
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>
33 #include <ModelAPI_AttributeString.h>
37 #include <QVBoxLayout>
40 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent,
41 const Config_WidgetAPI* theData)
42 : ModuleBase_PagedContainer(theParent, theData)
44 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
45 ModuleBase_Tools::zeroMargins(aMainLayout);
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());
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;"
61 "border-color:#fff #505050 #505050 #fff;}";
62 myToolBox->setStyleSheet(css);
63 // default vertical size policy is preferred
64 aMainLayout->addWidget(myToolBox);
66 connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
69 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
73 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
74 const QString& theName,
75 const QString& theCaseId,
76 const QPixmap& theIcon )
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();
84 int ModuleBase_WidgetToolbox::currentPageIndex() const
86 return myToolBox->currentIndex();
89 void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
91 bool isSignalsBlocked = myToolBox->blockSignals(true);
92 myToolBox->setCurrentIndex(theIndex);
93 myToolBox->blockSignals(isSignalsBlocked);