1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_aParameterDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "QAD_Tools.h"
30 #include "QAD_Desktop.h"
31 #include "QAD_Application.h"
33 #include "SMESHGUI_aParameterDlg.h"
34 #include "SMESHGUI_aParameter.h"
36 #include "SMESHGUI_SpinBox.h"
39 #include <qgroupbox.h>
41 #include <qpushbutton.h>
44 #include <qvalidator.h>
48 //======================================================================================
49 // function : SMESHGUI_aParameterDlg()
51 // The dialog will by default be modal, unless you set 'modal' to
52 // false when constructing dialog
54 //======================================================================================
55 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg
56 (std::list<SMESHGUI_aParameterPtr> params,
60 : QDialog( parent, "MyParameterDialog", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
63 /* creating widgets */
68 /* Move widget on the botton right corner of main widget */
69 QAD_Tools::centerWidget( this, parent );
72 //======================================================================================
73 // function : SMESHGUI_aParameterDlg::init()
74 // purpose : creates dialog's layout
75 //======================================================================================
76 void SMESHGUI_aParameterDlg::init()
78 setSizeGripEnabled( TRUE );
80 QGridLayout* topLayout = new QGridLayout( this );
81 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
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++ )
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 );
105 spin->setPrecision( 12 );
108 case SMESHGUI_aParameter::INT: {
109 QSpinBox* spin = new QSpinBox( GroupC1 );
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 );
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 );
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 );
140 myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
141 myButtonCancel->setText( tr("SMESH_BUT_CANCEL") );
142 myButtonCancel->setAutoDefault( TRUE );
143 GroupButtonsLayout->addWidget( myButtonCancel, 0, 2 );
145 /***************************************************************/
146 topLayout->addWidget( GroupC1, 0, 0);
147 topLayout->addWidget( GroupButtons, 1, 0);
149 /* signals and slots connections */
150 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
151 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
153 /* Retrieve SMESHGUI */
154 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
158 //======================================================================================
159 // function : ~SMESHGUI_aParameterDlg()
160 // purpose : Destructor
161 //======================================================================================
162 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg()
166 //=======================================================================
167 //function : ClickOnOk
169 //=======================================================================
171 void SMESHGUI_aParameterDlg::ClickOnOk()
173 if ( !mySMESHGUI->ActiveStudyLocked() ) {
174 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
175 list<QWidget*>::iterator widgetIt = mySpinList.begin();
177 paramIt != myParamList.end() && widgetIt != mySpinList.end();
178 paramIt++ , widgetIt++ )
179 (*paramIt)->TakeValue( *widgetIt );
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)
192 if ( !params.empty() ) {
193 SMESHGUI_aParameterDlg *Dialog =
194 new SMESHGUI_aParameterDlg(params,
195 QAD_Application::getDesktop(),
198 return (Dialog->exec() == QDialog::Accepted);