Almond.cpp 2.4 KB

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