1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOMEGUI_SetValueDlg.cxx
8 // Author : Vadim SANDLER
13 #include "SALOMEGUI_SetValueDlg.h"
14 #include "QAD_Tools.h"
16 #include <qgroupbox.h>
18 #include <qlineedit.h>
19 #include <qpushbutton.h>
21 #include <qvalidator.h>
23 #define MARGIN_SIZE 11
24 #define SPACING_SIZE 6
28 SALOMEGUI_SetValueDlg::SALOMEGUI_SetValueDlg( QWidget* parent )
29 : QDialog( parent, "SALOMEGUI_SetValueDlg", true,
30 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
32 setCaption( tr("TLT_SETVALUE") );
33 setSizeGripEnabled( TRUE );
35 QVBoxLayout* topLayout = new QVBoxLayout( this );
36 topLayout->setMargin( MARGIN_SIZE ); topLayout->setSpacing( SPACING_SIZE );
38 /***************************************************************/
39 QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
40 TopGroup->setColumnLayout(0, Qt::Vertical );
41 TopGroup->layout()->setMargin( 0 ); TopGroup->layout()->setSpacing( 0 );
42 QHBoxLayout* TopGroupLayout = new QHBoxLayout( TopGroup->layout() );
43 TopGroupLayout->setAlignment( Qt::AlignTop );
44 TopGroupLayout->setMargin( MARGIN_SIZE ); TopGroupLayout->setSpacing( SPACING_SIZE );
46 myLabel = new QLabel( tr( "VALUE_LBL" ), TopGroup, "myLabel" );
47 myLineEdit = new QLineEdit( TopGroup, "myLineEdit" );
48 myLineEdit->setMinimumSize( 250, 0 );
50 TopGroupLayout->addWidget( myLabel );
51 TopGroupLayout->addWidget( myLineEdit );
53 /***************************************************************/
54 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
55 GroupButtons->setColumnLayout(0, Qt::Vertical );
56 GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 );
57 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
58 GroupButtonsLayout->setAlignment( Qt::AlignTop );
59 GroupButtonsLayout->setMargin( MARGIN_SIZE ); GroupButtonsLayout->setSpacing( SPACING_SIZE );
61 myButtonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons, "myButtonOk" );
62 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
63 myButtonCancel = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "myButtonCancel" );
64 myButtonCancel->setAutoDefault( TRUE );
66 GroupButtonsLayout->addWidget( myButtonOk );
67 GroupButtonsLayout->addStretch();
68 GroupButtonsLayout->addWidget( myButtonCancel );
69 /***************************************************************/
71 topLayout->addWidget( TopGroup );
72 topLayout->addWidget( GroupButtons );
74 // signals and slots connections
75 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
76 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
78 /* Move widget on the botton right corner of main widget */
79 QAD_Tools::centerWidget( this, parent );
85 SALOMEGUI_SetValueDlg::~SALOMEGUI_SetValueDlg()
92 void SALOMEGUI_SetValueDlg::setValue( const QString& value )
94 myLineEdit->setText( value );
95 myLineEdit->selectAll();
99 Returns value entered by user
101 QString SALOMEGUI_SetValueDlg::value()
103 return myLineEdit->text();
109 void SALOMEGUI_SetValueDlg::setValidator( QValidator* v )
111 myLineEdit->setValidator( v );
117 void SALOMEGUI_SetValueDlg::setLabel( const QString& label )
119 myLabel->setText( label );
122 void SALOMEGUI_SetValueDlg::accept()
124 const QValidator* v = myLineEdit->validator();
126 if ( v->inherits( "QIntValidator" ) ) {
128 int val = myLineEdit->text().toInt( &b );
129 const QIntValidator* iv = dynamic_cast<const QIntValidator*>(v);
130 if ( !b || val < iv->bottom() || val > iv->top())
140 QString SALOMEGUI_SetValueDlg::getString ( const QString& caption,
141 const QString& label,
142 const QString& oldValue,
146 QString v = QString::null;
147 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
148 dlg->setCaption( caption );
149 dlg->setLabel( label );
150 if ( !oldValue.isNull() )
151 dlg->setValue( oldValue );
152 int result = dlg->exec();
153 if ( result == QDialog::Accepted )
156 *ok = result == QDialog::Accepted;
164 int SALOMEGUI_SetValueDlg::getInteger( const QString& caption,
165 const QString& label,
171 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
172 dlg->setCaption( caption );
173 dlg->setLabel( label );
174 dlg->setValidator( new QIntValidator( dlg ) );
175 dlg->setValue( QString::number( oldValue ) );
176 int result = dlg->exec();
177 if ( result == QDialog::Accepted )
178 v = dlg->value().toInt();
180 *ok = result == QDialog::Accepted;
188 int SALOMEGUI_SetValueDlg::getInteger( const QString& caption,
189 const QString& label,
197 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
198 dlg->setCaption( caption );
199 dlg->setLabel( label );
200 dlg->setValidator( new QIntValidator( bottom, top, dlg ) );
201 dlg->setValue( QString::number( oldValue ) );
202 int result = dlg->exec();
203 if ( result == QDialog::Accepted )
204 v = dlg->value().toInt();
206 *ok = result == QDialog::Accepted;
214 double SALOMEGUI_SetValueDlg::getDouble ( const QString& caption,
215 const QString& label,
216 const double oldValue,
221 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
222 dlg->setCaption( caption );
223 dlg->setLabel( label );
224 dlg->setValidator( new QDoubleValidator( dlg ) );
225 dlg->setValue( QString::number( oldValue ) );
226 int result = dlg->exec();
227 if ( result == QDialog::Accepted )
228 v = dlg->value().toDouble();
230 *ok = result == QDialog::Accepted;