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(2);
23 myButtonsFrame = new QFrame( this );
25 myStack = new QStackedWidget( this );
26 myStack->setFrameStyle(QFrame::Box | QFrame::Raised);
28 aMainLayout->addWidget( myButtonsFrame, 0 );
29 aMainLayout->addWidget( myStack, 1 );
31 myButtonsGroup = new QButtonGroup(this);
32 myButtonsGroup->setExclusive( true );
33 myButtonsLayout = new QHBoxLayout( myButtonsFrame );
34 myButtonsLayout->setMargin( 0 );
35 myButtonsLayout->setSpacing( 5 );
36 myButtonsLayout->addStretch( 1 );
38 connect( myStack, SIGNAL( currentChanged( int ) ), this, SIGNAL( currentChanged( int ) ) );
39 connect( myButtonsGroup, SIGNAL( buttonPressed( int ) ), this, SLOT( onButton( int ) ) );
42 ModuleBase_ToolBox::~ModuleBase_ToolBox()
46 void ModuleBase_ToolBox::addItem( QWidget* thePage, const QString& theName, const QPixmap& theIcon )
48 int anOldCount = myStack->count();
50 myStack->addWidget( thePage );
52 QToolButton* aButton = new QToolButton( myButtonsFrame );
53 aButton->setFocusPolicy(Qt::StrongFocus);
54 aButton->setCheckable( true );
55 aButton->setIcon( theIcon );
56 aButton->setIconSize( theIcon.size() );
57 aButton->setToolTip( theName );
58 aButton->setObjectName( theName );
59 myButtonsGroup->addButton( aButton, anOldCount );
60 myButtonsLayout->insertWidget( anOldCount, aButton );
63 int ModuleBase_ToolBox::count() const
65 return myStack->count();
68 int ModuleBase_ToolBox::currentIndex() const
70 return myStack->currentIndex();
73 void ModuleBase_ToolBox::setCurrentIndex( const int theIndex )
75 myStack->setCurrentIndex( theIndex );
76 myButtonsGroup->button( theIndex )->setChecked( true );
79 void ModuleBase_ToolBox::onButton( int theIndex )
81 myStack->setCurrentIndex( theIndex );
84 bool ModuleBase_ToolBox::isOffToolBoxParent(ModuleBase_ModelWidget* theWidget)
86 bool isOffToolBox = false;
88 QList<QWidget*> aControls = theWidget->getControls();
89 if (aControls.size() > 0) {
90 QWidget* aFirstControl = aControls.first();
92 QWidget* aWidget = aFirstControl;
93 QWidget* aParent = (QWidget*)aFirstControl->parent();
95 QStackedWidget* aStackedWidget = dynamic_cast<QStackedWidget*>(aParent);
97 int anIndex = aStackedWidget->currentIndex();
98 isOffToolBox = aStackedWidget->currentWidget() != aWidget;
102 aParent = (QWidget*)aWidget->parent();