1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_ToolBox.cpp
4 // Created: 10 August 2015
5 // Author: Alexandre SOLOVYOV
7 #include <ModuleBase_ToolBox.h>
8 #include <ModuleBase_ModelWidget.h>
10 #include <QButtonGroup>
11 #include <QStackedWidget>
12 #include <QHBoxLayout>
13 #include <QVBoxLayout>
14 #include <QToolButton>
16 #include <ModuleBase_PagedContainer.h>
18 ModuleBase_ToolBox::ModuleBase_ToolBox(QWidget* theParent, const bool theUseFrameStyleBox)
21 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
22 aMainLayout->setMargin(0);
23 aMainLayout->setSpacing(2);
25 if (theUseFrameStyleBox) {
26 setFrameStyle(QFrame::Box | QFrame::Raised);
27 aMainLayout->setMargin(2);
30 myButtonsFrame = new QFrame(this);
32 myStack = new QStackedWidget(this);
34 aMainLayout->addWidget(myButtonsFrame, 0);
35 aMainLayout->addWidget(myStack, 1);
37 myButtonsGroup = new QButtonGroup(this);
38 myButtonsGroup->setExclusive(true);
39 myButtonsLayout = new QHBoxLayout(myButtonsFrame);
40 myButtonsLayout->setMargin(0);
41 myButtonsLayout->setSpacing(5);
42 myButtonsLayout->addStretch(1);
44 connect(myStack, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));
45 connect(myButtonsGroup, SIGNAL(buttonPressed(int)), this, SLOT(onButton(int)));
48 ModuleBase_ToolBox::~ModuleBase_ToolBox()
52 void ModuleBase_ToolBox::addItem(QWidget* thePage, const QString& theName, const QPixmap& theIcon)
54 int anOldCount = myStack->count();
56 myStack->addWidget(thePage);
58 QToolButton* aButton = new QToolButton(myButtonsFrame);
59 aButton->setFocusPolicy(Qt::StrongFocus);
60 aButton->setCheckable(true);
61 aButton->setIcon(theIcon);
62 aButton->setIconSize(theIcon.size());
63 aButton->setToolTip(theName);
64 aButton->setObjectName(theName);
65 myButtonsGroup->addButton(aButton, anOldCount);
66 myButtonsLayout->insertWidget(anOldCount, aButton);
69 int ModuleBase_ToolBox::count() const
71 return myStack->count();
74 int ModuleBase_ToolBox::currentIndex() const
76 return myStack->currentIndex();
79 void ModuleBase_ToolBox::setCurrentIndex(const int theIndex)
81 myStack->setCurrentIndex(theIndex);
82 myButtonsGroup->button(theIndex)->setChecked(true);
85 void ModuleBase_ToolBox::onButton(int theIndex)
87 myStack->setCurrentIndex(theIndex);
90 bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget)
92 bool isOffToolBox = false;
94 QList<QWidget*> aControls = theWidget->getControls();
95 if (aControls.size() > 0) {
96 QWidget* aFirstControl = aControls.first();
98 QWidget* aWidget = aFirstControl;
99 QWidget* aParent = (QWidget*)aFirstControl->parent();
101 QStackedWidget* aStackedWidget = dynamic_cast<QStackedWidget*>(aParent);
102 if (aStackedWidget) {
103 int anIndex = aStackedWidget->currentIndex();
104 isOffToolBox = aStackedWidget->currentWidget() != aWidget;
108 aParent = (QWidget*)aWidget->parent();