Salome HOME
NRI : loadPixmap( "SMESH", ...) instead of "SMESHGUI".
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MaxElementAreaDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_MaxElementAreaDlg.cxx
3 //  Created   : Mon May 27 11:38:27 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11 #include "SMESHGUI_MaxElementAreaDlg.h"
12 #include "SMESHGUI.h"
13 #include "SMESHGUI_SpinBox.h"
14
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "utilities.h"
18
19 // QT Includes
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
22 #include <qlabel.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
26 #include <qlayout.h>
27 #include <qvariant.h>
28 #include <qtooltip.h>
29 #include <qwhatsthis.h>
30 #include <qimage.h>
31 #include <qpixmap.h>
32
33 //=================================================================================
34 // class    : SMESHGUI_MaxElementAreaDlg()
35 // purpose  : Constructs a SMESHGUI_MaxElementAreaDlg which is a child of 'parent', with the 
36 //            name 'name' and widget flags set to 'f'.
37 //            The dialog will by default be modeless, unless you set 'modal' to
38 //            TRUE to construct a modal dialog.
39 //=================================================================================
40 SMESHGUI_MaxElementAreaDlg::SMESHGUI_MaxElementAreaDlg( QWidget* parent, const char* name, bool modal, WFlags fl )
41     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
42 {
43     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_MAX_ELEMENT_AREA")));
44     
45     if ( !name )
46       setName( "SMESHGUI_MaxElementAreaDlg" );
47     resize( 303, 175 ); 
48     setCaption( tr( "SMESH_MAX_ELEMENT_AREA_TITLE"  ) );
49     setSizeGripEnabled( TRUE );
50     SMESHGUI_MaxElementAreaDlgLayout = new QGridLayout( this ); 
51     SMESHGUI_MaxElementAreaDlgLayout->setSpacing( 6 );
52     SMESHGUI_MaxElementAreaDlgLayout->setMargin( 11 );
53
54     /***************************************************************/
55     GroupButtons = new QGroupBox( this, "GroupButtons" );
56     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
57     GroupButtons->setTitle( tr( ""  ) );
58     GroupButtons->setColumnLayout(0, Qt::Vertical );
59     GroupButtons->layout()->setSpacing( 0 );
60     GroupButtons->layout()->setMargin( 0 );
61     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
62     GroupButtonsLayout->setAlignment( Qt::AlignTop );
63     GroupButtonsLayout->setSpacing( 6 );
64     GroupButtonsLayout->setMargin( 11 );
65     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
66     buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
67     buttonCancel->setAutoDefault( TRUE );
68     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
69     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
70     buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
71     buttonApply->setAutoDefault( TRUE );
72     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
73     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
74     GroupButtonsLayout->addItem( spacer, 0, 2 );
75     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
76     buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
77     buttonOk->setAutoDefault( TRUE );
78     buttonOk->setDefault( TRUE );
79     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
80     SMESHGUI_MaxElementAreaDlgLayout->addWidget( GroupButtons, 2, 0 );
81
82     /***************************************************************/
83     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
84     GroupConstructors->setTitle( tr( "SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"  ) );
85     GroupConstructors->setExclusive( TRUE );
86     GroupConstructors->setColumnLayout(0, Qt::Vertical );
87     GroupConstructors->layout()->setSpacing( 0 );
88     GroupConstructors->layout()->setMargin( 0 );
89     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
90     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
91     GroupConstructorsLayout->setSpacing( 6 );
92     GroupConstructorsLayout->setMargin( 11 );
93     QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
94     GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
95     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
96     Constructor1->setText( tr( ""  ) );
97     Constructor1->setPixmap( image0 );
98     Constructor1->setChecked( TRUE );
99     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
100     Constructor1->setMinimumSize( QSize( 50, 0 ) );
101     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
102     QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
103     GroupConstructorsLayout->addItem( spacer_3, 0, 1 );
104     SMESHGUI_MaxElementAreaDlgLayout->addWidget( GroupConstructors, 0, 0 );
105     
106     /***************************************************************/
107     GroupC1 = new QGroupBox( this, "GroupC1" );
108     GroupC1->setTitle( tr( "SMESH_ARGUMENTS"  ) );
109     GroupC1->setColumnLayout(0, Qt::Vertical );
110     GroupC1->layout()->setSpacing( 0 );
111     GroupC1->layout()->setMargin( 0 );
112     GroupC1Layout = new QGridLayout( GroupC1->layout() );
113     GroupC1Layout->setAlignment( Qt::AlignTop );
114     GroupC1Layout->setSpacing( 6 );
115     GroupC1Layout->setMargin( 11 );
116     TextLabel_MaxElementArea = new QLabel(GroupC1 , "TextLabel_MaxElementArea" );
117     TextLabel_MaxElementArea->setText( tr( "SMESH_MAX_ELEMENT_AREA"  ) );
118     GroupC1Layout->addWidget( TextLabel_MaxElementArea, 1, 0 );
119     TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
120     TextLabel_NameHypothesis->setText( tr( "SMESH_NAME"  ) );
121     GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
122  
123     SpinBox_MaxElementArea = new SMESHGUI_SpinBox( GroupC1, "SpinBox_MaxElementArea" ) ;
124     GroupC1Layout->addWidget( SpinBox_MaxElementArea, 1, 1 );
125  
126     LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
127     GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
128     QSpacerItem* spacer1 = new QSpacerItem( 20, 24, QSizePolicy::Minimum, QSizePolicy::Fixed );
129     GroupC1Layout->addItem( spacer1, 1, 3 );
130     SMESHGUI_MaxElementAreaDlgLayout->addWidget(GroupC1 , 1, 0 );
131
132     /***************************************************************/
133
134     Init() ;
135 }
136
137
138 //=================================================================================
139 // function : ~SMESHGUI_MaxElementAreaDlg()
140 // purpose  : Destroys the object and frees any allocated resources
141 //=================================================================================
142 SMESHGUI_MaxElementAreaDlg::~SMESHGUI_MaxElementAreaDlg()
143 {
144     // no need to delete child widgets, Qt does it all for us
145 }
146
147
148 //=================================================================================
149 // function : Init()
150 // purpose  :
151 //=================================================================================
152 void SMESHGUI_MaxElementAreaDlg::Init()
153 {
154    
155   GroupC1->show();
156   myConstructorId = 0 ;
157   Constructor1->setChecked( TRUE );
158   myEditCurrentArgument = LineEdit_NameHypothesis ;
159
160   /* Get setting of step value from file configuration */
161   double step ;
162   // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ;  TODO
163   // step = St.toDouble() ;                                    TODO
164   step = 1.0 ;
165
166   /* min, max, step and decimals for spin boxes */
167   SpinBox_MaxElementArea->setPrecision( 10 );
168   SpinBox_MaxElementArea->RangeStepAndValidator( 0.001, 999999.999, step, 3 ) ;
169   SpinBox_MaxElementArea->SetValue( 1.0 ) ;  /* is myMaxElementArea */
170   
171   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
172   LineEdit_NameHypothesis->setText("") ;
173   myNameHypothesis = "" ;
174   myMaxElementArea = 1.0 ;
175
176   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
177
178   /* signals and slots connections */
179   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
180   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
181   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
182   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );  
183
184   connect( LineEdit_NameHypothesis, SIGNAL (textChanged(const QString&)  ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
185
186   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
187   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
188
189   /* Move widget on the botton right corner of main widget */
190   int x, y ;
191   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
192   this->move( x, y ) ; 
193   this->show() ; /* displays Dialog */
194
195   return ;
196 }
197
198
199
200 //=================================================================================
201 // function : ConstructorsClicked()
202 // purpose  : Radio button management
203 //=================================================================================
204 void SMESHGUI_MaxElementAreaDlg::ConstructorsClicked(int constructorId)
205 {
206   return;
207 }
208
209 //=================================================================================
210 // function : ClickOnOk()
211 // purpose  :
212 //=================================================================================
213 void SMESHGUI_MaxElementAreaDlg::ClickOnOk()
214 {
215   this->ClickOnApply() ;
216   this->ClickOnCancel() ;
217
218   return ;
219 }
220
221 //=================================================================================
222 // function : ClickOnApply()
223 // purpose  :
224 //=================================================================================
225 void SMESHGUI_MaxElementAreaDlg::ClickOnApply()
226 {
227   switch(myConstructorId)
228     { 
229     case 0 :
230       { 
231         myMaxElementArea = SpinBox_MaxElementArea->GetValue() ;
232         mySMESHGUI->CreateMaxElementArea( "MaxElementArea", myNameHypothesis, myMaxElementArea );
233         break ;
234       }
235     }
236   return ;
237 }
238
239
240 //=================================================================================
241 // function : ClickOnCancel()
242 // purpose  :
243 //=================================================================================
244 void SMESHGUI_MaxElementAreaDlg::ClickOnCancel()
245 {
246   mySMESHGUI->ResetState() ;
247   reject() ;
248 }
249
250 //=================================================================================
251 // function : TextChangedInLineEdit()
252 // purpose  :
253 //=================================================================================
254 void SMESHGUI_MaxElementAreaDlg::TextChangedInLineEdit(const QString& newText)
255 {  
256   QLineEdit* send = (QLineEdit*)sender();
257   QString newT = strdup(newText) ;
258   
259   if (send == LineEdit_NameHypothesis) {
260     myNameHypothesis = newText ;
261   }
262   return ;
263 }
264
265
266 //=================================================================================
267 // function : DeactivateActiveDialog()
268 // purpose  :
269 //=================================================================================
270 void SMESHGUI_MaxElementAreaDlg::DeactivateActiveDialog()
271 {
272   if ( GroupConstructors->isEnabled() ) {
273     GroupConstructors->setEnabled(false) ;
274     GroupC1->setEnabled(false) ;
275     GroupButtons->setEnabled(false) ;
276   } 
277 }
278
279
280 //=================================================================================
281 // function : ActivateThisDialog()
282 // purpose  :
283 //=================================================================================
284 void SMESHGUI_MaxElementAreaDlg::ActivateThisDialog()
285 {
286   mySMESHGUI->EmitSignalDeactivateDialog() ;   
287   GroupConstructors->setEnabled(true) ;
288   GroupC1->setEnabled(true) ;
289   GroupButtons->setEnabled(true) ;
290   return ;
291 }
292
293
294 //=================================================================================
295 // function : enterEvent()
296 // purpose  :
297 //=================================================================================
298 void SMESHGUI_MaxElementAreaDlg::enterEvent(QEvent* e)
299 {
300   if ( GroupConstructors->isEnabled() )
301     return ;  
302   ActivateThisDialog() ;
303   return ;
304 }
305
306
307 //=================================================================================
308 // function : closeEvent()
309 // purpose  :
310 //=================================================================================
311 void SMESHGUI_MaxElementAreaDlg::closeEvent( QCloseEvent* e )
312 {
313   this->ClickOnCancel() ;
314   return ;
315 }