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