Salome HOME
57c7332c6f85f9822553f3bb4940c51ed4c74549
[modules/shaper.git] / src / ModuleBase / ModuleBase_ToolBox.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_ToolBox.cpp
4 // Created:     10 August 2015
5 // Author:      Alexandre SOLOVYOV
6
7 #include <ModuleBase_ToolBox.h>
8 #include <QButtonGroup>
9 #include <QStackedWidget>
10 #include <QHBoxLayout>
11 #include <QVBoxLayout>
12 #include <QToolButton>
13
14 ModuleBase_ToolBox::ModuleBase_ToolBox( QWidget* theParent )
15   : QFrame( theParent )
16 {
17   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
18   aMainLayout->setMargin( 0 );
19   aMainLayout->setSpacing( 0 );
20
21   myButtonsFrame = new QFrame( this );
22   myStack = new QStackedWidget( this );
23   aMainLayout->addWidget( myButtonsFrame, 0 );
24   aMainLayout->addWidget( myStack, 1 );
25
26   myButtonsGroup = new QButtonGroup(this);
27   myButtonsGroup->setExclusive( true );
28   myButtonsLayout = new QHBoxLayout( myButtonsFrame );
29   myButtonsLayout->setMargin( 0 );
30   myButtonsLayout->setSpacing( 5 );
31   myButtonsLayout->addStretch( 1 );
32
33   connect( myStack, SIGNAL( currentChanged( int ) ), this, SIGNAL( currentChanged( int ) ) );
34   connect( myButtonsGroup, SIGNAL( buttonPressed( int ) ), this, SLOT( onButton( int ) ) );
35 }
36
37 ModuleBase_ToolBox::~ModuleBase_ToolBox()
38 {
39 }
40
41 void ModuleBase_ToolBox::addItem( QWidget* thePage, const QString& theName, const QPixmap& theIcon )
42 {
43   int anOldCount = myStack->count();
44
45   myStack->addWidget( thePage );
46
47   QToolButton* aButton = new QToolButton( myButtonsFrame );
48   aButton->setFocusPolicy(Qt::StrongFocus);
49   aButton->setCheckable( true );
50   aButton->setIcon( theIcon );
51   aButton->setIconSize( theIcon.size() );
52   aButton->setToolTip( theName );
53   aButton->setObjectName( theName );
54   myButtonsGroup->addButton( aButton, anOldCount );
55   myButtonsLayout->insertWidget( anOldCount, aButton );
56 }
57
58 int ModuleBase_ToolBox::count() const
59 {
60   return myStack->count();
61 }
62
63 int ModuleBase_ToolBox::currentIndex() const
64 {
65   return myStack->currentIndex();
66 }
67
68 void ModuleBase_ToolBox::setCurrentIndex( const int theIndex )
69 {
70   myStack->setCurrentIndex( theIndex );
71   myButtonsGroup->button( theIndex )->setChecked( true );
72 }
73
74 void ModuleBase_ToolBox::onButton( int theIndex )
75 {
76   myStack->setCurrentIndex( theIndex );
77 }
78