]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_NameDlg.cxx
Salome HOME
b4a479ffa402959a8ea02608364effa828ff9338
[modules/visu.git] / src / VISUGUI / VisuGUI_NameDlg.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
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. 
8 // 
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. 
13 // 
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 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : VisuGUI_NameDlg.cxx
21 //  Author : Vadim SANDLER
22 //  Module : SALOME
23 //  $Header$
24
25 #include "VisuGUI_NameDlg.h"
26 #include "VisuGUI.h"
27
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>
34
35 #include <LightApp_Application.h>
36
37 #include <qgroupbox.h>
38 #include <qlabel.h>
39 #include <qlineedit.h>
40 #include <qpushbutton.h>
41 #include <qlayout.h>
42 using namespace std;
43
44 /*!
45   Constructor
46 */
47 VisuGUI_NameDlg::VisuGUI_NameDlg( QWidget* parent )
48     : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(), 
49                "VisuGUI_NameDlg", 
50                true, 
51                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
52 {
53   setCaption( tr("TLT_RENAME") );
54   setSizeGripEnabled( TRUE );
55   
56   QVBoxLayout* topLayout = new QVBoxLayout( this );
57   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
58
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 );
66   
67   QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" );
68   TextLabel->setText( tr( "NAME_LBL" ) );
69   GroupC1Layout->addWidget( TextLabel );
70   
71   myLineEdit = new QLineEdit( GroupC1, "LineEdit1" );
72   myLineEdit->setMinimumSize( 250, 0 );
73   GroupC1Layout->addWidget( myLineEdit );
74   
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 );
82   
83   myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
84   myButtonOk->setText( tr( "BUT_OK"  ) );
85   myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
86   GroupButtonsLayout->addWidget( myButtonOk );
87
88   GroupButtonsLayout->addStretch();
89   
90   myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
91   myButtonCancel->setText( tr( "BUT_CANCEL"  ) );
92   myButtonCancel->setAutoDefault( TRUE );
93   GroupButtonsLayout->addWidget( myButtonCancel );
94
95   myButtonHelp = new QPushButton( GroupButtons, "buttonHelp" );
96   myButtonHelp->setText( tr( "BUT_HELP"  ) );
97   myButtonHelp->setAutoDefault( TRUE );
98   GroupButtonsLayout->addWidget( myButtonHelp );
99   /***************************************************************/
100   
101   topLayout->addWidget( GroupC1 );
102   topLayout->addWidget( GroupButtons );
103   
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() ) );
108   
109   /* Move widget on the botton right corner of main widget */
110   SUIT_Tools::centerWidget( this, parent );
111 }
112
113 /*!
114   Destructor
115 */
116 VisuGUI_NameDlg::~VisuGUI_NameDlg()
117 {
118 }
119
120 /*!
121   Sets name
122 */
123 void VisuGUI_NameDlg::setName( const QString& name )
124 {
125   myLineEdit->setText( name );
126   myLineEdit->end(false);
127   myLineEdit->home(true);
128 }
129
130 /*!
131   Returns name entered by user
132 */
133 QString VisuGUI_NameDlg::name()
134 {
135   return myLineEdit->text();
136 }
137
138 void VisuGUI_NameDlg::accept()
139 {
140   if ( name().stripWhiteSpace().isEmpty() )
141     return;
142   QDialog::accept();
143 }
144
145 void VisuGUI_NameDlg::onHelp()
146 {
147   QString aHelpFileName = "/files/renaming_presentations.htm";
148   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
149   if (app) {
150     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
151     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
152   }
153   else {
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"));
158   }
159 }
160
161 /*!
162   Creates modal <Rename> dialog and returns name entered [ static ]
163 */
164 QString VisuGUI_NameDlg::getName( QWidget* parent, const QString& oldName )
165 {
166   QString n;
167   VisuGUI_NameDlg* dlg = new VisuGUI_NameDlg( parent );
168   if ( !oldName.isNull() )
169     dlg->setName( oldName );
170   if ( dlg->exec() == QDialog::Accepted ) 
171     n = dlg->name();
172   delete dlg;
173   return n;
174 }