Salome HOME
Patch modules/smesh.git for Doxygen typos/grammar + misc. typos
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_RadioButtonsGrpWdg.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "StdMeshersGUI_RadioButtonsGrpWdg.h"
20
21 #include "SMESHGUI.h"
22
23 #include <SUIT_ResourceMgr.h>
24
25 #include <QGridLayout>
26 #include <QLabel>
27 #include <QRadioButton>
28 #include <QButtonGroup>
29 #include <QStringList>
30
31 #define SPACING 6
32 #define MARGIN  11
33
34 //================================================================================
35 /*!
36  * \brief Creates a QGroupBox with a given title
37  */
38 //================================================================================
39
40 StdMeshersGUI_RadioButtonsGrpWdg::StdMeshersGUI_RadioButtonsGrpWdg( const QString& title )
41   : QGroupBox( title )
42 {
43   myButtonGrp = new QButtonGroup( this );
44 }
45
46 //================================================================================
47 /*!
48  * \brief Creates a given number of button labels with given labels (QString's)
49  */
50 //================================================================================
51
52 void StdMeshersGUI_RadioButtonsGrpWdg::setButtonLabels( const QStringList& buttonLabels,
53                                                         const QStringList& buttonIcons )
54 {
55   QGridLayout* layout = new QGridLayout( this );
56   layout->setSpacing(SPACING);
57   layout->setMargin(MARGIN);
58
59   for ( int id = 0; id < buttonLabels.size(); ++id )
60   {
61     QRadioButton* button = new QRadioButton( buttonLabels.at(id), this );
62     layout->addWidget( button, id, 0 );
63     myButtonGrp->addButton( button, id );
64
65     if ( id < buttonIcons.count() )
66     {
67       QPixmap pmi (SMESHGUI::resourceMgr()->loadPixmap("SMESH", buttonIcons.at(id)));
68       if ( !pmi.isNull() ) {
69         QLabel* pixLabel = new QLabel( this );
70         pixLabel->setPixmap( pmi );
71         layout->addWidget( pixLabel, id, 1 );
72       }
73     }
74   }
75 }
76
77 //================================================================================
78 /*!
79  * \brief Set checked a radio button with a give id.
80  */
81 //================================================================================
82
83 void StdMeshersGUI_RadioButtonsGrpWdg::setChecked(int id)
84 {
85   if ( QAbstractButton* but = myButtonGrp->button( id ))
86     but->setChecked( true );
87 }
88
89 //================================================================================
90 /*!
91  * \brief Return id (zero based) of a checked radio button
92  */
93 //================================================================================
94
95 int StdMeshersGUI_RadioButtonsGrpWdg::checkedId () const
96 {
97   return myButtonGrp->checkedId();
98 }