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