Nessuna descrizione

mainwindow.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /// \file
  2. // RAN - 2014/06/10 : Clear the textEdit control image is loaded.
  3. #include "mainwindow.h"
  4. #include "ui_mainwindow.h"
  5. #include <QtDebug>
  6. #include <QLabel>
  7. #include "steganography.h"
  8. /// \fn StegaPanel::StegaPanel(QWidget *parent)
  9. /// \~English
  10. /// \brief GUI Constructor
  11. /// \~Spanish
  12. /// \brief Constructor del GUI
  13. StegaPanel::StegaPanel(QWidget *parent) :
  14. QMainWindow(parent),
  15. ui(new Ui::StegaPanel)
  16. {
  17. ui->setupUi(this); //
  18. }
  19. /// \fn void StegaPanel::hideMessage()
  20. /// \~English
  21. /// \brief Function that calls the message embedding function.
  22. /// \~Spanish
  23. /// \brief Funcion que llama la funcion de embedir el mensaje.
  24. ///
  25. void StegaPanel::hideMessage()
  26. {
  27. string binMsg ; // Will be used to store the message in a binary String format
  28. ui->error_msg_label->clear(); //clear error text
  29. orig_msg = ui->textEdit->toPlainText(); //obtain msg from textEdit
  30. if(old_image.isNull()){
  31. qDebug() << "Load an image first!";
  32. ui->error_msg_label->setText("NO IMAGE LOADED!");
  33. }
  34. else if (orig_msg == NULL){
  35. ui->error_msg_label->setText("No message to hide!");
  36. }
  37. else{
  38. binMsg = messageToBinaryString(orig_msg.toStdString()) ;
  39. if(((old_image.width() * old_image.height()) * 3) < (int)binMsg.length())
  40. {
  41. ui->error_msg_label->setText("IMAGE NOT BIG ENOUGH FOR MESSAGE!");
  42. }
  43. else
  44. {
  45. EmbbedMessage(old_image, new_image, orig_msg.toStdString()) ;
  46. }
  47. ui->error_msg_label->setText("Message hidden in Stego Image with 1 stego bits.");
  48. }
  49. }
  50. /// \fn void StegaPanel::revealMessage()
  51. /// \~English
  52. /// \brief Function that calls the message extraction function.
  53. /// \~Spanish
  54. /// \brief Funcion que llama la funcion de extraer el mensaje.
  55. ///
  56. void StegaPanel::revealMessage()
  57. {
  58. string msg = ExtractMessage(new_image) ;
  59. if (msg.length() > 0){
  60. ui->textEdit->setText(QString::fromStdString(msg));
  61. ui->error_msg_label->setText("Message extracted!");
  62. }
  63. else{
  64. ui->error_msg_label->setText("Could not extract message!");
  65. }
  66. }
  67. /// \fn void StegaPanel::on_loadImage_clicked()
  68. /// \~English
  69. /// \brief Event function to load an image from the
  70. /// file system.
  71. /// \~Spanish
  72. /// \brief Funcion de evento que carga una imagen de el
  73. /// sistema de archivos.
  74. ///
  75. void StegaPanel::on_loadImage_clicked()
  76. {
  77. QString fname = QFileDialog::getOpenFileName(this, tr("Choose an image"), QDir::homePath());
  78. if (!fname.isEmpty()){
  79. QImage image(fname);
  80. if (image.isNull())
  81. QMessageBox::information(this, tr("Choose an image"),tr("Cannot load %1.").arg(fname));
  82. old_image=image;
  83. new_image=image;
  84. repaint();
  85. }
  86. ui->old_image->setPixmap(QPixmap::fromImage(old_image));
  87. ui->new_image->setPixmap(QPixmap::fromImage(new_image));
  88. ui->textEdit->setText("");
  89. ui->error_msg_label->setText("Image loaded!");
  90. }
  91. /// \fn void StegaPanel::on_hideMessage_clicked()
  92. /// \~English
  93. /// \brief Event function to hide message into
  94. /// the image.
  95. /// \~Spanish
  96. /// \brief Funcion de evento para esconder e
  97. /// el mensaje en la imagen.
  98. ///
  99. void StegaPanel::on_hideMessage_clicked()
  100. {
  101. hideMessage();
  102. ui->new_image->setPixmap(QPixmap::fromImage(new_image));
  103. }
  104. /// \fn void StegaPanel::on_getMessage_clicked()
  105. /// \~English
  106. /// \brief Event function to extract the message hidden
  107. /// in the image.
  108. /// \~Spanish
  109. /// \brief Funcion de evento para estraer el mensaje
  110. /// escondido en la imagen.
  111. ///
  112. void StegaPanel::on_getMessage_clicked()
  113. {
  114. revealMessage();
  115. }
  116. /// \fn StegaPanel::~StegaPanel()
  117. /// \~English
  118. /// \brief GUI Destructor
  119. /// \~Spanish
  120. /// \brief Destructor del GUI
  121. StegaPanel::~StegaPanel()
  122. {
  123. delete ui;
  124. }
  125. /// \fn void StegaPanel::on_storeImage_clicked()
  126. /// \~English
  127. /// \brief on_storeImage_clicked - Event function to save the new image in the
  128. /// file system.
  129. /// \~Spanish
  130. /// \brief Funcion de evento para salvar la imagen nueva
  131. /// en el sistema de archivos.
  132. ///
  133. void StegaPanel::on_storeImage_clicked()
  134. {
  135. QPixmap out = QPixmap::grabWidget(this,361,10,481,481);
  136. QString fname = QFileDialog::getSaveFileName(this, tr("Save Edited Image"), (""), tr("PNG (*.png)" ));
  137. new_image.save(fname, "PNG");
  138. ui->error_msg_label->setText("Image saved to" + fname + " !");
  139. }