Salome HOME
Updated copyright comment
[modules/gui.git] / src / LightApp / LightApp_NameDlg.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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, or (at your option) any later version.
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
23 // File   : LightApp_NameDlg.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 //
26 #include "LightApp_NameDlg.h"
27 #include <SUIT_Tools.h>
28
29 #include <QGroupBox>
30 #include <QLabel>
31 #include <QLineEdit>
32 #include <QPushButton>
33 #include <QHBoxLayout>
34 #include <QVBoxLayout>
35
36 /*!
37   Constructor
38 */
39 LightApp_NameDlg::LightApp_NameDlg( QWidget* parent )
40 : QDialog( parent ? parent : NULL,//application()->desktop(), 
41 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
42 {
43   setObjectName( "LightApp_NameDlg" );
44   setModal( true );
45
46   setWindowTitle( tr("TLT_RENAME") );
47   setSizeGripEnabled( true );
48
49   QVBoxLayout* topLayout = new QVBoxLayout( this );
50   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
51
52   /***************************************************************/
53   QGroupBox* GroupC1 = new QGroupBox( this );
54   GroupC1->setObjectName( "GroupC1" );
55   QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
56   GroupC1Layout->setAlignment( Qt::AlignTop );
57   GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
58   
59   QLabel* TextLabel = new QLabel( GroupC1 );
60   TextLabel->setObjectName( "TextLabel1" );
61   TextLabel->setText( tr( "NAME_LBL" ) );
62   GroupC1Layout->addWidget( TextLabel );
63   
64   myLineEdit = new QLineEdit( GroupC1 );
65   myLineEdit->setObjectName( "LineEdit1" );
66   myLineEdit->setMinimumSize( 250, 0 );
67   GroupC1Layout->addWidget( myLineEdit );
68   
69   /***************************************************************/
70   QGroupBox* GroupButtons = new QGroupBox( this );
71   GroupButtons->setObjectName( "GroupButtons" );
72   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
73   GroupButtonsLayout->setAlignment( Qt::AlignTop );
74   GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
75   
76   myButtonOk = new QPushButton( GroupButtons );
77   myButtonOk->setObjectName( "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 );
85   myButtonCancel->setObjectName( "buttonCancel" );
86   myButtonCancel->setText( tr( "BUT_CANCEL"  ) );
87   myButtonCancel->setAutoDefault( true );
88   GroupButtonsLayout->addWidget( myButtonCancel );
89   /***************************************************************/
90   
91   topLayout->addWidget( GroupC1 );
92   topLayout->addWidget( GroupButtons );
93   
94   // signals and slots connections
95   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
96   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
97   
98   /* Move widget on the botton right corner of main widget */
99   SUIT_Tools::centerWidget( this, parent );
100 }
101
102 /*!
103   Destructor
104 */
105 LightApp_NameDlg::~LightApp_NameDlg()
106 {
107 }
108
109 /*!
110   Sets name
111 */
112 void LightApp_NameDlg::setName( const QString& name )
113 {
114   myLineEdit->setText( name );
115   myLineEdit->end(false);
116   myLineEdit->home(true);
117 }
118
119 /*!
120   Returns name entered by user
121 */
122 QString LightApp_NameDlg::name()
123 {
124   return myLineEdit->text();
125 }
126
127 /*!
128   Accepts if name isn't empty
129 */
130 void LightApp_NameDlg::accept()
131 {
132   if ( name().trimmed().isEmpty() )
133     return;
134   QDialog::accept();
135 }
136
137 /*!
138   Creates modal <Rename> dialog and returns name entered [ static ]
139 */
140 QString LightApp_NameDlg::getName( QWidget* parent, const QString& oldName )
141 {
142   QString n;
143   LightApp_NameDlg* dlg = new LightApp_NameDlg( parent );
144   if ( !oldName.isNull() )
145     dlg->setName( oldName );
146   if ( dlg->exec() == QDialog::Accepted ) 
147     n = dlg->name();
148   delete dlg;
149   return n;
150 }