]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_NameDlg.cxx
Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/visu.git] / src / VISUGUI / VisuGUI_NameDlg.cxx
1 //  SALOME VisuGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : VisuGUI_NameDlg.cxx
8 //  Author : Vadim SANDLER
9 //  Module : SALOME
10 //  $Header$
11
12 #include "VisuGUI_NameDlg.h"
13 #include "VisuGUI.h"
14
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>
21
22 #include <LightApp_Application.h>
23
24 #include <qgroupbox.h>
25 #include <qlabel.h>
26 #include <qlineedit.h>
27 #include <qpushbutton.h>
28 #include <qlayout.h>
29 using namespace std;
30
31 /*!
32   Constructor
33 */
34 VisuGUI_NameDlg::VisuGUI_NameDlg( QWidget* parent )
35     : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(), 
36                "VisuGUI_NameDlg", 
37                true, 
38                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
39 {
40   setCaption( tr("TLT_RENAME") );
41   setSizeGripEnabled( TRUE );
42   
43   QVBoxLayout* topLayout = new QVBoxLayout( this );
44   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
45
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 );
53   
54   QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" );
55   TextLabel->setText( tr( "NAME_LBL" ) );
56   GroupC1Layout->addWidget( TextLabel );
57   
58   myLineEdit = new QLineEdit( GroupC1, "LineEdit1" );
59   myLineEdit->setMinimumSize( 250, 0 );
60   GroupC1Layout->addWidget( myLineEdit );
61   
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 );
69   
70   myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
71   myButtonOk->setText( tr( "BUT_OK"  ) );
72   myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
73   GroupButtonsLayout->addWidget( myButtonOk );
74
75   GroupButtonsLayout->addStretch();
76   
77   myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
78   myButtonCancel->setText( tr( "BUT_CANCEL"  ) );
79   myButtonCancel->setAutoDefault( TRUE );
80   GroupButtonsLayout->addWidget( myButtonCancel );
81
82   myButtonHelp = new QPushButton( GroupButtons, "buttonHelp" );
83   myButtonHelp->setText( tr( "BUT_HELP"  ) );
84   myButtonHelp->setAutoDefault( TRUE );
85   GroupButtonsLayout->addWidget( myButtonHelp );
86   /***************************************************************/
87   
88   topLayout->addWidget( GroupC1 );
89   topLayout->addWidget( GroupButtons );
90   
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() ) );
95   
96   /* Move widget on the botton right corner of main widget */
97   SUIT_Tools::centerWidget( this, parent );
98 }
99
100 /*!
101   Destructor
102 */
103 VisuGUI_NameDlg::~VisuGUI_NameDlg()
104 {
105 }
106
107 /*!
108   Sets name
109 */
110 void VisuGUI_NameDlg::setName( const QString& name )
111 {
112   myLineEdit->setText( name );
113   myLineEdit->end(false);
114   myLineEdit->home(true);
115 }
116
117 /*!
118   Returns name entered by user
119 */
120 QString VisuGUI_NameDlg::name()
121 {
122   return myLineEdit->text();
123 }
124
125 void VisuGUI_NameDlg::accept()
126 {
127   if ( name().stripWhiteSpace().isEmpty() )
128     return;
129   QDialog::accept();
130 }
131
132 void VisuGUI_NameDlg::onHelp()
133 {
134   QString aHelpFileName = "/files/renaming_presentations.htm";
135   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
136   if (app) {
137     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
138     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
139   }
140   else {
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"));
145   }
146 }
147
148 /*!
149   Creates modal <Rename> dialog and returns name entered [ static ]
150 */
151 QString VisuGUI_NameDlg::getName( QWidget* parent, const QString& oldName )
152 {
153   QString n;
154   VisuGUI_NameDlg* dlg = new VisuGUI_NameDlg( parent );
155   if ( !oldName.isNull() )
156     dlg->setName( oldName );
157   if ( dlg->exec() == QDialog::Accepted ) 
158     n = dlg->name();
159   delete dlg;
160   return n;
161 }