1 // Copyright (C) 2014-2019 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
20 #include <ModuleBase_ToolBox.h>
21 #include <ModuleBase_ModelWidget.h>
23 #include <QButtonGroup>
24 #include <QStackedWidget>
25 #include <QHBoxLayout>
26 #include <QVBoxLayout>
27 #include <QToolButton>
29 #include <ModuleBase_PagedContainer.h>
31 ModuleBase_ToolBox::ModuleBase_ToolBox(QWidget* theParent, const bool theUseFrameStyleBox)
34 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
35 aMainLayout->setMargin(0);
36 aMainLayout->setSpacing(2);
38 if (theUseFrameStyleBox) {
39 setFrameStyle(QFrame::Box | QFrame::Raised);
40 aMainLayout->setMargin(2);
43 myButtonsFrame = new QFrame(this);
45 myStack = new QStackedWidget(this);
47 aMainLayout->addWidget(myButtonsFrame, 0);
48 aMainLayout->addWidget(myStack, 1);
50 myButtonsGroup = new QButtonGroup(this);
51 myButtonsGroup->setExclusive(true);
52 myButtonsLayout = new QHBoxLayout(myButtonsFrame);
53 myButtonsLayout->setMargin(0);
54 myButtonsLayout->setSpacing(5);
55 myButtonsLayout->addStretch(1);
57 connect(myStack, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));
58 connect(myButtonsGroup, SIGNAL(buttonPressed(int)), this, SLOT(onButton(int)));
61 ModuleBase_ToolBox::~ModuleBase_ToolBox()
65 void ModuleBase_ToolBox::addItem(QWidget* thePage, const QString& theName, const QPixmap& theIcon)
67 int anOldCount = myStack->count();
69 myStack->addWidget(thePage);
71 QToolButton* aButton = new QToolButton(myButtonsFrame);
72 aButton->setFocusPolicy(Qt::StrongFocus);
73 aButton->setCheckable(true);
75 aButton->setText(theName);
77 aButton->setIcon(theIcon);
78 aButton->setIconSize(theIcon.size());
80 aButton->setToolTip(theName);
81 aButton->setObjectName(theName);
82 myButtonsGroup->addButton(aButton, anOldCount);
83 myButtonsLayout->insertWidget(anOldCount, aButton);
86 int ModuleBase_ToolBox::count() const
88 return myStack->count();
91 int ModuleBase_ToolBox::currentIndex() const
93 return myStack->currentIndex();
96 void ModuleBase_ToolBox::setCurrentIndex(const int theIndex)
98 myStack->setCurrentIndex(theIndex);
99 myButtonsGroup->button(theIndex)->setChecked(true);
102 void ModuleBase_ToolBox::onButton(int theIndex)
104 myStack->setCurrentIndex(theIndex);
107 bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget)
109 bool isOffToolBox = false;
111 QList<QWidget*> aControls = theWidget->getControls();
112 if (aControls.size() > 0) {
113 QWidget* aFirstControl = aControls.first();
115 QWidget* aWidget = aFirstControl;
116 QWidget* aParent = (QWidget*)aFirstControl->parent();
118 QStackedWidget* aStackedWidget = dynamic_cast<QStackedWidget*>(aParent);
119 if (aStackedWidget) {
120 int anIndex = aStackedWidget->currentIndex();
121 isOffToolBox = aStackedWidget->currentWidget() != aWidget;
125 aParent = (QWidget*)aWidget->parent();