1 // SALOME VisuGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : VisuGUI_NameDlg.cxx
8 // Author : Vadim SANDLER
12 #include "VisuGUI_NameDlg.h"
15 #include <SUIT_Session.h>
16 #include <SUIT_Application.h>
17 #include <SUIT_Desktop.h>
18 #include <SUIT_Tools.h>
19 #include <SUIT_MessageBox.h>
20 #include <SUIT_ResourceMgr.h>
22 #include <LightApp_Application.h>
24 #include <qgroupbox.h>
26 #include <qlineedit.h>
27 #include <qpushbutton.h>
34 VisuGUI_NameDlg::VisuGUI_NameDlg( QWidget* parent )
35 : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(),
38 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
40 setCaption( tr("TLT_RENAME") );
41 setSizeGripEnabled( TRUE );
43 QVBoxLayout* topLayout = new QVBoxLayout( this );
44 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
46 /***************************************************************/
47 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
48 GroupC1->setColumnLayout(0, Qt::Vertical );
49 GroupC1->layout()->setMargin( 0 ); GroupC1->layout()->setSpacing( 0 );
50 QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1->layout() );
51 GroupC1Layout->setAlignment( Qt::AlignTop );
52 GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
54 QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" );
55 TextLabel->setText( tr( "NAME_LBL" ) );
56 GroupC1Layout->addWidget( TextLabel );
58 myLineEdit = new QLineEdit( GroupC1, "LineEdit1" );
59 myLineEdit->setMinimumSize( 250, 0 );
60 GroupC1Layout->addWidget( myLineEdit );
62 /***************************************************************/
63 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
64 GroupButtons->setColumnLayout(0, Qt::Vertical );
65 GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 );
66 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
67 GroupButtonsLayout->setAlignment( Qt::AlignTop );
68 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
70 myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
71 myButtonOk->setText( tr( "BUT_OK" ) );
72 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
73 GroupButtonsLayout->addWidget( myButtonOk );
75 GroupButtonsLayout->addStretch();
77 myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
78 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
79 myButtonCancel->setAutoDefault( TRUE );
80 GroupButtonsLayout->addWidget( myButtonCancel );
82 myButtonHelp = new QPushButton( GroupButtons, "buttonHelp" );
83 myButtonHelp->setText( tr( "BUT_HELP" ) );
84 myButtonHelp->setAutoDefault( TRUE );
85 GroupButtonsLayout->addWidget( myButtonHelp );
86 /***************************************************************/
88 topLayout->addWidget( GroupC1 );
89 topLayout->addWidget( GroupButtons );
91 // signals and slots connections
92 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
93 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
94 connect( myButtonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
96 /* Move widget on the botton right corner of main widget */
97 SUIT_Tools::centerWidget( this, parent );
103 VisuGUI_NameDlg::~VisuGUI_NameDlg()
110 void VisuGUI_NameDlg::setName( const QString& name )
112 myLineEdit->setText( name );
113 myLineEdit->end(false);
114 myLineEdit->home(true);
118 Returns name entered by user
120 QString VisuGUI_NameDlg::name()
122 return myLineEdit->text();
125 void VisuGUI_NameDlg::accept()
127 if ( name().stripWhiteSpace().isEmpty() )
132 void VisuGUI_NameDlg::onHelp()
134 QString aHelpFileName = "/files/renaming_presentations.htm";
135 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
137 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
138 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
141 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
142 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
143 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
144 QObject::tr("BUT_OK"));
149 Creates modal <Rename> dialog and returns name entered [ static ]
151 QString VisuGUI_NameDlg::getName( QWidget* parent, const QString& oldName )
154 VisuGUI_NameDlg* dlg = new VisuGUI_NameDlg( parent );
155 if ( !oldName.isNull() )
156 dlg->setName( oldName );
157 if ( dlg->exec() == QDialog::Accepted )