Almond.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "Almond.h"
  2. #include <QIntValidator>
  3. #include <QFileDialog>
  4. #include <QMessageBox>
  5. #include "benchmarkdialog.h"
  6. Almond::Almond(QWidget *parent) :
  7. QMainWindow(parent)
  8. {
  9. ui.setupUi(this);
  10. printf("not yet created!\n");
  11. mw = std::make_unique<MandelWidget>(ui.centralWidget);
  12. printf("created!\n");
  13. ui.verticalLayout_left->addWidget(mw.get());
  14. //ui.verticalLayout_left->addWidget(new MyGLWidget(ui.centralWidget));
  15. //mw->show();
  16. }
  17. void Almond::on_pushButton_clicked()
  18. {
  19. ExportImageDialog dialog(this);
  20. auto response = dialog.exec();
  21. if (response == 1) {
  22. MandelInfo mi;
  23. mi.maxIter = dialog.getMaxIterations();
  24. mi.view = mw->getViewport();
  25. mi.bWidth = dialog.getWidth();
  26. mi.bHeight = dialog.getHeight();
  27. mi.view.adjustAspectRatio(mi.bWidth, mi.bHeight);
  28. CpuGenerator<double> cpg;
  29. auto bitmap = cpg.generate(mi);
  30. QImage img((unsigned char*)bitmap.pixels.get(), bitmap.width, bitmap.height, bitmap.width * 3, QImage::Format_RGB888);
  31. img.save(dialog.getPath());
  32. }
  33. }
  34. ExportImageDialog::ExportImageDialog(QWidget* parent) :
  35. QDialog{ parent }
  36. {
  37. eid.setupUi(this);
  38. eid.maxIterations->setValidator(new QIntValidator(1, 10000000, this));
  39. eid.imgWidth->setValidator(new QIntValidator(1, 10000000, this));
  40. eid.imgHeight->setValidator(new QIntValidator(1, 10000000, this));
  41. }
  42. int ExportImageDialog::getMaxIterations(void) const
  43. {
  44. return std::stoi(eid.maxIterations->text().toStdString());
  45. }
  46. int ExportImageDialog::getWidth(void) const
  47. {
  48. return std::stoi(eid.imgWidth->text().toStdString());
  49. }
  50. int ExportImageDialog::getHeight(void) const
  51. {
  52. return std::stoi(eid.imgHeight->text().toStdString());
  53. }
  54. QString ExportImageDialog::getPath(void) const
  55. {
  56. return eid.savePath->text();
  57. }
  58. void ExportImageDialog::on_pushButton_clicked()
  59. {
  60. QString saveAs = QFileDialog::getSaveFileName(this,
  61. tr("Save exported image"), "",
  62. tr("PNG image (*.png);;JPEG image (*.jpg);;All Files (*)"));
  63. eid.savePath->setText(saveAs);
  64. this->repaint();
  65. }
  66. void ExportImageDialog::on_buttonBox_accepted()
  67. {
  68. if (eid.savePath->text() == "") {
  69. QMessageBox msgBox;
  70. msgBox.setText("Please specify a path.");
  71. msgBox.exec();
  72. reject();
  73. }
  74. }
  75. void Almond::on_pushButton_2_clicked()
  76. {
  77. BenchmarkDialog bd(this);
  78. bd.exec();
  79. }