Ingen beskrivning

ImageScrambler.cpp 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "ImageScrambler.h"
  2. #include "ui_ImageScrambler.h"
  3. /// \fn ImageScrambler::ImageScrambler(QWidget *parent)
  4. /// \~English
  5. /// \brief Constructor
  6. /// \~Spanish
  7. /// \brief Constructor
  8. ImageScrambler::ImageScrambler(QWidget *parent) :
  9. QMainWindow(parent),
  10. ui(new Ui::ImageScrambler)
  11. {
  12. ui->setupUi(this);
  13. scrambleDepth = 1 ;
  14. // KEYBOARD SHORTCUTS
  15. // ATAJOS DEL KEYBOARD
  16. // Loads a image with cmd + o
  17. // Carga una imagen con cmd + o
  18. new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_O), this, SLOT(on_btnLoadNewImage_clicked()));
  19. // Saves a image with cmd + s
  20. // Guarda una imagen con cmd + s
  21. new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this, SLOT(on_btnSave_clicked()));
  22. // Closes window with cmd + w
  23. // Cierra la ventana con cmd + w
  24. new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(close()));
  25. // Scramble a image with cmd + e
  26. // Revuelve una imagen con cmd + e
  27. new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_E), this, SLOT(on_btnScrambleImage_clicked()));
  28. // Restore the image with cmd + d
  29. // Restaura la imagen con cmd + d
  30. new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_D), this, SLOT(on_btnDescrambleImage_clicked()));
  31. ui->btnDescrambleImage->setEnabled(false);
  32. }
  33. /// \fn ImageScrambler::~ImageScrambler(QWidget *parent)
  34. /// \~English
  35. /// \brief Destructor
  36. /// \~Spanish
  37. /// \brief Destructor
  38. ImageScrambler::~ImageScrambler()
  39. {
  40. delete ui;
  41. }
  42. /// \fn void ImageScrambler::on_btnLoadNewImage_clicked()
  43. /// \~English
  44. /// \brief Function display a file browsing window to load an image into the GUI
  45. /// \~Spanish
  46. /// \brief Funcion que despliega una ventana de busqueda de archivos para cargar
  47. /// una imagen en el GUI.
  48. void ImageScrambler::on_btnLoadNewImage_clicked(){
  49. QString fname = QFileDialog::getOpenFileName(this, tr("Choose an image"), QDir::homePath());
  50. if (!fname.isEmpty()){
  51. QImage image(fname);
  52. if (image.isNull())
  53. QMessageBox::information(this, tr("Choose an image"),tr("Cannot load %1.").arg(fname));
  54. originalImage=image;
  55. scrambledImage=image;
  56. ui->lblOriginalImage->setPixmap(QPixmap::fromImage(originalImage));
  57. ui->lblScrambleImage->setPixmap(QPixmap::fromImage(scrambledImage));
  58. ui->btnDescrambleImage->setEnabled(false);
  59. }
  60. }
  61. /// \fn void ImageScrambler::on_btnSave_clicked()
  62. /// \~English
  63. /// \brief Function that saves the scrambled image in the computer.
  64. /// \~Spanish
  65. /// \brief Funcion que guarda la imagen revuelta en la computadora.
  66. void ImageScrambler::on_btnSave_clicked(){
  67. QPixmap out = QPixmap::grabWidget(this,361,10,481,481);
  68. QString fname = QFileDialog::getSaveFileName(this, tr("Save Edited Image"), (""), tr("PNG (*.png)" ));
  69. scrambledImage.save(fname, "PNG");
  70. }
  71. /// \fn void ImageScrambler::on_btnScrambleImage_clicked()
  72. /// \~English
  73. /// \brief Function invokes the ScrambleFilter function to scramble the image and
  74. /// load it in the GUI.
  75. /// \~Spanish
  76. /// \brief Funcion que invoca la funcion ScrambleFilter para revolver la imagen y
  77. /// cargarla en el GUI.
  78. void ImageScrambler::on_btnScrambleImage_clicked(){
  79. //Call Scramble to scramble the image
  80. scrambleDepth = ui->scrambleDepth->value() ;
  81. scrambledImage = ScrambleFilter(originalImage, scrambleDepth, 0, 0, originalImage.width(),originalImage.height());
  82. ui->lblScrambleImage->setPixmap(QPixmap::fromImage(scrambledImage));
  83. ui->btnDescrambleImage->setEnabled(true);
  84. }
  85. /// \fn void ImageScrambler::on_btnDescrambleImage_clicked()
  86. /// \~English
  87. /// \brief Function that restore the scrambled image to the original image.
  88. /// \~Spanish
  89. /// \brief Funcion que restaura la imagen revuelta a la imagen original.
  90. void ImageScrambler::on_btnDescrambleImage_clicked(){
  91. scrambledImage = originalImage;
  92. ui->lblScrambleImage->setPixmap(QPixmap::fromImage(scrambledImage));
  93. }
  94. /// \fn void ImageScrambler::on_actionLoad_Image_triggered()
  95. /// \~English
  96. /// \brief Function that invokes the on_btnLoadNewImage_clicked() function.
  97. /// \~Spanish
  98. /// \brief Funcion que invoca la funcion on_btnLoadNewImage_clicked().
  99. void ImageScrambler::on_actionLoad_Image_triggered(){
  100. on_btnLoadNewImage_clicked();
  101. }
  102. /// \fn void ImageScrambler::on_actionSave_Image_triggered()
  103. /// \~English
  104. /// \brief Function that invokes the on_btnSave_clicked() function.
  105. /// \~Spanish
  106. /// \brief Funcion que invoca la funcion on_btnSave_clicked().
  107. void ImageScrambler::on_actionSave_Image_triggered(){
  108. on_btnSave_clicked();
  109. }
  110. /// \fn void ImageScrambler::on_actionScramble_Image_triggered()
  111. /// \~English
  112. /// \brief Function that invokes the on_btnScrambleImage_clicked() function.
  113. /// \~Spanish
  114. /// \brief Funcion que invoca la funcion on_btnScrambleImage_clicked().
  115. void ImageScrambler::on_actionScramble_Image_triggered(){
  116. on_btnScrambleImage_clicked();
  117. }
  118. /// \fn void ImageScrambler::on_actionDescramble_Image_triggered()
  119. /// \~English
  120. /// \brief Function that invokes the on_btnDescrambleImage_clicked() function.
  121. /// \~Spanish
  122. /// \brief Funcion que invoca la funcion on_btnDescrambleImage_clicked().
  123. void ImageScrambler::on_actionDescramble_Image_triggered(){
  124. on_btnDescrambleImage_clicked();
  125. }