1 // Copyright (C) 2007-2011 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
23 // File : VisuGUI_NameDlg.cxx
24 // Author : Vadim SANDLER
28 #include "VisuGUI_NameDlg.h"
31 #include <SUIT_Session.h>
32 #include <SUIT_Application.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Tools.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_ResourceMgr.h>
38 #include <LightApp_Application.h>
43 #include <QPushButton>
51 VisuGUI_NameDlg::VisuGUI_NameDlg( QWidget* parent )
52 : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(),
53 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )//,WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
55 setWindowTitle( tr("TLT_RENAME") );
56 setSizeGripEnabled( TRUE );
59 QVBoxLayout* topLayout = new QVBoxLayout( this );
60 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
62 /***************************************************************/
63 QGroupBox* GroupC1 = new QGroupBox( this );
64 //GroupC1->setColumnLayout(0, Qt::Vertical );
65 //GroupC1->layout()->setMargin( 0 ); GroupC1->layout()->setSpacing( 0 );
66 QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
67 GroupC1Layout->setAlignment( Qt::AlignTop );
68 GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
70 QLabel* TextLabel = new QLabel( tr( "NAME_LBL" ), GroupC1 );
71 GroupC1Layout->addWidget( TextLabel );
73 myLineEdit = new QLineEdit( GroupC1 );
74 myLineEdit->setMinimumSize( 250, 0 );
75 GroupC1Layout->addWidget( myLineEdit );
77 /***************************************************************/
78 QGroupBox* GroupButtons = new QGroupBox( this );
79 //GroupButtons->setColumnLayout(0, Qt::Vertical );
80 //GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 );
81 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
82 GroupButtonsLayout->setAlignment( Qt::AlignTop );
83 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
85 myButtonOk = new QPushButton( GroupButtons );
86 myButtonOk->setText( tr( "BUT_OK" ) );
87 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
88 GroupButtonsLayout->addWidget( myButtonOk );
90 GroupButtonsLayout->addStretch();
92 myButtonCancel = new QPushButton( GroupButtons );
93 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
94 myButtonCancel->setAutoDefault( TRUE );
95 GroupButtonsLayout->addWidget( myButtonCancel );
97 myButtonHelp = new QPushButton( GroupButtons );
98 myButtonHelp->setText( tr( "BUT_HELP" ) );
99 myButtonHelp->setAutoDefault( TRUE );
100 GroupButtonsLayout->addWidget( myButtonHelp );
101 /***************************************************************/
103 topLayout->addWidget( GroupC1 );
104 topLayout->addWidget( GroupButtons );
106 // signals and slots connections
107 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
108 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
109 connect( myButtonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
111 /* Move widget on the botton right corner of main widget */
112 SUIT_Tools::centerWidget( this, parent );
118 VisuGUI_NameDlg::~VisuGUI_NameDlg()
125 void VisuGUI_NameDlg::setName( const QString& name )
127 myLineEdit->setText( name );
128 myLineEdit->end(false);
129 myLineEdit->home(true);
133 Returns name entered by user
135 QString VisuGUI_NameDlg::name()
137 return myLineEdit->text();
140 void VisuGUI_NameDlg::accept()
142 if ( name().trimmed().isEmpty() )
147 void VisuGUI_NameDlg::onHelp()
149 QString aHelpFileName = "viewing_3d_presentations_page.html#rename_anchor";
150 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
152 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
153 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
158 platform = "winapplication";
160 platform = "application";
162 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
163 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
164 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
169 Creates modal <Rename> dialog and returns name entered [ static ]
171 QString VisuGUI_NameDlg::getName( QWidget* parent, const QString& oldName )
174 VisuGUI_NameDlg* dlg = new VisuGUI_NameDlg( parent );
175 if ( !oldName.isNull() )
176 dlg->setName( oldName );
177 if ( dlg->exec() == QDialog::Accepted )
183 void VisuGUI_NameDlg::keyPressEvent( QKeyEvent* e )
185 QDialog::keyPressEvent( e );
186 if ( e->isAccepted() )
189 if ( e->key() == Qt::Key_F1 )