Back to index

salome-gui  6.5.0
LightApp_NameDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : LightApp_NameDlg.cxx
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 //
00026 #include "LightApp_NameDlg.h"
00027 #include <SUIT_Tools.h>
00028 
00029 #include <QGroupBox>
00030 #include <QLabel>
00031 #include <QLineEdit>
00032 #include <QPushButton>
00033 #include <QHBoxLayout>
00034 #include <QVBoxLayout>
00035 
00039 LightApp_NameDlg::LightApp_NameDlg( QWidget* parent )
00040 : QDialog( parent ? parent : NULL,//application()->desktop(), 
00041 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
00042 {
00043   setObjectName( "LightApp_NameDlg" );
00044   setModal( true );
00045 
00046   setWindowTitle( tr("TLT_RENAME") );
00047   setSizeGripEnabled( TRUE );
00048 
00049   QVBoxLayout* topLayout = new QVBoxLayout( this );
00050   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
00051 
00052   /***************************************************************/
00053   QGroupBox* GroupC1 = new QGroupBox( this );
00054   GroupC1->setObjectName( "GroupC1" );
00055   QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
00056   GroupC1Layout->setAlignment( Qt::AlignTop );
00057   GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
00058   
00059   QLabel* TextLabel = new QLabel( GroupC1 );
00060   TextLabel->setObjectName( "TextLabel1" );
00061   TextLabel->setText( tr( "NAME_LBL" ) );
00062   GroupC1Layout->addWidget( TextLabel );
00063   
00064   myLineEdit = new QLineEdit( GroupC1 );
00065   myLineEdit->setObjectName( "LineEdit1" );
00066   myLineEdit->setMinimumSize( 250, 0 );
00067   GroupC1Layout->addWidget( myLineEdit );
00068   
00069   /***************************************************************/
00070   QGroupBox* GroupButtons = new QGroupBox( this );
00071   GroupButtons->setObjectName( "GroupButtons" );
00072   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
00073   GroupButtonsLayout->setAlignment( Qt::AlignTop );
00074   GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
00075   
00076   myButtonOk = new QPushButton( GroupButtons );
00077   myButtonOk->setObjectName( "buttonOk" );
00078   myButtonOk->setText( tr( "BUT_OK"  ) );
00079   myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
00080   GroupButtonsLayout->addWidget( myButtonOk );
00081 
00082   GroupButtonsLayout->addStretch();
00083   
00084   myButtonCancel = new QPushButton( GroupButtons );
00085   myButtonCancel->setObjectName( "buttonCancel" );
00086   myButtonCancel->setText( tr( "BUT_CANCEL"  ) );
00087   myButtonCancel->setAutoDefault( TRUE );
00088   GroupButtonsLayout->addWidget( myButtonCancel );
00089   /***************************************************************/
00090   
00091   topLayout->addWidget( GroupC1 );
00092   topLayout->addWidget( GroupButtons );
00093   
00094   // signals and slots connections
00095   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
00096   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00097   
00098   /* Move widget on the botton right corner of main widget */
00099   SUIT_Tools::centerWidget( this, parent );
00100 }
00101 
00105 LightApp_NameDlg::~LightApp_NameDlg()
00106 {
00107 }
00108 
00112 void LightApp_NameDlg::setName( const QString& name )
00113 {
00114   myLineEdit->setText( name );
00115   myLineEdit->end(false);
00116   myLineEdit->home(true);
00117 }
00118 
00122 QString LightApp_NameDlg::name()
00123 {
00124   return myLineEdit->text();
00125 }
00126 
00130 void LightApp_NameDlg::accept()
00131 {
00132   if ( name().trimmed().isEmpty() )
00133     return;
00134   QDialog::accept();
00135 }
00136 
00140 QString LightApp_NameDlg::getName( QWidget* parent, const QString& oldName )
00141 {
00142   QString n;
00143   LightApp_NameDlg* dlg = new LightApp_NameDlg( parent );
00144   if ( !oldName.isNull() )
00145     dlg->setName( oldName );
00146   if ( dlg->exec() == QDialog::Accepted ) 
00147     n = dlg->name();
00148   delete dlg;
00149   return n;
00150 }