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