Salome HOME
d90377548a43fe6ec98767a09c09524dc1587c6b
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_LineWidthDlg.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  GEOM GEOMGUI : GUI for Geometry component
21 //  File   : GEOMToolsGUI_LineWidthDlg.cxx
22 //  Author : OCC Team
23 //
24 #include "GEOMToolsGUI_LineWidthDlg.h"
25 #include <GeometryGUI.h>
26 #include <GEOM_Constants.h>
27 #include <LightApp_Application.h>
28 #include <SalomeApp_IntSpinBox.h>
29
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 <QChar>
37 #include <QPushButton>
38 #include <QGroupBox>
39 #include <QGridLayout>
40 #include <QKeyEvent>
41
42 //=================================================================================
43 // class    : GEOMToolsGUI_LineWidthDlg()
44 // purpose  : Constructs a GEOMToolsGUI_LineWidthDlg 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
50 GEOMToolsGUI_LineWidthDlg::GEOMToolsGUI_LineWidthDlg (QWidget* parent, const QString& title)
51   : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
52 {
53   setObjectName("GEOMToolsGUI_LineWidthDlg");
54   setModal(true);
55
56   setWindowTitle(tr(title.toUtf8().constData()));
57   setSizeGripEnabled(true);
58   QGridLayout* MyDialogLayout = new QGridLayout(this);
59   MyDialogLayout->setSpacing(6);
60   MyDialogLayout->setMargin(11);
61
62
63   /***************************************************************/
64   QGroupBox* GroupC1 = new QGroupBox (this);
65   GroupC1->setObjectName("GroupC1");
66   QGridLayout* GroupC1Layout = new QGridLayout (GroupC1);
67   GroupC1Layout->setAlignment(Qt::AlignTop);
68   GroupC1Layout->setSpacing(6);
69   GroupC1Layout->setMargin(11);
70
71   QLabel* TextLabel1 = new QLabel (GroupC1);
72   TextLabel1->setObjectName("TextLabel1");
73   TextLabel1->setText(tr("GEOM_LINE_WIDTH"));
74   GroupC1Layout->addWidget(TextLabel1, 0, 0);
75
76
77   mySpinBox = new SalomeApp_IntSpinBox (GroupC1);
78   mySpinBox->setRange( 1, 5 );
79   mySpinBox->setSingleStep( 1 );
80  
81   mySpinBox->setObjectName("SpinBoxU");
82   mySpinBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
83   mySpinBox->setValue(1);
84   GroupC1Layout->addWidget(mySpinBox, 0, 1);
85
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 = "line_width_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 bottom right corner of main widget
128   SUIT_Tools::centerWidget(this, parent);
129 }
130
131
132 //=================================================================================
133 // function : ~GEOMToolsGUI_LineWidthDlg()
134 // purpose  : Destroys the object and frees any allocated resources
135 //=================================================================================
136 GEOMToolsGUI_LineWidthDlg::~GEOMToolsGUI_LineWidthDlg()
137 {
138   // no need to delete child widgets, Qt does it all for us
139 }
140
141 int GEOMToolsGUI_LineWidthDlg::getTheLW() const
142 {
143   return mySpinBox->text().toInt();
144 }
145
146 void GEOMToolsGUI_LineWidthDlg::setTheLW (const int v)
147 {
148   mySpinBox->setValue(v);
149 }
150
151
152 //=================================================================================
153 // function : ClickOnHelp()
154 // purpose  :
155 //=================================================================================
156 void GEOMToolsGUI_LineWidthDlg::ClickOnHelp()
157 {
158   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
159   if (app) {
160     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>(app->module("Geometry"));
161     app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
162   }
163   else {
164     QString platform;
165 #ifdef WIN32
166     platform = "winapplication";
167 #else
168     platform = "application";
169 #endif
170     SUIT_MessageBox::warning
171       (0, QObject::tr("WRN_WARNING"),
172        QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
173        arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
174        QObject::tr("BUT_OK"));
175   }
176 }
177
178 //=================================================================================
179 // function : keyPressEvent()
180 // purpose  :
181 //=================================================================================
182 void GEOMToolsGUI_LineWidthDlg::keyPressEvent (QKeyEvent* e)
183 {
184   QDialog::keyPressEvent(e);
185   if (e->isAccepted())
186     return;
187
188   if (e->key() == Qt::Key_F1) {
189     e->accept();
190     ClickOnHelp();
191   }
192 }