Salome HOME
NRI : Explode OCC_LIBS.
[modules/geom.git] / src / GEOMGUI / GeometryGUI_aParameterDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_aParameterDlg.cxx
3 //  Created   : 
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : Open CASCADE
8 //  $Header$
9
10 #include "GeometryGUI_aParameterDlg.h"
11 #include "GeometryGUI.h"
12 #include "QAD_SpinBoxDbl.h"
13 #include "QAD_Tools.h"
14
15 #include <stdio.h>
16
17 #include <qgroupbox.h>
18 #include <qlabel.h>
19 #include <qpushbutton.h>
20 #include <qlayout.h>
21 #include <qvariant.h>
22 #include <qvalidator.h>
23
24 //====================================================================================== 
25 // function : GeometryGUI_aParameterDlg()
26 // purpose  : Constructs a GeometryGUI_aParametertDlg which is a child of 'parent', with the 
27 //            name 'name' and widget flags set to 'f'
28 //
29 //  avalue1    : is a float or integer used as default value in edit line
30 //  aTitle1    : is the prompt for aValue1
31 //  aTitle     : is the title for the user in dialog box
32 //
33 //  bottom     : the minimal value to be entered
34 //  top        : the maximum value to be entered
35 //  decimals   : number of decimals to be entered
36 //
37 //  The dialog will by default be modeless, unless you set 'modal' to
38 //  TRUE to construct a modal dialog.
39 // 
40 //====================================================================================== 
41 GeometryGUI_aParameterDlg::GeometryGUI_aParameterDlg( const char *aValue1,
42                                                       const char *aTitle1,
43                                                       QWidget* parent,
44                                                       const char* name,
45                                                       bool modal,
46                                                       WFlags fl,
47                                                       const double bottom,
48                                                       const double top,
49                                                       const int decimals )
50   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
51 {
52   if ( !name )
53     setName( "MyParameterDialog" );
54   resize( 288, 81 ); 
55   setCaption( name ); /* appears on the title bar */
56   setSizeGripEnabled( TRUE );
57   
58   QGridLayout* topLayout = new QGridLayout( this ); 
59   topLayout->setSpacing( 6 );
60   topLayout->setMargin( 11 );
61
62   QGroupBox* mainGrp = new QGroupBox( this, "mainGrp" );
63   mainGrp->setColumnLayout(0, Qt::Vertical );
64   mainGrp->layout()->setSpacing( 0 );
65   mainGrp->layout()->setMargin( 0 );
66   QGridLayout* mainGrpLayout = new QGridLayout( mainGrp->layout() );
67   mainGrpLayout->setAlignment( Qt::AlignTop );
68   mainGrpLayout ->setSpacing( 6 );
69   mainGrpLayout->setMargin( 11 );
70   topLayout->addWidget( mainGrp, 0, 0 );
71
72   /* aTitle1 : text prompt on left of edit line */
73   QLabel* TextLabel1 = new QLabel( mainGrp, "TextLabel1" );
74   TextLabel1->setText( tr( aTitle1  ) );  
75   mainGrpLayout->addWidget( TextLabel1, 0, 0 );
76
77   mySpinBox = new QAD_SpinBoxDbl( mainGrp, "mySpinBox" );
78   mySpinBox->setPrecision( 12);
79   mySpinBox->setRange( bottom, top );
80   (( QDoubleValidator* )(mySpinBox->validator()))->setRange(bottom, top, decimals);
81   mySpinBox->setValue(QString(aValue1).toDouble());
82   mainGrpLayout->addWidget( mySpinBox, 0, 1 );
83   
84   QGroupBox* btnGrp = new QGroupBox( this, "btnGrp" );
85   btnGrp->setColumnLayout(0, Qt::Vertical );
86   btnGrp->layout()->setSpacing( 0 );
87   btnGrp->layout()->setMargin( 0 );
88   QGridLayout* btnGrpLayout = new QGridLayout( btnGrp->layout() );
89   btnGrpLayout->setAlignment( Qt::AlignTop );
90   btnGrpLayout->setSpacing( 6 );
91   btnGrpLayout->setMargin( 11 );
92   topLayout->addWidget( btnGrp, 1, 0 );
93
94   /* Ok button */
95   myButtonOk = new QPushButton( btnGrp, "buttonOk" );
96   myButtonOk->setText( tr("GEOM_BUT_OK") );
97   myButtonOk->setAutoDefault( TRUE );
98   myButtonOk->setDefault( TRUE );
99   btnGrpLayout->addWidget( myButtonOk, 0, 0 );
100
101   btnGrpLayout->addItem( new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
102
103   /* Cancel button */
104   myButtonCancel = new QPushButton( btnGrp, "buttonCancel" );
105   myButtonCancel->setText( tr("GEOM_BUT_CANCEL") );
106   myButtonCancel->setAutoDefault( TRUE );
107   btnGrpLayout->addWidget( myButtonCancel, 0, 2 );
108
109   /* signals and slots connections */
110   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
111   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
112  
113   /* Retrieve GeomGUI */
114   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
115   
116   /* Move widget on the botton right corner of main widget */
117   QAD_Tools::centerWidget(this, parent);
118 }
119
120
121 //====================================================================================== 
122 // function : ~GeometryGUI_aParameterDlg() destructor
123 // purpose  : Destroys the object and frees any allocated resources
124 //====================================================================================== 
125 GeometryGUI_aParameterDlg::~GeometryGUI_aParameterDlg()
126 {    // no need to delete child widgets, Qt does it all for us
127 }
128
129 //====================================================================================== 
130 // function : GeometryGUI_aParameterDlg::setValue
131 // purpose  : sets value
132 //====================================================================================== 
133 void GeometryGUI_aParameterDlg::setValue( double val )
134 {
135   mySpinBox->setValue( val );
136 }
137
138 //====================================================================================== 
139 // function : GeometryGUI_aParameterDlg::getValue
140 // purpose  : gets value
141 //====================================================================================== 
142 double GeometryGUI_aParameterDlg::getValue()
143 {
144   return mySpinBox->value();
145 }
146