Salome HOME
Update version to 3.2.0a1
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_NameDlg.cxx
1 //  SALOME GEOMToolsGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : GEOMToolsGUI_NameDlg.cxx
8 //  Author : Vadim SANDLER
9 //  Module : SALOME
10 //  $Header$
11
12
13 #include "GEOMToolsGUI_NameDlg.h"
14 #include <SUIT_Session.h>
15 #include <SUIT_Application.h>
16 #include <SUIT_Desktop.h>
17 #include <SUIT_Tools.h>
18
19 #include <qgroupbox.h>
20 #include <qlabel.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qlayout.h>
24
25 //using namespace std;
26 /*!
27   Constructor
28 */
29 GEOMToolsGUI_NameDlg::GEOMToolsGUI_NameDlg( QWidget* parent )
30     : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(), 
31                "GEOMToolsGUI_NameDlg", 
32                true, 
33                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
34 {
35   setCaption( tr("TLT_RENAME") );
36   setSizeGripEnabled( TRUE );
37   
38   QVBoxLayout* topLayout = new QVBoxLayout( this );
39   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
40
41   /***************************************************************/
42   QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
43   GroupC1->setColumnLayout(0, Qt::Vertical );
44   GroupC1->layout()->setMargin( 0 ); GroupC1->layout()->setSpacing( 0 );
45   QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1->layout() );
46   GroupC1Layout->setAlignment( Qt::AlignTop );
47   GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
48   
49   QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" );
50   TextLabel->setText( tr( "NAME_LBL" ) );
51   GroupC1Layout->addWidget( TextLabel );
52   
53   myLineEdit = new QLineEdit( GroupC1, "LineEdit1" );
54   myLineEdit->setMinimumSize( 250, 0 );
55   GroupC1Layout->addWidget( myLineEdit );
56   
57   /***************************************************************/
58   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
59   GroupButtons->setColumnLayout(0, Qt::Vertical );
60   GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 ); 
61   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
62   GroupButtonsLayout->setAlignment( Qt::AlignTop );
63   GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
64   
65   myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
66   myButtonOk->setText( tr( "GEOM_BUT_OK"  ) );
67   myButtonOk->setAutoDefault( TRUE ); 
68   myButtonOk->setDefault( TRUE );
69   GroupButtonsLayout->addWidget( myButtonOk );
70
71   GroupButtonsLayout->addStretch();
72   
73   myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
74   myButtonCancel->setText( tr( "GEOM_BUT_CANCEL"  ) );
75   myButtonCancel->setAutoDefault( TRUE );
76   GroupButtonsLayout->addWidget( myButtonCancel );
77   /***************************************************************/
78   
79   topLayout->addWidget( GroupC1 );
80   topLayout->addWidget( GroupButtons );
81   
82   // signals and slots connections
83   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
84   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
85   
86   /* Move widget on the botton right corner of main widget */
87   SUIT_Tools::centerWidget( this, parent );
88 }
89
90 /*!
91   Destructor
92 */
93 GEOMToolsGUI_NameDlg::~GEOMToolsGUI_NameDlg()
94 {
95 }
96
97 /*!
98   Sets name
99 */
100 void GEOMToolsGUI_NameDlg::setName( const QString& name )
101 {
102   myLineEdit->setText( name );
103   myLineEdit->end(false);
104   myLineEdit->home(true);
105 }
106
107 /*!
108   Returns name entered by user
109 */
110 QString GEOMToolsGUI_NameDlg::name()
111 {
112   return myLineEdit->text();
113 }
114
115 void GEOMToolsGUI_NameDlg::accept()
116 {
117   if ( name().stripWhiteSpace().isEmpty() )
118     return;
119   QDialog::accept();
120 }
121
122 /*!
123   Creates modal <Rename> dialog and returns name entered [ static ]
124 */
125 QString GEOMToolsGUI_NameDlg::getName( QWidget* parent, const QString& oldName )
126 {
127   QString n;
128   GEOMToolsGUI_NameDlg* dlg = new GEOMToolsGUI_NameDlg( parent );
129   if ( !oldName.isNull() )
130     dlg->setName( oldName );
131   if ( dlg->exec() == QDialog::Accepted ) 
132     n = dlg->name();
133   delete dlg;
134   return n;
135 }