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 const QString AStyle = "QToolButton:checked {border: 1px solid black; background-color:#C0DCF3}";
34 ModuleBase_ToolBox::ModuleBase_ToolBox(QWidget* theParent, const bool theUseFrameStyleBox)
37 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
38 aMainLayout->setMargin(0);
39 aMainLayout->setSpacing(2);
41 if (theUseFrameStyleBox) {
42 setFrameStyle(QFrame::Box | QFrame::Raised);
43 aMainLayout->setMargin(2);
46 myButtonsFrame = new QFrame(this);
48 myStack = new QStackedWidget(this);
50 aMainLayout->addWidget(myButtonsFrame, 0);
51 aMainLayout->addWidget(myStack, 1);
53 myButtonsGroup = new QButtonGroup(this);
54 myButtonsGroup->setExclusive(true);
55 myButtonsLayout = new QHBoxLayout(myButtonsFrame);
56 myButtonsLayout->setMargin(0);
57 myButtonsLayout->setSpacing(5);
58 myButtonsLayout->addStretch(1);
60 connect(myStack, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));
61 connect(myButtonsGroup, SIGNAL(buttonPressed(int)), this, SLOT(onButton(int)));
64 ModuleBase_ToolBox::~ModuleBase_ToolBox()
68 void ModuleBase_ToolBox::addItem(QWidget* thePage, const QString& theName, const QPixmap& theIcon)
70 int anOldCount = myStack->count();
72 myStack->addWidget(thePage);
74 QToolButton* aButton = new QToolButton(myButtonsFrame);
75 aButton->setFocusPolicy(Qt::StrongFocus);
76 aButton->setCheckable(true);
77 aButton->setStyleSheet(AStyle);
79 aButton->setText(theName);
81 aButton->setIcon(theIcon);
82 aButton->setIconSize(theIcon.size());
84 aButton->setToolTip(theName);
85 aButton->setObjectName(theName);
86 myButtonsGroup->addButton(aButton, anOldCount);
87 myButtonsLayout->insertWidget(anOldCount, aButton);
90 int ModuleBase_ToolBox::count() const
92 return myStack->count();
95 int ModuleBase_ToolBox::currentIndex() const
97 return myStack->currentIndex();
100 void ModuleBase_ToolBox::setCurrentIndex(const int theIndex)
102 myStack->setCurrentIndex(theIndex);
103 myButtonsGroup->button(theIndex)->setChecked(true);
106 void ModuleBase_ToolBox::onButton(int theIndex)
108 myStack->setCurrentIndex(theIndex);
111 bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget)
113 bool isOffToolBox = false;
115 QList<QWidget*> aControls = theWidget->getControls();
116 if (aControls.size() > 0) {
117 QWidget* aFirstControl = aControls.first();
119 QWidget* aWidget = aFirstControl;
120 QWidget* aParent = (QWidget*)aFirstControl->parent();
122 QStackedWidget* aStackedWidget = dynamic_cast<QStackedWidget*>(aParent);
123 if (aStackedWidget) {
124 int anIndex = aStackedWidget->currentIndex();
125 isOffToolBox = aStackedWidget->currentWidget() != aWidget;
129 aParent = (QWidget*)aWidget->parent();