2 // File : SALOMEGUI_SetValueDlg.cxx
3 // Created : Wed Jun 27 16:39:06 2001
4 // Author : Vadim SANDLER
7 // Copyright : Open CASCADE
10 #include "SALOMEGUI_SetValueDlg.h"
11 #include "QAD_Tools.h"
13 #include <qgroupbox.h>
15 #include <qlineedit.h>
16 #include <qpushbutton.h>
18 #include <qvalidator.h>
20 #define MARGIN_SIZE 11
21 #define SPACING_SIZE 6
25 SALOMEGUI_SetValueDlg::SALOMEGUI_SetValueDlg( QWidget* parent )
26 : QDialog( parent, "SALOMEGUI_SetValueDlg", true,
27 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
29 setCaption( tr("TLT_SETVALUE") );
30 setSizeGripEnabled( TRUE );
32 QVBoxLayout* topLayout = new QVBoxLayout( this );
33 topLayout->setMargin( MARGIN_SIZE ); topLayout->setSpacing( SPACING_SIZE );
35 /***************************************************************/
36 QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
37 TopGroup->setColumnLayout(0, Qt::Vertical );
38 TopGroup->layout()->setMargin( 0 ); TopGroup->layout()->setSpacing( 0 );
39 QHBoxLayout* TopGroupLayout = new QHBoxLayout( TopGroup->layout() );
40 TopGroupLayout->setAlignment( Qt::AlignTop );
41 TopGroupLayout->setMargin( MARGIN_SIZE ); TopGroupLayout->setSpacing( SPACING_SIZE );
43 myLabel = new QLabel( tr( "VALUE_LBL" ), TopGroup, "myLabel" );
44 myLineEdit = new QLineEdit( TopGroup, "myLineEdit" );
45 myLineEdit->setMinimumSize( 250, 0 );
47 TopGroupLayout->addWidget( myLabel );
48 TopGroupLayout->addWidget( myLineEdit );
50 /***************************************************************/
51 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
52 GroupButtons->setColumnLayout(0, Qt::Vertical );
53 GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 );
54 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
55 GroupButtonsLayout->setAlignment( Qt::AlignTop );
56 GroupButtonsLayout->setMargin( MARGIN_SIZE ); GroupButtonsLayout->setSpacing( SPACING_SIZE );
58 myButtonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons, "myButtonOk" );
59 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
60 myButtonCancel = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "myButtonCancel" );
61 myButtonCancel->setAutoDefault( TRUE );
63 GroupButtonsLayout->addWidget( myButtonOk );
64 GroupButtonsLayout->addStretch();
65 GroupButtonsLayout->addWidget( myButtonCancel );
66 /***************************************************************/
68 topLayout->addWidget( TopGroup );
69 topLayout->addWidget( GroupButtons );
71 // signals and slots connections
72 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
73 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
75 /* Move widget on the botton right corner of main widget */
76 QAD_Tools::centerWidget( this, parent );
82 SALOMEGUI_SetValueDlg::~SALOMEGUI_SetValueDlg()
89 void SALOMEGUI_SetValueDlg::setValue( const QString& value )
91 myLineEdit->setText( value );
92 myLineEdit->selectAll();
96 Returns value entered by user
98 QString SALOMEGUI_SetValueDlg::value()
100 return myLineEdit->text();
106 void SALOMEGUI_SetValueDlg::setValidator( QValidator* v )
108 myLineEdit->setValidator( v );
114 void SALOMEGUI_SetValueDlg::setLabel( const QString& label )
116 myLabel->setText( label );
122 QString SALOMEGUI_SetValueDlg::getString ( const QString& caption,
123 const QString& label,
124 const QString& oldValue,
128 QString v = QString::null;
129 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
130 dlg->setCaption( caption );
131 dlg->setLabel( label );
132 if ( !oldValue.isNull() )
133 dlg->setValue( oldValue );
134 int result = dlg->exec();
135 if ( result == QDialog::Accepted )
138 *ok = result == QDialog::Accepted;
146 int SALOMEGUI_SetValueDlg::getInteger( const QString& caption,
147 const QString& label,
153 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
154 dlg->setCaption( caption );
155 dlg->setLabel( label );
156 dlg->setValidator( new QIntValidator( dlg ) );
157 dlg->setValue( QString::number( oldValue ) );
158 int result = dlg->exec();
159 if ( result == QDialog::Accepted )
160 v = dlg->value().toInt();
162 *ok = result == QDialog::Accepted;
170 double SALOMEGUI_SetValueDlg::getDouble ( const QString& caption,
171 const QString& label,
172 const double oldValue,
177 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
178 dlg->setCaption( caption );
179 dlg->setLabel( label );
180 dlg->setValidator( new QDoubleValidator( dlg ) );
181 dlg->setValue( QString::number( oldValue ) );
182 int result = dlg->exec();
183 if ( result == QDialog::Accepted )
184 v = dlg->value().toDouble();
186 *ok = result == QDialog::Accepted;