Salome HOME
yfr : Merge with v1.2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_aParameterDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_aParameterDlg.cxx
3 //  Created   : Wed Jun 12 21:06:21 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11 #include "SMESHGUI_aParameterDlg.h"
12 #include "SMESHGUI.h"
13 #include "QAD_SpinBoxDbl.h"
14 #include "QAD_Tools.h"
15
16 // QT Includes
17 #include <qgroupbox.h>
18 #include <qlabel.h>
19 #include <qpushbutton.h>
20 #include <qlayout.h>
21 #include <qspinbox.h>
22 #include <qvalidator.h>
23
24 //====================================================================================== 
25 // function : SMESHGUI_aParameterDlg()
26 // purpose  : Constructs a SMESHGUI_aParametertDlg for double values
27 //
28 //  parent    : parent widget
29 //  title     : is the title for the user in dialog box
30 //  label     : text label for the value
31 //
32 //  bottom     : the minimal value to be entered
33 //  top        : the maximum value to be entered
34 //  decimals   : number of decimals to be entered
35 //
36 //  The dialog will by default be modal, unless you set 'modal' to
37 //  false when constructing dialog
38 // 
39 //====================================================================================== 
40 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg( QWidget*     parent,
41                                                 QString      title,
42                                                 QString      label,
43                                                 const double bottom,
44                                                 const double top,
45                                                 const int    decimals,
46                                                 bool         modal ) 
47 : QDialog( parent, "MyParameterDialog", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
48   myIntSpin( 0 ), myDblSpin( 0 )
49 {
50   /* creating widgets */
51   init( true );
52   /* title */
53   setCaption( title );
54   /* caption */
55   myTextLabel->setText( label );
56   /* range */
57   myDblSpin->setRange( bottom, top );
58   ((QDoubleValidator*)(myDblSpin->validator()))->setRange( bottom, top, decimals );
59
60   /* Move widget on the botton right corner of main widget */
61   QAD_Tools::centerWidget( this, parent );
62 }
63
64 //====================================================================================== 
65 // function : SMESHGUI_aParameterDlg()
66 // purpose  : Constructs a SMESHGUI_aParametertDlg for int values
67 //
68 //  parent    : parent widget
69 //  title     : is the title for the user in dialog box
70 //  label     : text label for the value
71 //
72 //  bottom     : the minimal value to be entered
73 //  top        : the maximum value to be entered
74 //
75 //  The dialog will by default be modal, unless you set 'modal' to
76 //  false when constructing dialog
77 // 
78 //====================================================================================== 
79 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg( QWidget*     parent,
80                                                 QString      title,
81                                                 QString      label,
82                                                 const int    bottom,
83                                                 const int    top,
84                                                 bool         modal ) 
85 : QDialog( parent, "MyParameterDialog", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
86   myIntSpin( 0 ), myDblSpin( 0 )
87 {
88   /* creating widgets */
89   init( false );
90   /* title */
91   setCaption( title );
92   /* caption */
93   myTextLabel->setText( label );
94   /* range */
95   myIntSpin->setRange( bottom, top );
96   ((QIntValidator*)(myIntSpin->validator()))->setRange( bottom, top );
97
98   /* Move widget on the botton right corner of main widget */
99   QAD_Tools::centerWidget( this, parent );
100 }
101
102 //====================================================================================== 
103 // function : SMESHGUI_aParameterDlg::init()
104 // purpose  : creates dialog's layout
105 //====================================================================================== 
106 void SMESHGUI_aParameterDlg::init( bool isDouble )
107 {
108   setSizeGripEnabled( TRUE );
109   
110   QGridLayout* topLayout = new QGridLayout( this );
111   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
112
113   /***************************************************************/
114   QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
115   GroupC1->setColumnLayout(0, Qt::Vertical );
116   GroupC1->layout()->setSpacing( 0 );
117   GroupC1->layout()->setMargin( 0 );
118   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
119   GroupC1Layout->setAlignment( Qt::AlignTop );
120   GroupC1Layout->setSpacing( 6 );
121   GroupC1Layout->setMargin( 11 );
122   /* Label */
123   /* aTitle1 : text prompt on left of edit line */
124   myTextLabel = new QLabel( GroupC1, "TextLabel" );
125   GroupC1Layout->addWidget( myTextLabel, 0, 0 );
126   /* Spin box */
127   if ( isDouble ) {
128     myIntSpin = 0;
129     myDblSpin = new QAD_SpinBoxDbl( GroupC1 );
130     myDblSpin->setPrecision( 12 );
131     myDblSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
132     myDblSpin->setMinimumSize( 150, 0 );
133     GroupC1Layout->addWidget( myDblSpin, 0, 1 );
134   }
135   else {
136     myDblSpin = 0;
137     myIntSpin = new QSpinBox( GroupC1 );
138     myIntSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
139     myIntSpin->setMinimumSize( 150, 0 );
140     GroupC1Layout->addWidget( myIntSpin, 0, 1 );
141   }
142   
143   /***************************************************************/
144   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
145   GroupButtons->setColumnLayout(0, Qt::Vertical );
146   GroupButtons->layout()->setSpacing( 0 );
147   GroupButtons->layout()->setMargin( 0 );
148   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
149   GroupButtonsLayout->setAlignment( Qt::AlignTop );
150   GroupButtonsLayout->setSpacing( 6 );
151   GroupButtonsLayout->setMargin( 11 );
152   /* Ok button */
153   myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
154   myButtonOk->setText( tr("SMESH_BUT_OK") );
155   myButtonOk->setAutoDefault( TRUE );
156   myButtonOk->setDefault( TRUE );
157   GroupButtonsLayout->addWidget( myButtonOk, 0, 0 );
158   /* add spacer between buttons */
159   GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
160   /* Cancel button */
161   myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
162   myButtonCancel->setText( tr("SMESH_BUT_CANCEL") );
163   myButtonCancel->setAutoDefault( TRUE );
164   GroupButtonsLayout->addWidget( myButtonCancel, 0, 2 );
165   
166   /***************************************************************/
167   topLayout->addWidget( GroupC1,      0, 0);
168   topLayout->addWidget( GroupButtons, 1, 0);
169
170   /* signals and slots connections */
171   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
172   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
173
174   /* Retrieve SMESHGUI */
175   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
176 }
177
178
179 //====================================================================================== 
180 // function : ~SMESHGUI_aParameterDlg()
181 // purpose  : Destructor
182 //====================================================================================== 
183 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg() 
184 {
185 }
186
187 //====================================================================================== 
188 // function : SMESHGUI_aParameterDlg::setValue
189 // purpose  : sets double value
190 //====================================================================================== 
191 void SMESHGUI_aParameterDlg::setValue( const double val )
192 {
193   if ( myDblSpin )
194     myDblSpin->setValue( val );
195 }
196 //====================================================================================== 
197 // function : SMESHGUI_aParameterDlg::setValue
198 // purpose  : sets int value
199 //====================================================================================== 
200 void SMESHGUI_aParameterDlg::setValue( const int val )
201 {
202   if ( myIntSpin )
203     myIntSpin->setValue( val );
204 }
205 //====================================================================================== 
206 // function : SMESHGUI_aParameterDlg::getDblValue
207 // purpose  : returns double value entered by user
208 //====================================================================================== 
209 double SMESHGUI_aParameterDlg::getDblValue()
210 {
211   if ( myDblSpin )
212     return myDblSpin->value();
213   return 0.0;
214 }
215
216 //====================================================================================== 
217 // function : SMESHGUI_aParameterDlg::getIntValu
218 // purpose  : returns int value entered by user
219 //====================================================================================== 
220 int SMESHGUI_aParameterDlg::getIntValue()
221 {
222   if ( myIntSpin )
223     return myIntSpin->value();
224   return 0;
225 }
226
227
228
229
230
231
232
233
234