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 ModuleBase_ToolBox::ModuleBase_ToolBox( QWidget* theParent )
19 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
20 aMainLayout->setMargin( 0 );
21 aMainLayout->setSpacing( 0 );
23 myButtonsFrame = new QFrame( this );
24 myStack = new QStackedWidget( this );
25 aMainLayout->addWidget( myButtonsFrame, 0 );
26 aMainLayout->addWidget( myStack, 1 );
28 myButtonsGroup = new QButtonGroup(this);
29 myButtonsGroup->setExclusive( true );
30 myButtonsLayout = new QHBoxLayout( myButtonsFrame );
31 myButtonsLayout->setMargin( 0 );
32 myButtonsLayout->setSpacing( 5 );
33 myButtonsLayout->addStretch( 1 );
35 connect( myStack, SIGNAL( currentChanged( int ) ), this, SIGNAL( currentChanged( int ) ) );
36 connect( myButtonsGroup, SIGNAL( buttonPressed( int ) ), this, SLOT( onButton( int ) ) );
39 ModuleBase_ToolBox::~ModuleBase_ToolBox()
43 void ModuleBase_ToolBox::addItem( QWidget* thePage, const QString& theName, const QPixmap& theIcon )
45 int anOldCount = myStack->count();
47 myStack->addWidget( thePage );
49 QToolButton* aButton = new QToolButton( myButtonsFrame );
50 aButton->setFocusPolicy(Qt::StrongFocus);
51 aButton->setCheckable( true );
52 aButton->setIcon( theIcon );
53 aButton->setIconSize( theIcon.size() );
54 aButton->setToolTip( theName );
55 aButton->setObjectName( theName );
56 myButtonsGroup->addButton( aButton, anOldCount );
57 myButtonsLayout->insertWidget( anOldCount, aButton );
60 int ModuleBase_ToolBox::count() const
62 return myStack->count();
65 int ModuleBase_ToolBox::currentIndex() const
67 return myStack->currentIndex();
70 void ModuleBase_ToolBox::setCurrentIndex( const int theIndex )
72 myStack->setCurrentIndex( theIndex );
73 myButtonsGroup->button( theIndex )->setChecked( true );
76 void ModuleBase_ToolBox::onButton( int theIndex )
78 myStack->setCurrentIndex( theIndex );
81 bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget)
83 bool isOffToolBox = false;
85 QList<QWidget*> aControls = theWidget->getControls();
86 if (aControls.size() > 0) {
87 QWidget* aFirstControl = aControls.first();
89 QWidget* aWidget = aFirstControl;
90 QWidget* aParent = (QWidget*)aFirstControl->parent();
92 QStackedWidget* aStackedWidget = dynamic_cast<QStackedWidget*>(aParent);
94 int anIndex = aStackedWidget->currentIndex();
95 isOffToolBox = aStackedWidget->currentWidget() != aWidget;
99 aParent = (QWidget*)aWidget->parent();