Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSolResistanceDialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
23 #include "TYSolResistanceDialog.h"
24 
25 #include <qvariant.h>
26 #include <qframe.h>
27 #include <qslider.h>
28 #include <qtoolbutton.h>
29 #include <qtooltip.h>
30 #include <qwhatsthis.h>
31 #include <qbuttongroup.h>
32 // Added by qt3to4:
33 #include <QLabel>
34 #include <QVBoxLayout>
35 // #include <QWindowsStyle>
36 #include <QLineEdit>
37 #include <QStyle>
38 
39 #include "QPushButton"
40 
42 #define TR(id) OLocalizator::getString("TYSolResistanceDialog", (id))
43 
46 
48 static double resistance[] = {5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000};
49 
50 TYSolResistanceDialog::TYSolResistanceDialog(QWidget* parent, double res /*=0*/, const char* name, bool modal,
51  Qt::WindowFlags fl)
52  : TYFormDialog(parent, fl)
53 {
54  setObjectName(name);
55  setModal(modal);
56  _res = res;
57  if (!name)
58  {
59  resize(263, 536);
60  }
61  setWindowTitle(TR("id_resistance"));
62  setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
63 
64  // Main Dialog window and its parameters
65  this->setFixedSize(280, 560);
66  _frame6 = new QFrame(this);
67  _frame6->setGeometry(QRect(0, 0, 280, 560));
68  _frame6->setFrameShape(QFrame::StyledPanel);
69  _frame6->setFrameShadow(QFrame::Raised);
70 
71  // Position indicators for the different ToolButtons
72  _line1_2_4 = new QFrame(_frame6);
73  _line1_2_4->setGeometry(QRect(150, 403, 20, 20));
74  _line1_2_4->setProperty("frameShape", (int)QFrame::HLine);
75  _line1_2_4->setFrameShadow(QFrame::Sunken);
76  _line1_2_4->setFrameShape(QFrame::HLine);
77 
78  _line1_2_11 = new QFrame(_frame6);
79  _line1_2_11->setGeometry(QRect(150, 333, 20, 20));
80  _line1_2_11->setProperty("frameShape", (int)QFrame::HLine);
81  _line1_2_11->setFrameShadow(QFrame::Sunken);
82  _line1_2_11->setFrameShape(QFrame::HLine);
83 
84  _line1_2_13 = new QFrame(_frame6);
85  _line1_2_13->setGeometry(QRect(150, 313, 20, 20));
86  _line1_2_13->setProperty("frameShape", (int)QFrame::HLine);
87  _line1_2_13->setFrameShadow(QFrame::Sunken);
88  _line1_2_13->setFrameShape(QFrame::HLine);
89 
90  _line1_2_6 = new QFrame(_frame6);
91  _line1_2_6->setGeometry(QRect(150, 252, 20, 20));
92  _line1_2_6->setProperty("frameShape", (int)QFrame::HLine);
93  _line1_2_6->setFrameShadow(QFrame::Sunken);
94  _line1_2_6->setFrameShape(QFrame::HLine);
95 
96  _line1_2 = new QFrame(_frame6);
97  _line1_2->setGeometry(QRect(150, 221, 20, 20));
98  _line1_2->setProperty("frameShape", (int)QFrame::HLine);
99  _line1_2->setFrameShadow(QFrame::Sunken);
100  _line1_2->setFrameShape(QFrame::HLine);
101 
102  _line1_2_5 = new QFrame(_frame6);
103  _line1_2_5->setGeometry(QRect(150, 196, 20, 20));
104  _line1_2_5->setProperty("frameShape", (int)QFrame::HLine);
105  _line1_2_5->setFrameShadow(QFrame::Sunken);
106  _line1_2_5->setFrameShape(QFrame::HLine);
107 
108  _line1_2_2 = new QFrame(_frame6);
109  _line1_2_2->setGeometry(QRect(150, 163, 20, 20));
110  _line1_2_2->setProperty("frameShape", (int)QFrame::HLine);
111  _line1_2_2->setFrameShadow(QFrame::Sunken);
112  _line1_2_2->setFrameShape(QFrame::HLine);
113 
114  _line1_2_7 = new QFrame(_frame6);
115  _line1_2_7->setGeometry(QRect(150, 98, 20, 16));
116  _line1_2_7->setProperty("frameShape", (int)QFrame::HLine);
117  _line1_2_7->setFrameShadow(QFrame::Sunken);
118  _line1_2_7->setFrameShape(QFrame::HLine);
119 
120  _line1_2_3 = new QFrame(_frame6);
121  _line1_2_3->setGeometry(QRect(150, 74, 20, 20));
122  _line1_2_3->setProperty("frameShape", (int)QFrame::HLine);
123  _line1_2_3->setFrameShadow(QFrame::Sunken);
124  _line1_2_3->setFrameShape(QFrame::HLine);
125 
126  _line1 = new QFrame(_frame6);
127  _line1->setGeometry(QRect(150, 36, 20, 20));
128  _line1->setProperty("frameShape", (int)QFrame::HLine);
129  _line1->setFrameShadow(QFrame::Sunken);
130  _line1->setFrameShape(QFrame::HLine);
131 
132  // Names associated to the different ToolButtons
133  _textLabel5 = new QLabel(_frame6);
134  _textLabel5->setGeometry(QRect(40, 403, 100, 18));
135  _textLabel5->setText(TR("id_neigefraiche"));
136 
137  _textLabel5_8_3 = new QLabel(_frame6);
138  _textLabel5_8_3->setGeometry(QRect(40, 333, 100, 18));
139  _textLabel5_8_3->setText(TR("id_neigedure"));
140 
141  _textLabel5_8_2 = new QLabel(_frame6);
142  _textLabel5_8_2->setGeometry(QRect(40, 313, 100, 18));
143  _textLabel5_8_2->setText(TR("id_terrevegetale"));
144 
145  _textLabel5_8 = new QLabel(_frame6);
146  _textLabel5_8->setGeometry(QRect(40, 252, 100, 18));
147  _textLabel5_8->setText(TR("id_solherbeux"));
148 
149  _textLabel5_8_4 = new QLabel(_frame6);
150  _textLabel5_8_4->setGeometry(QRect(40, 221, 100, 18));
151  _textLabel5_8_4->setText(TR("id_gazon"));
152 
153  _textLabel5_8_5 = new QLabel(_frame6);
154  _textLabel5_8_5->setGeometry(QRect(40, 196, 100, 18));
155  _textLabel5_8_5->setText(TR("id_guarrigue"));
156 
157  _textLabel5_8_6 = new QLabel(_frame6);
158  _textLabel5_8_6->setGeometry(QRect(40, 163, 100, 18));
159  _textLabel5_8_6->setText(TR("id_sablecompacte"));
160 
161  _textLabel5_8_7 = new QLabel(_frame6);
162  _textLabel5_8_7->setGeometry(QRect(40, 98, 100, 18));
163  _textLabel5_8_7->setText(TR("id_terrecompactee"));
164 
165  _textLabel5_8_11 = new QLabel(_frame6);
166  _textLabel5_8_11->setGeometry(QRect(40, 76, 100, 18));
167  _textLabel5_8_11->setText(TR("id_solpave"));
168 
169  _textLabel5_8_13 = new QLabel(_frame6);
170  _textLabel5_8_13->setGeometry(QRect(40, 36, 100, 18));
171  _textLabel5_8_13->setText(TR("id_asphalte"));
172 
173  _textLabel3 = new QLabel(_frame6);
174  _textLabel3->setGeometry(QRect(10, 460, 150, 19));
175  _textLabel3->setText(TR("id_resistance"));
176 
177  // Manual indication of the resistance value
179  _lineEdit1->setEnabled(true);
180  _lineEdit1->setGeometry(QRect(170, 460, 50, 20));
181 
182  _textLabel6 = new QLabel(_frame6);
183  _textLabel6->setGeometry(QRect(230, 460, 80, 21));
184  _textLabel6->setText("krayls");
185 
186  _pushButton1 = new QPushButton(_frame6);
187  _pushButton1->setGeometry(QRect(90, 500, 80, 30));
188  _pushButton1->setText(TR("id_ok_btn"));
189  _pushButton1->setDefault(true);
190 
191  _pushButton2 = new QPushButton(_frame6);
192  _pushButton2->setGeometry(QRect(180, 500, 80, 30));
193  _pushButton2->setText(TR("id_cancel_btn"));
194 
195  // Slider and scale
196  _slider1 = new QSlider(_frame6);
197  _slider1->setGeometry(QRect(170, 40, 30, 381));
198  _slider1->setOrientation(Qt::Vertical);
199  _slider1->setTickPosition(QSlider::TicksRight);
200  _slider1->setTickInterval(9);
201  _slider1->setTracking(false);
202 
203  QWidget* privateLayoutWidget = new QWidget(_frame6);
204  privateLayoutWidget->setGeometry(QRect(200, 25, 60, 410));
205 
206  _layout1 = new QVBoxLayout();
207  privateLayoutWidget->setLayout(_layout1);
208 
209  _textLabel4 = new QLabel(privateLayoutWidget);
210  _textLabel4->setText("20000");
211  _layout1->addWidget(_textLabel4);
212 
213  _textLabel4_2 = new QLabel(privateLayoutWidget);
214  _textLabel4_2->setText("10000");
215  _layout1->addWidget(_textLabel4_2);
216 
217  _textLabel4_3 = new QLabel(privateLayoutWidget);
218  _textLabel4_3->setText("5000");
219  _layout1->addWidget(_textLabel4_3);
220 
221  _textLabel4_4 = new QLabel(privateLayoutWidget);
222  _textLabel4_4->setText("2000");
223  _layout1->addWidget(_textLabel4_4);
224 
225  _textLabel4_5 = new QLabel(privateLayoutWidget);
226  _textLabel4_5->setText("1000");
227  _layout1->addWidget(_textLabel4_5);
228 
229  _textLabel4_6 = new QLabel(privateLayoutWidget);
230  _textLabel4_6->setText("500");
231  _layout1->addWidget(_textLabel4_6);
232 
233  _textLabel4_7 = new QLabel(privateLayoutWidget);
234  _textLabel4_7->setText("200");
235  _layout1->addWidget(_textLabel4_7);
236 
237  _textLabel4_8 = new QLabel(privateLayoutWidget);
238  _textLabel4_8->setText("100");
239  _layout1->addWidget(_textLabel4_8);
240 
241  _textLabel4_9 = new QLabel(privateLayoutWidget);
242  _textLabel4_9->setText("50");
243  _layout1->addWidget(_textLabel4_9);
244 
245  _textLabel4_10 = new QLabel(privateLayoutWidget);
246  _textLabel4_10->setText("20");
247  _layout1->addWidget(_textLabel4_10);
248 
249  _textLabel4_11 = new QLabel(privateLayoutWidget);
250  _textLabel4_11->setText("10");
251  _layout1->addWidget(_textLabel4_11);
252 
253  _textLabel4_12 = new QLabel(privateLayoutWidget);
254  _textLabel4_12->setText("5");
255  _layout1->addWidget(_textLabel4_12);
256 
257  // ToolButtons
258  _pButtonGroup = new QButtonGroup(_frame6);
259 
260  _toolButton1 = new QToolButton(_frame6);
261  _toolButton1->setGeometry(QRect(10, 406, 20, 20));
262  QColor color(225, 255, 255);
263  _toolButton1->setStyleSheet(QString("background-color: %1;").arg(color.name()));
264  _toolButton1->setToolButtonStyle(Qt::ToolButtonTextOnly);
265  _pButtonGroup->addButton(_toolButton1, 0);
266 
267  _toolButton1_8_3 = new QToolButton(_frame6);
268  _toolButton1_8_3->setGeometry(QRect(10, 336, 20, 20));
269  color = QColor(225, 221, 213);
270  _toolButton1_8_3->setStyleSheet(QString("background-color: %1;").arg(color.name()));
271  _toolButton1_8_3->setToolButtonStyle(Qt::ToolButtonTextOnly);
272  _pButtonGroup->addButton(_toolButton1_8_3, 4);
273 
274  _toolButton1_8_2 = new QToolButton(_frame6);
275  _toolButton1_8_2->setGeometry(QRect(10, 316, 20, 20));
276  color = QColor(170, 170, 127);
277  _toolButton1_8_2->setStyleSheet(QString("background-color: %1;").arg(color.name()));
278  _toolButton1_8_2->setToolButtonStyle(Qt::ToolButtonTextOnly);
279  _pButtonGroup->addButton(_toolButton1_8_2, 8);
280 
281  _toolButton1_8 = new QToolButton(_frame6);
282  _toolButton1_8->setGeometry(QRect(10, 255, 20, 20));
283  color = QColor(0, 218, 0);
284  _toolButton1_8->setStyleSheet(QString("background-color: %1;").arg(color.name()));
285  _toolButton1_8->setToolButtonStyle(Qt::ToolButtonTextOnly);
286  _pButtonGroup->addButton(_toolButton1_8, 6);
287 
288  _toolButton1_8_4 = new QToolButton(_frame6);
289  _toolButton1_8_4->setGeometry(QRect(10, 226, 20, 20));
290  color = QColor(0, 124, 0);
291  _toolButton1_8_4->setStyleSheet(QString("background-color: %1;").arg(color.name()));
292  _toolButton1_8_4->setToolButtonStyle(Qt::ToolButtonTextOnly);
293  _pButtonGroup->addButton(_toolButton1_8_4, 1);
294 
295  _toolButton1_8_5 = new QToolButton(_frame6);
296  _toolButton1_8_5->setGeometry(QRect(10, 196, 20, 20));
297  color = QColor(224, 229, 66);
298  _toolButton1_8_5->setStyleSheet(QString("background-color: %1;").arg(color.name()));
299  _toolButton1_8_5->setToolButtonStyle(Qt::ToolButtonTextOnly);
300  _pButtonGroup->addButton(_toolButton1_8_5, 3);
301 
302  _toolButton1_8_6 = new QToolButton(_frame6);
303  _toolButton1_8_6->setGeometry(QRect(10, 166, 20, 20));
304  color = QColor(226, 191, 34);
305  _toolButton1_8_6->setStyleSheet(QString("background-color: %1;").arg(color.name()));
306  _toolButton1_8_6->setToolButtonStyle(Qt::ToolButtonTextOnly);
307  _pButtonGroup->addButton(_toolButton1_8_6, 2);
308 
309  _toolButton1_8_7 = new QToolButton(_frame6);
310  _toolButton1_8_7->setGeometry(QRect(10, 96, 20, 20));
311  color = QColor(111, 70, 32);
312  _toolButton1_8_7->setStyleSheet(QString("background-color: %1;").arg(color.name()));
313  _toolButton1_8_7->setToolButtonStyle(Qt::ToolButtonTextOnly);
314  _pButtonGroup->addButton(_toolButton1_8_7, 9);
315 
316  _toolButton1_8_11 = new QToolButton(_frame6);
317  _toolButton1_8_11->setGeometry(QRect(10, 76, 20, 20));
318  color = QColor(169, 194, 212);
319  _toolButton1_8_11->setStyleSheet(QString("background-color: %1;").arg(color.name()));
320  _toolButton1_8_11->setToolButtonStyle(Qt::ToolButtonTextOnly);
321  _pButtonGroup->addButton(_toolButton1_8_11, 5);
322 
323  _toolButton1_8_13 = new QToolButton(_frame6);
324  _toolButton1_8_13->setGeometry(QRect(10, 36, 20, 20));
325  color = QColor(146, 168, 184);
326  _toolButton1_8_13->setStyleSheet(QString("background-color: %1;").arg(color.name()));
327  _toolButton1_8_13->setToolButtonStyle(Qt::ToolButtonTextOnly);
328  _pButtonGroup->addButton(_toolButton1_8_13, 7);
329 
330  // Disambiguate the overloaded signal QButtonGroup::buttonClicked
331  void (QButtonGroup::*_qButtonGroup_clicked)(int) = &QButtonGroup::idClicked;
332 
333  connect(_slider1, &QSlider::valueChanged, this, &TYSolResistanceDialog::sliderChanged);
334  connect(_lineEdit1, &QLineEdit::textChanged, this, &TYSolResistanceDialog::lineEditChanged);
335  connect(_pushButton1, &QPushButton::clicked, this, &TYSolResistanceDialog::accept);
336  connect(_pushButton2, &QPushButton::clicked, this, &TYSolResistanceDialog::reject);
337  connect(_pButtonGroup, _qButtonGroup_clicked, this, &TYSolResistanceDialog::buttonValue);
338 
339  _mode = 1;
340  QString qString;
341  _lineEdit1->setText(qString.setNum(_res));
342  _mode = 0;
343 }
344 
345 /*
346  * Destroys the object and frees any allocated resources
347  */
349 {
350  // no need to delete child widgets, Qt does it all for us
351 }
352 
354 {
355  if (_mode == 0)
356  {
357  double val = double(value) / 9;
358  int i = int(val);
359  _res = resistance[i] + (val - double(i)) * (resistance[i + 1] - resistance[i]);
360  QString qString;
361  _lineEdit1->setText(qString.setNum(_res));
362  }
363 
364  _mode = 0;
365 }
366 
367 void TYSolResistanceDialog::lineEditChanged(const QString& sValue)
368 {
369  if (_mode == 1)
370  {
371  int i = 0;
372  double value = sValue.toDouble();
373  _res = value;
374  while ((value > resistance[i + 1]) && (i < 12))
375  {
376  i++;
377  }
378 
379  if (i == 12)
380  {
381  _slider1->setValue(100);
382  }
383  else
384  {
385  double res = (i + (value - resistance[i]) / (resistance[i + 1] - resistance[i])) * 9;
386  _slider1->setValue(int(res));
387  }
388  }
389 
390  _mode = 1;
391 }
392 
394 {
395  switch (button)
396  {
397  case 0:
398  _res = 5.55;
399  _lineEdit1->setText(QString().setNum(_res));
400  break;
401  case 4:
402  _res = 26.66;
403  _lineEdit1->setText(QString().setNum(_res));
404  break;
405  case 8:
406  _res = 45;
407  _lineEdit1->setText(QString().setNum(_res));
408  break;
409  case 6:
410  _res = 156;
411  _lineEdit1->setText(QString().setNum(_res));
412  break;
413  case 1:
414  _res = 350;
415  _lineEdit1->setText(QString().setNum(_res));
416  break;
417  case 3:
418  _res = 666;
419  _lineEdit1->setText(QString().setNum(_res));
420  break;
421  case 2:
422  _res = 1300;
423  _lineEdit1->setText(QString().setNum(_res));
424  break;
425  case 9:
426  _res = 6666;
427  _lineEdit1->setText(QString().setNum(_res));
428  break;
429  case 5:
430  _res = 9500;
431  _lineEdit1->setText(QString().setNum(_res));
432  break;
433  case 7:
434  _res = 20000;
435  _lineEdit1->setText(QString().setNum(_res));
436  break;
437  }
438  lineEditChanged(_lineEdit1->text());
439 }
outil IHM pour l'objet ColorInterface (fichier header)
outil IHM pour une entrée utilisateur (fichier header)
const char * name
#define TR(id)
Outil IHM pour la saisie de la resisitivite du sol (fichier header)
TYSolResistanceDialog(QWidget *parent=0, double res=0, const char *name=0, bool modal=false, Qt::WindowFlags fl=QFlag(0))
void lineEditChanged(const QString &sValue)