Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / LightApp / LightApp_NameDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : LightApp_NameDlg.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24 //
25 #include "LightApp_NameDlg.h"
26 #include <SUIT_Tools.h>
27
28 #include <QGroupBox>
29 #include <QLabel>
30 #include <QLineEdit>
31 #include <QPushButton>
32 #include <QHBoxLayout>
33 #include <QVBoxLayout>
34
35 #ifndef WIN32
36 using namespace std;
37 #endif
38
39 /*!
40   Constructor
41 */
42 LightApp_NameDlg::LightApp_NameDlg( QWidget* parent )
43 : QDialog( parent ? parent : NULL,//application()->desktop(), 
44 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
45 {
46   setObjectName( "LightApp_NameDlg" );
47   setModal( true );
48
49   setWindowTitle( tr("TLT_RENAME") );
50   setSizeGripEnabled( TRUE );
51
52   QVBoxLayout* topLayout = new QVBoxLayout( this );
53   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
54
55   /***************************************************************/
56   QGroupBox* GroupC1 = new QGroupBox( this );
57   GroupC1->setObjectName( "GroupC1" );
58   QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
59   GroupC1Layout->setAlignment( Qt::AlignTop );
60   GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
61   
62   QLabel* TextLabel = new QLabel( GroupC1 );
63   TextLabel->setObjectName( "TextLabel1" );
64   TextLabel->setText( tr( "NAME_LBL" ) );
65   GroupC1Layout->addWidget( TextLabel );
66   
67   myLineEdit = new QLineEdit( GroupC1 );
68   myLineEdit->setObjectName( "LineEdit1" );
69   myLineEdit->setMinimumSize( 250, 0 );
70   GroupC1Layout->addWidget( myLineEdit );
71   
72   /***************************************************************/
73   QGroupBox* GroupButtons = new QGroupBox( this );
74   GroupButtons->setObjectName( "GroupButtons" );
75   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
76   GroupButtonsLayout->setAlignment( Qt::AlignTop );
77   GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
78   
79   myButtonOk = new QPushButton( GroupButtons );
80   myButtonOk->setObjectName( "buttonOk" );
81   myButtonOk->setText( tr( "BUT_OK"  ) );
82   myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
83   GroupButtonsLayout->addWidget( myButtonOk );
84
85   GroupButtonsLayout->addStretch();
86   
87   myButtonCancel = new QPushButton( GroupButtons );
88   myButtonCancel->setObjectName( "buttonCancel" );
89   myButtonCancel->setText( tr( "BUT_CANCEL"  ) );
90   myButtonCancel->setAutoDefault( TRUE );
91   GroupButtonsLayout->addWidget( myButtonCancel );
92   /***************************************************************/
93   
94   topLayout->addWidget( GroupC1 );
95   topLayout->addWidget( GroupButtons );
96   
97   // signals and slots connections
98   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
99   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
100   
101   /* Move widget on the botton right corner of main widget */
102   SUIT_Tools::centerWidget( this, parent );
103 }
104
105 /*!
106   Destructor
107 */
108 LightApp_NameDlg::~LightApp_NameDlg()
109 {
110 }
111
112 /*!
113   Sets name
114 */
115 void LightApp_NameDlg::setName( const QString& name )
116 {
117   myLineEdit->setText( name );
118   myLineEdit->end(false);
119   myLineEdit->home(true);
120 }
121
122 /*!
123   Returns name entered by user
124 */
125 QString LightApp_NameDlg::name()
126 {
127   return myLineEdit->text();
128 }
129
130 /*!
131   Accepts if name isn't empty
132 */
133 void LightApp_NameDlg::accept()
134 {
135   if ( name().trimmed().isEmpty() )
136     return;
137   QDialog::accept();
138 }
139
140 /*!
141   Creates modal <Rename> dialog and returns name entered [ static ]
142 */
143 QString LightApp_NameDlg::getName( QWidget* parent, const QString& oldName )
144 {
145   QString n;
146   LightApp_NameDlg* dlg = new LightApp_NameDlg( parent );
147   if ( !oldName.isNull() )
148     dlg->setName( oldName );
149   if ( dlg->exec() == QDialog::Accepted ) 
150     n = dlg->name();
151   delete dlg;
152   return n;
153 }