1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, 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.
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
22 // File : LightApp_NameDlg.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "LightApp_NameDlg.h"
26 #include <SUIT_Tools.h>
31 #include <QPushButton>
32 #include <QHBoxLayout>
33 #include <QVBoxLayout>
42 LightApp_NameDlg::LightApp_NameDlg( QWidget* parent )
43 : QDialog( parent ? parent : NULL,//application()->desktop(),
44 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
46 setObjectName( "LightApp_NameDlg" );
49 setWindowTitle( tr("TLT_RENAME") );
50 setSizeGripEnabled( TRUE );
52 QVBoxLayout* topLayout = new QVBoxLayout( this );
53 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
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 );
62 QLabel* TextLabel = new QLabel( GroupC1 );
63 TextLabel->setObjectName( "TextLabel1" );
64 TextLabel->setText( tr( "NAME_LBL" ) );
65 GroupC1Layout->addWidget( TextLabel );
67 myLineEdit = new QLineEdit( GroupC1 );
68 myLineEdit->setObjectName( "LineEdit1" );
69 myLineEdit->setMinimumSize( 250, 0 );
70 GroupC1Layout->addWidget( myLineEdit );
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 );
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 );
85 GroupButtonsLayout->addStretch();
87 myButtonCancel = new QPushButton( GroupButtons );
88 myButtonCancel->setObjectName( "buttonCancel" );
89 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
90 myButtonCancel->setAutoDefault( TRUE );
91 GroupButtonsLayout->addWidget( myButtonCancel );
92 /***************************************************************/
94 topLayout->addWidget( GroupC1 );
95 topLayout->addWidget( GroupButtons );
97 // signals and slots connections
98 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
99 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
101 /* Move widget on the botton right corner of main widget */
102 SUIT_Tools::centerWidget( this, parent );
108 LightApp_NameDlg::~LightApp_NameDlg()
115 void LightApp_NameDlg::setName( const QString& name )
117 myLineEdit->setText( name );
118 myLineEdit->end(false);
119 myLineEdit->home(true);
123 Returns name entered by user
125 QString LightApp_NameDlg::name()
127 return myLineEdit->text();
131 Accepts if name isn't empty
133 void LightApp_NameDlg::accept()
135 if ( name().trimmed().isEmpty() )
141 Creates modal <Rename> dialog and returns name entered [ static ]
143 QString LightApp_NameDlg::getName( QWidget* parent, const QString& oldName )
146 LightApp_NameDlg* dlg = new LightApp_NameDlg( parent );
147 if ( !oldName.isNull() )
148 dlg->setName( oldName );
149 if ( dlg->exec() == QDialog::Accepted )