2 // File : SMESHGUI_NbSegmentsDlg.cxx
3 // Created : Mon May 27 11:38:27 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_NbSegmentsDlg.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
19 #include <qbuttongroup.h>
20 #include <qgroupbox.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
28 #include <qwhatsthis.h>
33 //=================================================================================
34 // class : SMESHGUI_NbSegmentsDlg()
35 // purpose : Constructs a SMESHGUI_NbSegmentsDlg 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_NbSegmentsDlg::SMESHGUI_NbSegmentsDlg( 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_NB_SEGMENTS")));
46 setName( "SMESHGUI_NbSegmentsDlg" );
48 setCaption( tr( "SMESH_NB_SEGMENTS_TITLE" ) );
49 setSizeGripEnabled( TRUE );
50 SMESHGUI_NbSegmentsDlgLayout = new QGridLayout( this );
51 SMESHGUI_NbSegmentsDlgLayout->setSpacing( 6 );
52 SMESHGUI_NbSegmentsDlgLayout->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_NbSegmentsDlgLayout->addWidget( GroupButtons, 2, 0 );
82 /***************************************************************/
83 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
84 GroupConstructors->setTitle( tr( "SMESH_NB_SEGMENTS_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_NbSegmentsDlgLayout->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_NbSeg = new QLabel(GroupC1 , "TextLabel_NbSeg" );
117 TextLabel_NbSeg->setText( tr( "SMESH_SEGMENTS" ) );
118 GroupC1Layout->addWidget( TextLabel_NbSeg, 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_NbSeg = new QSpinBox( GroupC1, "SpinBox_NbSeg" );
124 GroupC1Layout->addWidget( SpinBox_NbSeg, 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_NbSegmentsDlgLayout->addWidget(GroupC1 , 1, 0 );
132 /***************************************************************/
138 //=================================================================================
139 // function : ~SMESHGUI_NbSegmentsDlg()
140 // purpose : Destroys the object and frees any allocated resources
141 //=================================================================================
142 SMESHGUI_NbSegmentsDlg::~SMESHGUI_NbSegmentsDlg()
144 // no need to delete child widgets, Qt does it all for us
148 //=================================================================================
151 //=================================================================================
152 void SMESHGUI_NbSegmentsDlg::Init()
156 myConstructorId = 0 ;
157 Constructor1->setChecked( TRUE );
158 myEditCurrentArgument = LineEdit_NameHypothesis ;
160 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
161 LineEdit_NameHypothesis->setText("") ;
163 SpinBox_NbSeg->setMinValue( 1 );
164 SpinBox_NbSeg->setMaxValue( 9999 );
165 SpinBox_NbSeg->setValue(3) ; /* myNbSeg */
168 myNameHypothesis = "" ;
170 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
172 /* signals and slots connections */
173 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
174 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
175 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
176 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
178 connect( LineEdit_NameHypothesis, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
180 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
181 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
183 /* Move widget on the botton right corner of main widget */
185 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
187 this->show() ; /* displays Dialog */
194 //=================================================================================
195 // function : ConstructorsClicked()
196 // purpose : Radio button management
197 //=================================================================================
198 void SMESHGUI_NbSegmentsDlg::ConstructorsClicked(int constructorId)
203 //=================================================================================
204 // function : ClickOnOk()
206 //=================================================================================
207 void SMESHGUI_NbSegmentsDlg::ClickOnOk()
209 this->ClickOnApply() ;
210 this->ClickOnCancel() ;
215 //=================================================================================
216 // function : ClickOnApply()
218 //=================================================================================
219 void SMESHGUI_NbSegmentsDlg::ClickOnApply()
221 switch(myConstructorId)
225 myNbSeg = SpinBox_NbSeg->value() ;
226 mySMESHGUI->CreateNbSegments( "NumberOfSegments", myNameHypothesis, myNbSeg );
234 //=================================================================================
235 // function : ClickOnCancel()
237 //=================================================================================
238 void SMESHGUI_NbSegmentsDlg::ClickOnCancel()
240 mySMESHGUI->ResetState() ;
245 //=================================================================================
246 // function : DeactivateActiveDialog()
248 //=================================================================================
249 void SMESHGUI_NbSegmentsDlg::DeactivateActiveDialog()
251 if ( GroupConstructors->isEnabled() ) {
252 GroupConstructors->setEnabled(false) ;
253 GroupC1->setEnabled(false) ;
254 GroupButtons->setEnabled(false) ;
259 //=================================================================================
260 // function : TextChangedInLineEdit()
262 //=================================================================================
263 void SMESHGUI_NbSegmentsDlg::TextChangedInLineEdit(const QString& newText)
265 QLineEdit* send = (QLineEdit*)sender();
266 QString newT = strdup(newText) ;
268 if (send == LineEdit_NameHypothesis) {
269 myNameHypothesis = newText ;
275 //=================================================================================
276 // function : ActivateThisDialog()
278 //=================================================================================
279 void SMESHGUI_NbSegmentsDlg::ActivateThisDialog()
281 mySMESHGUI->EmitSignalDeactivateDialog() ;
282 GroupConstructors->setEnabled(true) ;
283 GroupC1->setEnabled(true) ;
284 GroupButtons->setEnabled(true) ;
289 //=================================================================================
290 // function : enterEvent()
292 //=================================================================================
293 void SMESHGUI_NbSegmentsDlg::enterEvent(QEvent* e)
295 if ( GroupConstructors->isEnabled() )
297 ActivateThisDialog() ;
302 //=================================================================================
303 // function : closeEvent()
305 //=================================================================================
306 void SMESHGUI_NbSegmentsDlg::closeEvent( QCloseEvent* e )
308 this->ClickOnCancel() ;