Salome HOME
untabify
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_NbIsosDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : GEOMToolsGUI_NbIsosDlg.cxx
24 // Author : OCC Team
25 //
26 #include "GEOMToolsGUI_NbIsosDlg.h"
27 #include <GeometryGUI.h>
28 #include <LightApp_Application.h>
29 #include <SUIT_MessageBox.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Tools.h>
33
34 #include <QLabel>
35 #include <QPushButton>
36 #include <QGroupBox>
37 #include <QGridLayout>
38 #include <QSpinBox>
39 #include <QKeyEvent>
40
41 //=================================================================================
42 // class    : GEOMToolsGUI_NbIsosDlg()
43 // purpose  : Constructs a GEOMToolsGUI_NbIsosDlg which is a child of 'parent', with the 
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 GEOMToolsGUI_NbIsosDlg::GEOMToolsGUI_NbIsosDlg(QWidget* parent )
49   :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
50 {
51   setObjectName( "GEOMToolsGUI_NbIsosDlg" );
52   setModal( true );
53
54   setWindowTitle( tr( "GEOM_MEN_ISOS" ) );
55   setSizeGripEnabled(TRUE);
56   QGridLayout* MyDialogLayout = new QGridLayout(this); 
57   MyDialogLayout->setSpacing(6);
58   MyDialogLayout->setMargin(11);
59   
60   /***************************************************************/
61   QGroupBox* GroupC1 = new QGroupBox( this );
62   GroupC1->setObjectName( "GroupC1" );
63   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
64   GroupC1Layout->setAlignment( Qt::AlignTop );
65   GroupC1Layout->setSpacing( 6 );
66   GroupC1Layout->setMargin( 11 );
67   
68   QLabel* TextLabel1 = new QLabel( GroupC1 );
69   TextLabel1->setObjectName( "TextLabel1" );
70   TextLabel1->setText( tr( "GEOM_MEN_ISOU") );
71   GroupC1Layout->addWidget( TextLabel1, 0, 0 );
72   
73   SpinBoxU = new QSpinBox( GroupC1 );
74   SpinBoxU->setObjectName( "SpinBoxU" );
75   SpinBoxU->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
76   SpinBoxU->setMinimum( 0 );
77   SpinBoxU->setValue( 1 );
78   GroupC1Layout->addWidget( SpinBoxU, 0, 1 );
79
80   QLabel* TextLabel2 = new QLabel( GroupC1 );
81   TextLabel2->setObjectName( "TextLabel2" );
82   TextLabel2->setText( tr( "GEOM_MEN_ISOV") ) ;
83   GroupC1Layout->addWidget( TextLabel2, 0, 2 );
84
85   SpinBoxV = new QSpinBox( GroupC1 );
86   SpinBoxV->setObjectName( "SpinBoxV");
87   SpinBoxV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
88   SpinBoxV->setValue( 1 );
89   SpinBoxV->setMinimum( 0 );
90   GroupC1Layout->addWidget( SpinBoxV, 0, 3 );
91   
92   /***************************************************************/
93   QGroupBox* GroupButtons = new QGroupBox( this );
94   GroupButtons->setObjectName( "GroupButtons" );
95   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
96   GroupButtonsLayout->setAlignment( Qt::AlignTop );
97   GroupButtonsLayout->setSpacing( 6 );
98   GroupButtonsLayout->setMargin( 11 );
99   
100   QPushButton* buttonOk = new QPushButton( GroupButtons );
101   buttonOk->setObjectName( "buttonOk" );
102   buttonOk->setText( tr( "GEOM_BUT_OK" ) ) ;
103   buttonOk->setAutoDefault( TRUE );
104   buttonOk->setDefault( TRUE );
105   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
106   
107   GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
108   
109   QPushButton* buttonCancel = new QPushButton( GroupButtons );
110   buttonCancel->setObjectName( "buttonCancel" );
111   buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) ) ;
112   buttonCancel->setAutoDefault( TRUE );
113   GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
114
115   QPushButton* buttonHelp = new QPushButton( GroupButtons );
116   buttonHelp->setObjectName( "buttonHelp" );
117   buttonHelp->setText( tr( "GEOM_BUT_HELP" ) ) ;
118   buttonHelp->setAutoDefault( TRUE );
119   GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
120   /***************************************************************/
121   
122   MyDialogLayout->addWidget(GroupC1, 0, 0);
123   MyDialogLayout->addWidget(GroupButtons, 1, 0);
124
125   myHelpFileName = "isolines_page.html";
126   
127   // signals and slots connections
128   connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
129   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
130   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
131   
132   /* Move widget on the botton right corner of main widget */
133   SUIT_Tools::centerWidget(this, parent);
134 }
135
136 //=================================================================================
137 // function : ~GEOMToolsGUI_NbIsosDlg()
138 // purpose  : Destroys the object and frees any allocated resources
139 //=================================================================================
140 GEOMToolsGUI_NbIsosDlg::~GEOMToolsGUI_NbIsosDlg()
141 {
142     // no need to delete child widgets, Qt does it all for us
143 }
144
145 int GEOMToolsGUI_NbIsosDlg::getU() const
146 {
147   return SpinBoxU->text().toInt();
148 }
149
150 int GEOMToolsGUI_NbIsosDlg::getV() const
151 {
152   return SpinBoxV->text().toInt();
153 }
154
155 void GEOMToolsGUI_NbIsosDlg::setU( const int v )
156 {
157   SpinBoxU->setValue( v );
158 }
159
160 void GEOMToolsGUI_NbIsosDlg::setV( const int v )
161 {
162   SpinBoxV->setValue( v );
163 }
164
165 //=================================================================================
166 // function : ClickOnHelp()
167 // purpose  :
168 //=================================================================================
169 void GEOMToolsGUI_NbIsosDlg::ClickOnHelp()
170 {
171   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
172   if (app) {
173     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
174     app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
175   }
176   else {
177                 QString platform;
178 #ifdef WIN32
179                 platform = "winapplication";
180 #else
181                 platform = "application";
182 #endif
183     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
184                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
185                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
186                              QObject::tr("BUT_OK"));
187   }
188 }
189
190 //=================================================================================
191 // function : keyPressEvent()
192 // purpose  :
193 //=================================================================================
194 void GEOMToolsGUI_NbIsosDlg::keyPressEvent( QKeyEvent* e )
195 {
196   QDialog::keyPressEvent( e );
197   if ( e->isAccepted() )
198     return;
199
200   if ( e->key() == Qt::Key_F1 )
201     {
202       e->accept();
203       ClickOnHelp();
204     }
205 }