1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 // File : LightApp_NameDlg.cxx
20 // Author : Vadim SANDLER
23 #include <LightApp_NameDlg.h>
24 #include <SUIT_Application.h>
25 #include <SUIT_Desktop.h>
26 #include <SUIT_Tools.h>
28 #include <qgroupbox.h>
30 #include <qlineedit.h>
31 #include <qpushbutton.h>
41 LightApp_NameDlg::LightApp_NameDlg( QWidget* parent )
42 : QDialog( parent ? parent : NULL,//application()->desktop(),
45 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
47 setCaption( tr("TLT_RENAME") );
48 setSizeGripEnabled( TRUE );
50 QVBoxLayout* topLayout = new QVBoxLayout( this );
51 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
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 );
61 QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" );
62 TextLabel->setText( tr( "NAME_LBL" ) );
63 GroupC1Layout->addWidget( TextLabel );
65 myLineEdit = new QLineEdit( GroupC1, "LineEdit1" );
66 myLineEdit->setMinimumSize( 250, 0 );
67 GroupC1Layout->addWidget( myLineEdit );
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 );
77 myButtonOk = new QPushButton( GroupButtons, "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, "buttonCancel" );
85 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
86 myButtonCancel->setAutoDefault( TRUE );
87 GroupButtonsLayout->addWidget( myButtonCancel );
88 /***************************************************************/
90 topLayout->addWidget( GroupC1 );
91 topLayout->addWidget( GroupButtons );
93 // signals and slots connections
94 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
95 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
97 /* Move widget on the botton right corner of main widget */
98 SUIT_Tools::centerWidget( this, parent );
104 LightApp_NameDlg::~LightApp_NameDlg()
111 void LightApp_NameDlg::setName( const QString& name )
113 myLineEdit->setText( name );
114 myLineEdit->end(false);
115 myLineEdit->home(true);
119 Returns name entered by user
121 QString LightApp_NameDlg::name()
123 return myLineEdit->text();
126 void LightApp_NameDlg::accept()
128 if ( name().stripWhiteSpace().isEmpty() )
134 Creates modal <Rename> dialog and returns name entered [ static ]
136 QString LightApp_NameDlg::getName( QWidget* parent, const QString& oldName )
139 LightApp_NameDlg* dlg = new LightApp_NameDlg( parent );
140 if ( !oldName.isNull() )
141 dlg->setName( oldName );
142 if ( dlg->exec() == QDialog::Accepted )