1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VisuGUI_NameDlg.cxx
21 // Author : Vadim SANDLER
25 #include "VisuGUI_NameDlg.h"
28 #include <SUIT_Session.h>
29 #include <SUIT_Application.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_Tools.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_ResourceMgr.h>
35 #include <LightApp_Application.h>
37 #include <qgroupbox.h>
39 #include <qlineedit.h>
40 #include <qpushbutton.h>
47 VisuGUI_NameDlg::VisuGUI_NameDlg( QWidget* parent )
48 : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(),
51 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
53 setCaption( tr("TLT_RENAME") );
54 setSizeGripEnabled( TRUE );
56 QVBoxLayout* topLayout = new QVBoxLayout( this );
57 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
59 /***************************************************************/
60 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
61 GroupC1->setColumnLayout(0, Qt::Vertical );
62 GroupC1->layout()->setMargin( 0 ); GroupC1->layout()->setSpacing( 0 );
63 QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1->layout() );
64 GroupC1Layout->setAlignment( Qt::AlignTop );
65 GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
67 QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" );
68 TextLabel->setText( tr( "NAME_LBL" ) );
69 GroupC1Layout->addWidget( TextLabel );
71 myLineEdit = new QLineEdit( GroupC1, "LineEdit1" );
72 myLineEdit->setMinimumSize( 250, 0 );
73 GroupC1Layout->addWidget( myLineEdit );
75 /***************************************************************/
76 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
77 GroupButtons->setColumnLayout(0, Qt::Vertical );
78 GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 );
79 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
80 GroupButtonsLayout->setAlignment( Qt::AlignTop );
81 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
83 myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
84 myButtonOk->setText( tr( "BUT_OK" ) );
85 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
86 GroupButtonsLayout->addWidget( myButtonOk );
88 GroupButtonsLayout->addStretch();
90 myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
91 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
92 myButtonCancel->setAutoDefault( TRUE );
93 GroupButtonsLayout->addWidget( myButtonCancel );
95 myButtonHelp = new QPushButton( GroupButtons, "buttonHelp" );
96 myButtonHelp->setText( tr( "BUT_HELP" ) );
97 myButtonHelp->setAutoDefault( TRUE );
98 GroupButtonsLayout->addWidget( myButtonHelp );
99 /***************************************************************/
101 topLayout->addWidget( GroupC1 );
102 topLayout->addWidget( GroupButtons );
104 // signals and slots connections
105 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
106 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
107 connect( myButtonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
109 /* Move widget on the botton right corner of main widget */
110 SUIT_Tools::centerWidget( this, parent );
116 VisuGUI_NameDlg::~VisuGUI_NameDlg()
123 void VisuGUI_NameDlg::setName( const QString& name )
125 myLineEdit->setText( name );
126 myLineEdit->end(false);
127 myLineEdit->home(true);
131 Returns name entered by user
133 QString VisuGUI_NameDlg::name()
135 return myLineEdit->text();
138 void VisuGUI_NameDlg::accept()
140 if ( name().stripWhiteSpace().isEmpty() )
145 void VisuGUI_NameDlg::onHelp()
147 QString aHelpFileName = "/files/renaming_presentations.htm";
148 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
150 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
151 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
154 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
155 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
156 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
157 QObject::tr("BUT_OK"));
162 Creates modal <Rename> dialog and returns name entered [ static ]
164 QString VisuGUI_NameDlg::getName( QWidget* parent, const QString& oldName )
167 VisuGUI_NameDlg* dlg = new VisuGUI_NameDlg( parent );
168 if ( !oldName.isNull() )
169 dlg->setName( oldName );
170 if ( dlg->exec() == QDialog::Accepted )