1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : LightApp_NameDlg.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "LightApp_NameDlg.h"
27 #include <SUIT_Tools.h>
32 #include <QPushButton>
33 #include <QHBoxLayout>
34 #include <QVBoxLayout>
39 LightApp_NameDlg::LightApp_NameDlg( QWidget* parent )
40 : QDialog( parent ? parent : NULL,//application()->desktop(),
41 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
43 setObjectName( "LightApp_NameDlg" );
46 setWindowTitle( tr("TLT_RENAME") );
47 setSizeGripEnabled( true );
49 QVBoxLayout* topLayout = new QVBoxLayout( this );
50 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
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 );
59 QLabel* TextLabel = new QLabel( GroupC1 );
60 TextLabel->setObjectName( "TextLabel1" );
61 TextLabel->setText( tr( "NAME_LBL" ) );
62 GroupC1Layout->addWidget( TextLabel );
64 myLineEdit = new QLineEdit( GroupC1 );
65 myLineEdit->setObjectName( "LineEdit1" );
66 myLineEdit->setMinimumSize( 250, 0 );
67 GroupC1Layout->addWidget( myLineEdit );
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 );
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 );
82 GroupButtonsLayout->addStretch();
84 myButtonCancel = new QPushButton( GroupButtons );
85 myButtonCancel->setObjectName( "buttonCancel" );
86 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
87 myButtonCancel->setAutoDefault( true );
88 GroupButtonsLayout->addWidget( myButtonCancel );
89 /***************************************************************/
91 topLayout->addWidget( GroupC1 );
92 topLayout->addWidget( GroupButtons );
94 // signals and slots connections
95 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
96 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
98 /* Move widget on the botton right corner of main widget */
99 SUIT_Tools::centerWidget( this, parent );
105 LightApp_NameDlg::~LightApp_NameDlg()
112 void LightApp_NameDlg::setName( const QString& name )
114 myLineEdit->setText( name );
115 myLineEdit->end(false);
116 myLineEdit->home(true);
120 Returns name entered by user
122 QString LightApp_NameDlg::name()
124 return myLineEdit->text();
128 Accepts if name isn't empty
130 void LightApp_NameDlg::accept()
132 if ( name().trimmed().isEmpty() )
138 Creates modal <Rename> dialog and returns name entered [ static ]
140 QString LightApp_NameDlg::getName( QWidget* parent, const QString& oldName )
143 LightApp_NameDlg* dlg = new LightApp_NameDlg( parent );
144 if ( !oldName.isNull() )
145 dlg->setName( oldName );
146 if ( dlg->exec() == QDialog::Accepted )