]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI_DeflectionDlg.cxx
Salome HOME
715c22dee0c042eb5ab2713268f3ba82cabf905c
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_DeflectionDlg.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_DeflectionDlg.cxx
24 //  Author : OCC Team
25
26 #include "GEOMToolsGUI_DeflectionDlg.h"
27 #include <GeometryGUI.h>
28 #include <LightApp_Application.h>
29 #include <QtxDoubleSpinBox.h>
30
31 #include <SUIT_MessageBox.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_Tools.h>
35
36 #include <QLabel>
37 #include <QPushButton>
38 #include <QGroupBox>
39 #include <QGridLayout>
40 #include <QKeyEvent>
41
42 //=================================================================================
43 // class    : GEOMToolsGUI_DeflectionDlg()
44 // purpose  : Constructs a GEOMToolsGUI_DeflectionDlg 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_DeflectionDlg::GEOMToolsGUI_DeflectionDlg (QWidget* parent)
50   : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
51 {
52   setObjectName("GEOMToolsGUI_DeflectionDlg");
53   setModal(true);
54
55   setWindowTitle(tr("GEOM_DEFLECTION_TLT"));
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_DEFLECTION"));
72   GroupC1Layout->addWidget(TextLabel1, 0, 0);
73
74   SpinBox = new QtxDoubleSpinBox (GroupC1);
75   SpinBox->setPrecision( 6 );
76   SpinBox->setDecimals( 6 );
77   SpinBox->setRange( DEFLECTION_MIN, 1.0 );
78   SpinBox->setSingleStep( 1.0e-04 );
79   //SpinBox->setMinimum(1.0e-07);
80   //SpinBox->setMaximum(1.0);
81   //SpinBox->setStep(1.0e-04);
82   SpinBox->setObjectName("SpinBoxU");
83   SpinBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
84   SpinBox->setValue(1.0e-04);
85   GroupC1Layout->addWidget(SpinBox, 0, 1);
86
87   /***************************************************************/
88   QGroupBox* GroupButtons = new QGroupBox (this);
89   GroupButtons->setObjectName("GroupButtons");
90   QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
91   GroupButtonsLayout->setAlignment(Qt::AlignTop);
92   GroupButtonsLayout->setSpacing(6);
93   GroupButtonsLayout->setMargin(11);
94
95   QPushButton* buttonOk = new QPushButton (GroupButtons);
96   buttonOk->setObjectName("buttonOk");
97   buttonOk->setText(tr("GEOM_BUT_OK"));
98   buttonOk->setAutoDefault(TRUE);
99   buttonOk->setDefault(TRUE);
100   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
101
102   GroupButtonsLayout->addItem(new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
103
104   QPushButton* buttonCancel = new QPushButton (GroupButtons);
105   buttonCancel->setObjectName("buttonCancel");
106   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
107   buttonCancel->setAutoDefault(TRUE);
108   GroupButtonsLayout->addWidget(buttonCancel, 0, 1);
109
110   QPushButton* buttonHelp = new QPushButton (GroupButtons);
111   buttonHelp->setObjectName("buttonHelp");
112   buttonHelp->setText(tr("GEOM_BUT_HELP"));
113   buttonHelp->setAutoDefault(TRUE);
114   GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
115   /***************************************************************/
116
117   MyDialogLayout->addWidget(GroupC1, 0, 0);
118   MyDialogLayout->addWidget(GroupButtons, 1, 0);
119
120   myHelpFileName = "deflection_page.html";
121
122   // signals and slots connections
123   connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
124   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
125   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
126
127   // Move widget on the botton right corner of main widget
128   SUIT_Tools::centerWidget(this, parent);
129 }
130
131 //=================================================================================
132 // function : ~GEOMToolsGUI_DeflectionDlg()
133 // purpose  : Destroys the object and frees any allocated resources
134 //=================================================================================
135 GEOMToolsGUI_DeflectionDlg::~GEOMToolsGUI_DeflectionDlg()
136 {
137   // no need to delete child widgets, Qt does it all for us
138 }
139
140 double GEOMToolsGUI_DeflectionDlg::getDC() const
141 {
142   return SpinBox->text().toDouble();
143 }
144
145 void GEOMToolsGUI_DeflectionDlg::setDC (const double v)
146 {
147   SpinBox->setValue(v);
148 }
149
150 //=================================================================================
151 // function : ClickOnHelp()
152 // purpose  :
153 //=================================================================================
154 void GEOMToolsGUI_DeflectionDlg::ClickOnHelp()
155 {
156   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
157   if (app) {
158     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>(app->module("Geometry"));
159     app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
160   }
161   else {
162     QString platform;
163 #ifdef WIN32
164     platform = "winapplication";
165 #else
166     platform = "application";
167 #endif
168     SUIT_MessageBox::warning
169       (0, QObject::tr("WRN_WARNING"),
170        QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
171        arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
172        QObject::tr("BUT_OK"));
173   }
174 }
175
176 //=================================================================================
177 // function : keyPressEvent()
178 // purpose  :
179 //=================================================================================
180 void GEOMToolsGUI_DeflectionDlg::keyPressEvent (QKeyEvent* e)
181 {
182   QDialog::keyPressEvent(e);
183   if (e->isAccepted())
184     return;
185
186   if (e->key() == Qt::Key_F1) {
187     e->accept();
188     ClickOnHelp();
189   }
190 }