2 // File : SMESHGUI_MaxElementAreaDlg.cxx
3 // Created : Mon May 27 11:38:27 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_MaxElementAreaDlg.h"
13 #include "SMESHGUI_SpinBox.h"
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "utilities.h"
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
29 #include <qwhatsthis.h>
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 )
43 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_MAX_ELEMENT_AREA")));
46 setName( "SMESHGUI_MaxElementAreaDlg" );
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 );
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 );
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 );
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 );
123 SpinBox_MaxElementArea = new SMESHGUI_SpinBox( GroupC1, "SpinBox_MaxElementArea" ) ;
124 GroupC1Layout->addWidget( SpinBox_MaxElementArea, 1, 1 );
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 );
132 /***************************************************************/
138 //=================================================================================
139 // function : ~SMESHGUI_MaxElementAreaDlg()
140 // purpose : Destroys the object and frees any allocated resources
141 //=================================================================================
142 SMESHGUI_MaxElementAreaDlg::~SMESHGUI_MaxElementAreaDlg()
144 // no need to delete child widgets, Qt does it all for us
148 //=================================================================================
151 //=================================================================================
152 void SMESHGUI_MaxElementAreaDlg::Init()
156 myConstructorId = 0 ;
157 Constructor1->setChecked( TRUE );
158 myEditCurrentArgument = LineEdit_NameHypothesis ;
160 /* Get setting of step value from file configuration */
162 // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ; TODO
163 // step = St.toDouble() ; TODO
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 */
171 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
172 LineEdit_NameHypothesis->setText("") ;
173 myNameHypothesis = "" ;
174 myMaxElementArea = 1.0 ;
176 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
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) ) );
184 connect( LineEdit_NameHypothesis, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
186 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
187 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
189 /* Move widget on the botton right corner of main widget */
191 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
193 this->show() ; /* displays Dialog */
200 //=================================================================================
201 // function : ConstructorsClicked()
202 // purpose : Radio button management
203 //=================================================================================
204 void SMESHGUI_MaxElementAreaDlg::ConstructorsClicked(int constructorId)
209 //=================================================================================
210 // function : ClickOnOk()
212 //=================================================================================
213 void SMESHGUI_MaxElementAreaDlg::ClickOnOk()
215 this->ClickOnApply() ;
216 this->ClickOnCancel() ;
221 //=================================================================================
222 // function : ClickOnApply()
224 //=================================================================================
225 void SMESHGUI_MaxElementAreaDlg::ClickOnApply()
227 switch(myConstructorId)
231 myMaxElementArea = SpinBox_MaxElementArea->GetValue() ;
232 mySMESHGUI->CreateMaxElementArea( "MaxElementArea", myNameHypothesis, myMaxElementArea );
240 //=================================================================================
241 // function : ClickOnCancel()
243 //=================================================================================
244 void SMESHGUI_MaxElementAreaDlg::ClickOnCancel()
246 mySMESHGUI->ResetState() ;
250 //=================================================================================
251 // function : TextChangedInLineEdit()
253 //=================================================================================
254 void SMESHGUI_MaxElementAreaDlg::TextChangedInLineEdit(const QString& newText)
256 QLineEdit* send = (QLineEdit*)sender();
257 QString newT = strdup(newText) ;
259 if (send == LineEdit_NameHypothesis) {
260 myNameHypothesis = newText ;
266 //=================================================================================
267 // function : DeactivateActiveDialog()
269 //=================================================================================
270 void SMESHGUI_MaxElementAreaDlg::DeactivateActiveDialog()
272 if ( GroupConstructors->isEnabled() ) {
273 GroupConstructors->setEnabled(false) ;
274 GroupC1->setEnabled(false) ;
275 GroupButtons->setEnabled(false) ;
280 //=================================================================================
281 // function : ActivateThisDialog()
283 //=================================================================================
284 void SMESHGUI_MaxElementAreaDlg::ActivateThisDialog()
286 mySMESHGUI->EmitSignalDeactivateDialog() ;
287 GroupConstructors->setEnabled(true) ;
288 GroupC1->setEnabled(true) ;
289 GroupButtons->setEnabled(true) ;
294 //=================================================================================
295 // function : enterEvent()
297 //=================================================================================
298 void SMESHGUI_MaxElementAreaDlg::enterEvent(QEvent* e)
300 if ( GroupConstructors->isEnabled() )
302 ActivateThisDialog() ;
307 //=================================================================================
308 // function : closeEvent()
310 //=================================================================================
311 void SMESHGUI_MaxElementAreaDlg::closeEvent( QCloseEvent* e )
313 this->ClickOnCancel() ;