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 : VisuGUI_NameDlg.cxx
23 // Author : Vadim SANDLER
27 #include "VisuGUI_NameDlg.h"
30 #include <SUIT_Session.h>
31 #include <SUIT_Application.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Tools.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <LightApp_Application.h>
42 #include <QPushButton>
50 VisuGUI_NameDlg::VisuGUI_NameDlg( QWidget* parent )
51 : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(),
52 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )//,WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
54 setWindowTitle( tr("TLT_RENAME") );
55 setSizeGripEnabled( TRUE );
58 QVBoxLayout* topLayout = new QVBoxLayout( this );
59 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
61 /***************************************************************/
62 QGroupBox* GroupC1 = new QGroupBox( this );
63 //GroupC1->setColumnLayout(0, Qt::Vertical );
64 //GroupC1->layout()->setMargin( 0 ); GroupC1->layout()->setSpacing( 0 );
65 QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
66 GroupC1Layout->setAlignment( Qt::AlignTop );
67 GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
69 QLabel* TextLabel = new QLabel( tr( "NAME_LBL" ), GroupC1 );
70 GroupC1Layout->addWidget( TextLabel );
72 myLineEdit = new QLineEdit( GroupC1 );
73 myLineEdit->setMinimumSize( 250, 0 );
74 GroupC1Layout->addWidget( myLineEdit );
76 /***************************************************************/
77 QGroupBox* GroupButtons = new QGroupBox( this );
78 //GroupButtons->setColumnLayout(0, Qt::Vertical );
79 //GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 );
80 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
81 GroupButtonsLayout->setAlignment( Qt::AlignTop );
82 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
84 myButtonOk = new QPushButton( GroupButtons );
85 myButtonOk->setText( tr( "BUT_OK" ) );
86 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
87 GroupButtonsLayout->addWidget( myButtonOk );
89 GroupButtonsLayout->addStretch();
91 myButtonCancel = new QPushButton( GroupButtons );
92 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
93 myButtonCancel->setAutoDefault( TRUE );
94 GroupButtonsLayout->addWidget( myButtonCancel );
96 myButtonHelp = new QPushButton( GroupButtons );
97 myButtonHelp->setText( tr( "BUT_HELP" ) );
98 myButtonHelp->setAutoDefault( TRUE );
99 GroupButtonsLayout->addWidget( myButtonHelp );
100 /***************************************************************/
102 topLayout->addWidget( GroupC1 );
103 topLayout->addWidget( GroupButtons );
105 // signals and slots connections
106 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
107 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
108 connect( myButtonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
110 /* Move widget on the botton right corner of main widget */
111 SUIT_Tools::centerWidget( this, parent );
117 VisuGUI_NameDlg::~VisuGUI_NameDlg()
124 void VisuGUI_NameDlg::setName( const QString& name )
126 myLineEdit->setText( name );
127 myLineEdit->end(false);
128 myLineEdit->home(true);
132 Returns name entered by user
134 QString VisuGUI_NameDlg::name()
136 return myLineEdit->text();
139 void VisuGUI_NameDlg::accept()
141 if ( name().trimmed().isEmpty() )
146 void VisuGUI_NameDlg::onHelp()
148 QString aHelpFileName = "viewing_3d_presentations_intro_page.html";
149 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
151 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
152 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
157 platform = "winapplication";
159 platform = "application";
161 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
162 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
163 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
168 Creates modal <Rename> dialog and returns name entered [ static ]
170 QString VisuGUI_NameDlg::getName( QWidget* parent, const QString& oldName )
173 VisuGUI_NameDlg* dlg = new VisuGUI_NameDlg( parent );
174 if ( !oldName.isNull() )
175 dlg->setName( oldName );
176 if ( dlg->exec() == QDialog::Accepted )
182 void VisuGUI_NameDlg::keyPressEvent( QKeyEvent* e )
184 QDialog::keyPressEvent( e );
185 if ( e->isAccepted() )
188 if ( e->key() == Qt::Key_F1 )