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_ToolBox.h>
22 #include <ModuleBase_ModelWidget.h>
24 #include <QButtonGroup>
25 #include <QStackedWidget>
26 #include <QHBoxLayout>
27 #include <QVBoxLayout>
28 #include <QToolButton>
30 #include <ModuleBase_PagedContainer.h>
32 ModuleBase_ToolBox::ModuleBase_ToolBox(QWidget* theParent, const bool theUseFrameStyleBox)
35 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
36 aMainLayout->setMargin(0);
37 aMainLayout->setSpacing(2);
39 if (theUseFrameStyleBox) {
40 setFrameStyle(QFrame::Box | QFrame::Raised);
41 aMainLayout->setMargin(2);
44 myButtonsFrame = new QFrame(this);
46 myStack = new QStackedWidget(this);
48 aMainLayout->addWidget(myButtonsFrame, 0);
49 aMainLayout->addWidget(myStack, 1);
51 myButtonsGroup = new QButtonGroup(this);
52 myButtonsGroup->setExclusive(true);
53 myButtonsLayout = new QHBoxLayout(myButtonsFrame);
54 myButtonsLayout->setMargin(0);
55 myButtonsLayout->setSpacing(5);
56 myButtonsLayout->addStretch(1);
58 connect(myStack, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));
59 connect(myButtonsGroup, SIGNAL(buttonPressed(int)), this, SLOT(onButton(int)));
62 ModuleBase_ToolBox::~ModuleBase_ToolBox()
66 void ModuleBase_ToolBox::addItem(QWidget* thePage, const QString& theName, const QPixmap& theIcon)
68 int anOldCount = myStack->count();
70 myStack->addWidget(thePage);
72 QToolButton* aButton = new QToolButton(myButtonsFrame);
73 aButton->setFocusPolicy(Qt::StrongFocus);
74 aButton->setCheckable(true);
75 aButton->setIcon(theIcon);
76 aButton->setIconSize(theIcon.size());
77 aButton->setToolTip(theName);
78 aButton->setObjectName(theName);
79 myButtonsGroup->addButton(aButton, anOldCount);
80 myButtonsLayout->insertWidget(anOldCount, aButton);
83 int ModuleBase_ToolBox::count() const
85 return myStack->count();
88 int ModuleBase_ToolBox::currentIndex() const
90 return myStack->currentIndex();
93 void ModuleBase_ToolBox::setCurrentIndex(const int theIndex)
95 myStack->setCurrentIndex(theIndex);
96 myButtonsGroup->button(theIndex)->setChecked(true);
99 void ModuleBase_ToolBox::onButton(int theIndex)
101 myStack->setCurrentIndex(theIndex);
104 bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget)
106 bool isOffToolBox = false;
108 QList<QWidget*> aControls = theWidget->getControls();
109 if (aControls.size() > 0) {
110 QWidget* aFirstControl = aControls.first();
112 QWidget* aWidget = aFirstControl;
113 QWidget* aParent = (QWidget*)aFirstControl->parent();
115 QStackedWidget* aStackedWidget = dynamic_cast<QStackedWidget*>(aParent);
116 if (aStackedWidget) {
117 int anIndex = aStackedWidget->currentIndex();
118 isOffToolBox = aStackedWidget->currentWidget() != aWidget;
122 aParent = (QWidget*)aWidget->parent();