1 // SALOME SalomeApp : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SalomeApp_NameDlg.cxx
8 // Author : Vadim SANDLER
12 #include "SalomeApp_NameDlg.h"
13 #include "SUIT_Application.h"
14 #include "SUIT_Desktop.h"
15 #include "SUIT_Tools.h"
17 #include <qgroupbox.h>
19 #include <qlineedit.h>
20 #include <qpushbutton.h>
30 SalomeApp_NameDlg::SalomeApp_NameDlg( QWidget* parent )
31 : QDialog( parent ? parent : NULL,//application()->desktop(),
34 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
36 setCaption( tr("TLT_RENAME") );
37 setSizeGripEnabled( TRUE );
39 QVBoxLayout* topLayout = new QVBoxLayout( this );
40 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
42 /***************************************************************/
43 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
44 GroupC1->setColumnLayout(0, Qt::Vertical );
45 GroupC1->layout()->setMargin( 0 ); GroupC1->layout()->setSpacing( 0 );
46 QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1->layout() );
47 GroupC1Layout->setAlignment( Qt::AlignTop );
48 GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
50 QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" );
51 TextLabel->setText( tr( "NAME_LBL" ) );
52 GroupC1Layout->addWidget( TextLabel );
54 myLineEdit = new QLineEdit( GroupC1, "LineEdit1" );
55 myLineEdit->setMinimumSize( 250, 0 );
56 GroupC1Layout->addWidget( myLineEdit );
58 /***************************************************************/
59 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
60 GroupButtons->setColumnLayout(0, Qt::Vertical );
61 GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 );
62 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
63 GroupButtonsLayout->setAlignment( Qt::AlignTop );
64 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
66 myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
67 myButtonOk->setText( tr( "BUT_OK" ) );
68 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
69 GroupButtonsLayout->addWidget( myButtonOk );
71 GroupButtonsLayout->addStretch();
73 myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
74 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
75 myButtonCancel->setAutoDefault( TRUE );
76 GroupButtonsLayout->addWidget( myButtonCancel );
77 /***************************************************************/
79 topLayout->addWidget( GroupC1 );
80 topLayout->addWidget( GroupButtons );
82 // signals and slots connections
83 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
84 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
86 /* Move widget on the botton right corner of main widget */
87 SUIT_Tools::centerWidget( this, parent );
93 SalomeApp_NameDlg::~SalomeApp_NameDlg()
100 void SalomeApp_NameDlg::setName( const QString& name )
102 myLineEdit->setText( name );
103 myLineEdit->end(false);
104 myLineEdit->home(true);
108 Returns name entered by user
110 QString SalomeApp_NameDlg::name()
112 return myLineEdit->text();
115 void SalomeApp_NameDlg::accept()
117 if ( name().stripWhiteSpace().isEmpty() )
123 Creates modal <Rename> dialog and returns name entered [ static ]
125 QString SalomeApp_NameDlg::getName( QWidget* parent, const QString& oldName )
128 SalomeApp_NameDlg* dlg = new SalomeApp_NameDlg( parent );
129 if ( !oldName.isNull() )
130 dlg->setName( oldName );
131 if ( dlg->exec() == QDialog::Accepted )