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 );
125 QString SALOMEGUI_SetValueDlg::getString ( const QString& caption,
126 const QString& label,
127 const QString& oldValue,
131 QString v = QString::null;
132 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
133 dlg->setCaption( caption );
134 dlg->setLabel( label );
135 if ( !oldValue.isNull() )
136 dlg->setValue( oldValue );
137 int result = dlg->exec();
138 if ( result == QDialog::Accepted )
141 *ok = result == QDialog::Accepted;
149 int SALOMEGUI_SetValueDlg::getInteger( const QString& caption,
150 const QString& label,
156 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
157 dlg->setCaption( caption );
158 dlg->setLabel( label );
159 dlg->setValidator( new QIntValidator( dlg ) );
160 dlg->setValue( QString::number( oldValue ) );
161 int result = dlg->exec();
162 if ( result == QDialog::Accepted )
163 v = dlg->value().toInt();
165 *ok = result == QDialog::Accepted;
173 double SALOMEGUI_SetValueDlg::getDouble ( const QString& caption,
174 const QString& label,
175 const double oldValue,
180 SALOMEGUI_SetValueDlg* dlg = new SALOMEGUI_SetValueDlg( parent );
181 dlg->setCaption( caption );
182 dlg->setLabel( label );
183 dlg->setValidator( new QDoubleValidator( dlg ) );
184 dlg->setValue( QString::number( oldValue ) );
185 int result = dlg->exec();
186 if ( result == QDialog::Accepted )
187 v = dlg->value().toDouble();
189 *ok = result == QDialog::Accepted;