tank.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "qt/input/tank.hpp"
  2. QtInputTank::QtInputTank(QtInputData* d,Tank* t):QFrame(){
  3. data=d;
  4. if(t==nullptr){
  5. tank=data->addTank();
  6. }
  7. else{
  8. tank=t;
  9. }
  10. saturation_widget=new QWidget;
  11. left_right_widget=new QWidget;
  12. bottom_top_widget=new QWidget;
  13. main_layout=new QVBoxLayout;
  14. saturation_layout=new QHBoxLayout;
  15. left_right_layout=new QHBoxLayout;
  16. bottom_top_layout=new QHBoxLayout;
  17. saturation_label=new QLabel("Saturation: ");
  18. saturation_input=new QLineEdit();
  19. saturation_layout->addWidget(saturation_label);
  20. saturation_layout->addWidget(saturation_input);
  21. saturation_widget->setLayout(saturation_layout);
  22. left_label=new QLabel("Left: ");
  23. delta_left_label=new QLabel(" Left delta: ");
  24. left_input=new QLineEdit();
  25. delta_left_input=new QLineEdit();
  26. right_label=new QLabel(" Right: ");
  27. delta_right_label=new QLabel(" Right delta: ");
  28. right_input=new QLineEdit();
  29. delta_right_input=new QLineEdit();
  30. left_right_layout->addWidget(left_label);
  31. left_right_layout->addWidget(left_input,1);
  32. left_right_layout->addWidget(delta_left_label);
  33. left_right_layout->addWidget(delta_left_input,1);
  34. left_right_layout->addWidget(right_label);
  35. left_right_layout->addWidget(right_input,1);
  36. left_right_layout->addWidget(delta_right_label);
  37. left_right_layout->addWidget(delta_right_input,1);
  38. left_right_widget->setLayout(left_right_layout);
  39. bottom_label=new QLabel("Bottom: ");
  40. delta_bottom_label=new QLabel(" Bottom delta: ");
  41. bottom_input=new QLineEdit();
  42. delta_bottom_input=new QLineEdit();
  43. top_label=new QLabel(" Top: ");
  44. delta_top_label=new QLabel(" Top delta: ");
  45. top_input=new QLineEdit();
  46. delta_top_input=new QLineEdit();
  47. bottom_top_layout->addWidget(bottom_label);
  48. bottom_top_layout->addWidget(bottom_input,1);
  49. bottom_top_layout->addWidget(delta_bottom_label);
  50. bottom_top_layout->addWidget(delta_bottom_input,1);
  51. bottom_top_layout->addWidget(top_label);
  52. bottom_top_layout->addWidget(top_input,1);
  53. bottom_top_layout->addWidget(delta_top_label);
  54. bottom_top_layout->addWidget(delta_top_input,1);
  55. bottom_top_widget->setLayout(bottom_top_layout);
  56. remove_button=new QPushButton("Remove",this);
  57. main_layout->addWidget(saturation_widget);
  58. main_layout->addWidget(left_right_widget);
  59. main_layout->addWidget(bottom_top_widget);
  60. main_layout->addWidget(remove_button);
  61. double_validator=new QDoubleValidator;
  62. double_validator->setBottom(0);
  63. double_validator->setTop(1);
  64. saturation_input->setValidator(double_validator);
  65. left_input->setValidator(double_validator);
  66. right_input->setValidator(double_validator);
  67. bottom_input->setValidator(double_validator);
  68. top_input->setValidator(double_validator);
  69. delta_left_input->setValidator(double_validator);
  70. delta_right_input->setValidator(double_validator);
  71. delta_bottom_input->setValidator(double_validator);
  72. delta_top_input->setValidator(double_validator);
  73. setLayout(main_layout);
  74. setFrameShape(QFrame::Box);
  75. connect(remove_button,&QPushButton::clicked,this,&QtInputTank::emitRemove);
  76. if(t==nullptr){
  77. tank->bottom*=data->factor;
  78. tank->top*=data->factor;
  79. tank->delta_bottom*=data->factor;
  80. tank->delta_top*=data->factor;
  81. }
  82. getTank();
  83. }
  84. QWidget*
  85. QtInputTank::validate(){
  86. if(not saturation_input->hasAcceptableInput()) return saturation_input;
  87. if(not left_input->hasAcceptableInput()) return left_input;
  88. if(not right_input->hasAcceptableInput()) return right_input;
  89. if(not bottom_input->hasAcceptableInput()) return bottom_input;
  90. if(not top_input->hasAcceptableInput()) return top_input;
  91. if(not delta_left_input->hasAcceptableInput()) return delta_left_input;
  92. if(not delta_right_input->hasAcceptableInput()) return delta_right_input;
  93. if(not delta_bottom_input->hasAcceptableInput()) return delta_bottom_input;
  94. if(not delta_top_input->hasAcceptableInput()) return delta_top_input;
  95. double l,r,t,b;
  96. l=left_input->text().toDouble();
  97. r=right_input->text().toDouble();
  98. t=top_input->text().toDouble();
  99. b=bottom_input->text().toDouble();
  100. if(l>=r) return right_input;
  101. if(b>=t) return top_input;
  102. setTank();
  103. return nullptr;
  104. }
  105. void
  106. QtInputTank::setTank(){
  107. double s,l,r,t,b,sl,sr,st,sb;
  108. s=saturation_input->text().toDouble();
  109. l=left_input->text().toDouble();
  110. r=right_input->text().toDouble();
  111. t=top_input->text().toDouble();
  112. b=bottom_input->text().toDouble();
  113. sl=delta_left_input->text().toDouble();
  114. sr=delta_right_input->text().toDouble();
  115. st=delta_top_input->text().toDouble();
  116. sb=delta_bottom_input->text().toDouble();
  117. tank->saturation=s;
  118. tank->left=l;
  119. tank->right=r;
  120. tank->bottom=b*data->factor;
  121. tank->top=t*data->factor;
  122. tank->delta_left=sl;
  123. tank->delta_right=sr;
  124. tank->delta_bottom=sb*data->factor;
  125. tank->delta_top=st*data->factor;
  126. }
  127. void
  128. QtInputTank::getTank(){
  129. double factor_inv=1/data->factor;
  130. saturation_input->setText(QString::number(tank->saturation));
  131. left_input->setText(QString::number(tank->left));
  132. right_input->setText(QString::number(tank->right));
  133. top_input->setText(QString::number(tank->top*factor_inv));
  134. bottom_input->setText(QString::number(tank->bottom*factor_inv));
  135. delta_left_input->setText(QString::number(tank->delta_left));
  136. delta_right_input->setText(QString::number(tank->delta_right));
  137. delta_top_input->setText(QString::number(tank->delta_top*factor_inv));
  138. delta_bottom_input->setText(QString::number(tank->delta_bottom*factor_inv));
  139. }