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);
76 aButton->setText(theName);
78 aButton->setIcon(theIcon);
79 aButton->setIconSize(theIcon.size());
81 aButton->setToolTip(theName);
82 aButton->setObjectName(theName);
83 myButtonsGroup->addButton(aButton, anOldCount);
84 myButtonsLayout->insertWidget(anOldCount, aButton);
87 int ModuleBase_ToolBox::count() const
89 return myStack->count();
92 int ModuleBase_ToolBox::currentIndex() const
94 return myStack->currentIndex();
97 void ModuleBase_ToolBox::setCurrentIndex(const int theIndex)
99 myStack->setCurrentIndex(theIndex);
100 myButtonsGroup->button(theIndex)->setChecked(true);
103 void ModuleBase_ToolBox::onButton(int theIndex)
105 myStack->setCurrentIndex(theIndex);
108 bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget)
110 bool isOffToolBox = false;
112 QList<QWidget*> aControls = theWidget->getControls();
113 if (aControls.size() > 0) {
114 QWidget* aFirstControl = aControls.first();
116 QWidget* aWidget = aFirstControl;
117 QWidget* aParent = (QWidget*)aFirstControl->parent();
119 QStackedWidget* aStackedWidget = dynamic_cast<QStackedWidget*>(aParent);
120 if (aStackedWidget) {
121 int anIndex = aStackedWidget->currentIndex();
122 isOffToolBox = aStackedWidget->currentWidget() != aWidget;
126 aParent = (QWidget*)aWidget->parent();