PageRenderTime 84ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/old_src/specialenrollment.cpp

https://gitlab.com/nyimbi/voter-registration
C++ | 332 lines | 206 code | 103 blank | 23 comment | 24 complexity | 0e4dd3dbc7743a16b50e7968a65beb08 MD5 | raw file
  1. #include "specialenrollment.h"
  2. #include "ui_specialenrollment.h"
  3. #include "QDebug"
  4. #include "QFile"
  5. #include "QMessageBox"
  6. #include "capturephotodialog.h"
  7. #include "QProcess"
  8. #include "QDesktopWidget"
  9. QStringList comboOptions;
  10. QString specialPhotoFile = "photos/special_photo.jpg";
  11. SpecialEnrollment::SpecialEnrollment(QWidget *parent,QString capturableFingers) :
  12. QDialog(parent),
  13. ui(new Ui::SpecialEnrollment)
  14. {
  15. ui->setupUi(this);
  16. comboOptions.clear();
  17. comboOptions << "Scan" << "Skip";
  18. loadFingerOptions();
  19. // ui->btnCapturePhoto->setEnabled(false);
  20. }
  21. //SpecialEnrollment::~SpecialEnrollment()
  22. //{
  23. // delete ui;
  24. //}
  25. void SpecialEnrollment::changeEvent(QEvent *e)
  26. {
  27. QDialog::changeEvent(e);
  28. switch (e->type()) {
  29. case QEvent::LanguageChange:
  30. ui->retranslateUi(this);
  31. break;
  32. default:
  33. break;
  34. }
  35. }
  36. void SpecialEnrollment::loadFingerOptions(){
  37. ui->cmbLeftThumb->addItems(comboOptions);
  38. ui->cmbLeftIndex->addItems(comboOptions);
  39. ui->cmbLeftMiddle->addItems(comboOptions);
  40. ui->cmbLeftRing->addItems(comboOptions);
  41. ui->cmbLeftLittle->addItems(comboOptions);
  42. ui->cmbRightThumb->addItems(comboOptions);
  43. ui->cmbRightIndex->addItems(comboOptions);
  44. ui->cmbRightMiddle->addItems(comboOptions);
  45. ui->cmbRightRing->addItems(comboOptions);
  46. ui->cmbRightLittle->addItems(comboOptions);
  47. }
  48. void SpecialEnrollment::on_btnCancel_clicked()
  49. {
  50. emit(cancelSpecialEnrollment());
  51. this->close();
  52. }
  53. void SpecialEnrollment::on_btnContinue_clicked()
  54. {
  55. //let's validate
  56. QString errorMessages="";
  57. if(ui->txtNotes->toPlainText().isEmpty()) {
  58. errorMessages+="\nPlease enter NOTES to describe why this is a special enrollment";
  59. }
  60. if(ui->cmbGroup->currentText().isEmpty()) {
  61. errorMessages+="\nPlease select a GROUP for this special case";
  62. }
  63. if(!errorMessages.isEmpty()) {
  64. QMessageBox::critical(this,"Incomplete Information",errorMessages);
  65. return;
  66. }
  67. QStringList selectedFingers;
  68. if(ui->cmbLeftThumb->currentIndex()==0) selectedFingers.append("6");
  69. if(ui->cmbLeftIndex->currentIndex()==0) selectedFingers.append("7");
  70. if(ui->cmbLeftMiddle->currentIndex()==0) selectedFingers.append("8");;
  71. if(ui->cmbLeftRing->currentIndex()==0) selectedFingers.append("9");;
  72. if(ui->cmbLeftLittle->currentIndex()==0) selectedFingers.append("10");;
  73. if(ui->cmbRightThumb->currentIndex()==0) selectedFingers.append("1");;
  74. if(ui->cmbRightIndex->currentIndex()==0) selectedFingers.append("2");;
  75. if(ui->cmbRightMiddle->currentIndex()==0) selectedFingers.append("3");;
  76. if(ui->cmbRightRing->currentIndex()==0) selectedFingers.append("4");;
  77. if(ui->cmbRightLittle->currentIndex()==0) selectedFingers.append("5");;
  78. if(selectedFingers.length()==0){
  79. selectedFingers.append("0");
  80. }
  81. qDebug() << selectedFingers;
  82. emit(setFingersToCapture(selectedFingers,ui->txtNotes->toPlainText(),ui->cmbGroup->currentText()));
  83. this->close();
  84. }
  85. void SpecialEnrollment::on_btnReset_clicked()
  86. {
  87. ui->cmbLeftThumb->clear();
  88. ui->cmbLeftIndex->clear();
  89. ui->cmbLeftMiddle->clear();
  90. ui->cmbLeftRing->clear();
  91. ui->cmbLeftLittle->clear();
  92. ui->cmbRightThumb->clear();
  93. ui->cmbRightIndex->clear();
  94. ui->cmbRightMiddle->clear();
  95. ui->cmbRightRing->clear();
  96. ui->cmbRightLittle->clear();
  97. ui->cmbLeftThumb->addItems(comboOptions);
  98. ui->cmbLeftIndex->addItems(comboOptions);
  99. ui->cmbLeftMiddle->addItems(comboOptions);
  100. ui->cmbLeftRing->addItems(comboOptions);
  101. ui->cmbLeftLittle->addItems(comboOptions);
  102. ui->cmbRightThumb->addItems(comboOptions);
  103. ui->cmbRightIndex->addItems(comboOptions);
  104. ui->cmbRightMiddle->addItems(comboOptions);
  105. ui->cmbRightRing->addItems(comboOptions);
  106. ui->cmbRightLittle->addItems(comboOptions);
  107. ui->txtNotes->clear();
  108. }
  109. void SpecialEnrollment::on_btnSkipAll_clicked()
  110. {
  111. ui->cmbLeftThumb->setCurrentIndex(1);
  112. ui->cmbLeftIndex->setCurrentIndex(1);
  113. ui->cmbLeftMiddle->setCurrentIndex(1);
  114. ui->cmbLeftRing->setCurrentIndex(1);
  115. ui->cmbLeftLittle->setCurrentIndex(1);
  116. ui->cmbRightThumb->setCurrentIndex(1);
  117. ui->cmbRightIndex->setCurrentIndex(1);
  118. ui->cmbRightMiddle->setCurrentIndex(1);
  119. ui->cmbRightRing->setCurrentIndex(1);
  120. ui->cmbRightLittle->setCurrentIndex(1);
  121. }
  122. void SpecialEnrollment::on_btnScanAll_clicked()
  123. {
  124. ui->cmbLeftThumb->setCurrentIndex(0);
  125. ui->cmbLeftIndex->setCurrentIndex(0);
  126. ui->cmbLeftMiddle->setCurrentIndex(0);
  127. ui->cmbLeftRing->setCurrentIndex(0);
  128. ui->cmbLeftLittle->setCurrentIndex(0);
  129. ui->cmbRightThumb->setCurrentIndex(0);
  130. ui->cmbRightIndex->setCurrentIndex(0);
  131. ui->cmbRightMiddle->setCurrentIndex(0);
  132. ui->cmbRightRing->setCurrentIndex(0);
  133. ui->cmbRightLittle->setCurrentIndex(0);
  134. }
  135. void SpecialEnrollment::on_btnCapturePhoto_clicked()
  136. {
  137. QProcess *photoProcess = new QProcess();
  138. photoProcess->start("bin/cameraBot");
  139. this->hide();
  140. parentWidget()->hide();
  141. parentWidget()->parentWidget()->hide();
  142. connect(photoProcess, SIGNAL(finished(int)), this, SLOT(finishPhotoCapture(int)));
  143. return;
  144. CapturePhotoDialog *specialCaptureDialog = new CapturePhotoDialog(this,specialPhotoFile,1);
  145. specialCaptureDialog->show();
  146. if (specialCaptureDialog->exec() != 0){
  147. }
  148. const char *filename=specialPhotoFile.toUtf8().data();
  149. QFile fileReader(specialPhotoFile);
  150. if (fileReader.exists()) {
  151. IplImage* dummy=cvLoadImage(filename,1);
  152. QImage image(QSize(dummy->width,dummy->height),QImage::Format_RGB32);
  153. //Image by OpenCV has 3 channels, we want to make it compatible with QPixMap.
  154. int cvIndex = 0, cvLineStart = 0;
  155. for (int y = 0; y < dummy->height; y++) {
  156. unsigned char red,green,blue;
  157. cvIndex = cvLineStart;
  158. for (int x = 0; x < dummy->width; x++) {
  159. // DO it
  160. red = dummy->imageData[cvIndex+2];
  161. green = dummy->imageData[cvIndex+1];
  162. blue = dummy->imageData[cvIndex+0];
  163. //Modify the QImage
  164. image.setPixel(x,y,qRgb(red, green, blue));
  165. cvIndex += 3;
  166. }
  167. cvLineStart += dummy->widthStep;
  168. }
  169. //Update label and scale image to it.
  170. ui->lblSupEvd->setPixmap(QPixmap::fromImage(image));
  171. ui->lblSupEvd->setScaledContents(true);
  172. // lblPhotoFront->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
  173. // fileReader.open(QFile::ReadOnly);
  174. // frontPhotoHolder = fileReader.readAll();
  175. // fileReader.close();
  176. }
  177. }
  178. void SpecialEnrollment::finishPhotoCapture(int exitCode)
  179. {
  180. QFile photoFile("photos/captured.jpg");
  181. if(photoFile.exists()){
  182. // char filename[100] = "photos/selected_photox.jpg";
  183. char filename[100]="photos/special_photo.jpg";
  184. QString delString;
  185. delString.sprintf("rm -f %s",specialPhotoFile.toUtf8().data());
  186. QProcess::execute(delString);
  187. photoFile.rename("photos/captured.jpg",specialPhotoFile);
  188. QFile fileReader(specialPhotoFile);
  189. if (fileReader.exists()) {
  190. IplImage* dummy=cvLoadImage(filename,1);
  191. QImage image(QSize(dummy->width,dummy->height),QImage::Format_RGB32);
  192. //Image by OpenCV has 3 channels, we want to make it compatible with QPixMap.
  193. int cvIndex = 0, cvLineStart = 0;
  194. for (int y = 0; y < dummy->height; y++) {
  195. unsigned char red,green,blue;
  196. cvIndex = cvLineStart;
  197. for (int x = 0; x < dummy->width; x++) {
  198. // DO it
  199. red = dummy->imageData[cvIndex+2];
  200. green = dummy->imageData[cvIndex+1];
  201. blue = dummy->imageData[cvIndex+0];
  202. //Modify the QImage
  203. image.setPixel(x,y,qRgb(red, green, blue));
  204. cvIndex += 3;
  205. }
  206. cvLineStart += dummy->widthStep;
  207. }
  208. qDebug() << "{her";
  209. //Update label and scale image to it.
  210. ui->lblSupEvd->setPixmap(QPixmap::fromImage(image));
  211. ui->lblSupEvd->setScaledContents(true);
  212. // lblPhotoFront->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
  213. // fileReader.open(QFile::ReadOnly);
  214. // frontPhotoHolder = fileReader.readAll();
  215. // fileReader.close();
  216. }
  217. }
  218. this->setWindowFlags(Qt::Dialog);
  219. QDesktopWidget *xa = QApplication::desktop();
  220. parentWidget()->parentWidget()->setWindowFlags(Qt::Dialog);
  221. parentWidget()->parentWidget()->setGeometry(0,0,xa->screenGeometry().width(),xa->screenGeometry().height());
  222. parentWidget()->parentWidget()->show();
  223. parentWidget()->parentWidget()->showFullScreen();
  224. parentWidget()->setWindowFlags(Qt::Dialog);
  225. parentWidget()->setGeometry(0,0,xa->screenGeometry().width(),xa->screenGeometry().height());
  226. parentWidget()->show();
  227. parentWidget()->showFullScreen();
  228. this->show();
  229. }