Salome HOME
24560d0ef13e90dc541d1556ef224895075d93b0
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_aParameterDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_aParameterDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #include "QAD_Tools.h"
30 #include "QAD_Desktop.h"
31 #include "QAD_Application.h"
32
33 #include "SMESHGUI_aParameterDlg.h"
34 #include "SMESHGUI_aParameter.h"
35 #include "SMESHGUI.h"
36 #include "SMESHGUI_SpinBox.h"
37
38 // QT Includes
39 #include <qgroupbox.h>
40 #include <qlabel.h>
41 #include <qpushbutton.h>
42 #include <qlayout.h>
43 #include <qspinbox.h>
44 #include <qvalidator.h>
45
46 using namespace std;
47
48 //====================================================================================== 
49 // function : SMESHGUI_aParameterDlg()
50 //
51 //  The dialog will by default be modal, unless you set 'modal' to
52 //  false when constructing dialog
53 // 
54 //====================================================================================== 
55 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg
56                                         (std::list<SMESHGUI_aParameterPtr> params,
57                                          QWidget*                          parent,
58                                          QString                           title,
59                                          bool                              modal ) 
60 : QDialog( parent, "MyParameterDialog", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
61   myParamList( params )
62 {
63   /* creating widgets */
64   init();
65   /* title */
66   setCaption( title );
67
68   /* Move widget on the botton right corner of main widget */
69   QAD_Tools::centerWidget( this, parent );
70 }
71
72 //====================================================================================== 
73 // function : SMESHGUI_aParameterDlg::init()
74 // purpose  : creates dialog's layout
75 //====================================================================================== 
76 void SMESHGUI_aParameterDlg::init()
77 {
78   setSizeGripEnabled( TRUE );
79   
80   QGridLayout* topLayout = new QGridLayout( this );
81   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
82
83   /***************************************************************/
84   QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
85   GroupC1->setColumnLayout(0, Qt::Vertical );
86   GroupC1->layout()->setSpacing( 0 );
87   GroupC1->layout()->setMargin( 0 );
88   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
89   GroupC1Layout->setAlignment( Qt::AlignTop );
90   GroupC1Layout->setSpacing( 6 );
91   GroupC1Layout->setMargin( 11 );
92   /* Spin boxes with labels */
93   list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
94   for ( int row = 0; paramIt != myParamList.end(); paramIt++ , row++ )
95   {
96     SMESHGUI_aParameterPtr param = (*paramIt);
97     QLabel * label = new QLabel( GroupC1, "TextLabel" );
98     GroupC1Layout->addWidget( label, row, 0 );
99     label->setText( param->Label() );
100     QWidget* aSpinWidget;
101     switch ( param->GetType() ) {
102     case SMESHGUI_aParameter::DOUBLE: {
103       SMESHGUI_SpinBox* spin = new SMESHGUI_SpinBox( GroupC1 );
104       aSpinWidget = spin;
105       spin->setPrecision( 12 );
106       break;
107     }
108     case SMESHGUI_aParameter::INT: {
109       QSpinBox* spin = new QSpinBox( GroupC1 );
110       aSpinWidget = spin;
111       break;
112     }
113     default:;
114     }
115     GroupC1Layout->addWidget( aSpinWidget, row, 1 );
116     aSpinWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
117     aSpinWidget->setMinimumSize( 150, 0 );
118     param->InitializeWidget( aSpinWidget );
119     mySpinList.push_back( aSpinWidget );
120   }
121   
122   /***************************************************************/
123   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
124   GroupButtons->setColumnLayout(0, Qt::Vertical );
125   GroupButtons->layout()->setSpacing( 0 );
126   GroupButtons->layout()->setMargin( 0 );
127   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
128   GroupButtonsLayout->setAlignment( Qt::AlignTop );
129   GroupButtonsLayout->setSpacing( 6 );
130   GroupButtonsLayout->setMargin( 11 );
131   /* Ok button */
132   myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
133   myButtonOk->setText( tr("SMESH_BUT_OK") );
134   myButtonOk->setAutoDefault( TRUE );
135   myButtonOk->setDefault( TRUE );
136   GroupButtonsLayout->addWidget( myButtonOk, 0, 0 );
137   /* add spacer between buttons */
138   GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
139   /* Cancel button */
140   myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
141   myButtonCancel->setText( tr("SMESH_BUT_CANCEL") );
142   myButtonCancel->setAutoDefault( TRUE );
143   GroupButtonsLayout->addWidget( myButtonCancel, 0, 2 );
144   
145   /***************************************************************/
146   topLayout->addWidget( GroupC1,      0, 0);
147   topLayout->addWidget( GroupButtons, 1, 0);
148
149   /* signals and slots connections */
150   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
151   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
152
153   /* Retrieve SMESHGUI */
154   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
155 }
156
157
158 //====================================================================================== 
159 // function : ~SMESHGUI_aParameterDlg()
160 // purpose  : Destructor
161 //====================================================================================== 
162 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg() 
163 {
164 }
165
166 //=======================================================================
167 //function : ClickOnOk
168 //purpose  : 
169 //=======================================================================
170
171 void SMESHGUI_aParameterDlg::ClickOnOk()
172 {
173   if ( !mySMESHGUI->ActiveStudyLocked() ) {
174     list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
175     list<QWidget*>::iterator              widgetIt = mySpinList.begin();
176     for ( ;
177          paramIt != myParamList.end() && widgetIt != mySpinList.end();
178          paramIt++ , widgetIt++ )
179       (*paramIt)->TakeValue( *widgetIt );
180
181     accept();
182   }
183 }
184
185
186 //=======================================================================
187 // function : Parameters()
188 // purpose  : return a list of parameters from a dialog box
189 //=======================================================================
190 bool SMESHGUI_aParameterDlg::Parameters( list<SMESHGUI_aParameterPtr> params, const char *aTitle)
191 {
192   if ( !params.empty() ) {
193     SMESHGUI_aParameterDlg *Dialog =
194       new SMESHGUI_aParameterDlg(params,
195                                  QAD_Application::getDesktop(),
196                                  aTitle,
197                                  TRUE);
198     return (Dialog->exec() == QDialog::Accepted);
199   }
200   return false;
201 }