Ei kuvausta

mainwindow.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /// \file
  2. #include "mainwindow.h"
  3. #include "ui_mainwindow.h"
  4. #include <QtDebug>
  5. #include <QLabel>
  6. #include "steganography.h"
  7. StegaPanel::StegaPanel(QWidget *parent) :
  8. QMainWindow(parent),
  9. ui(new Ui::StegaPanel)
  10. {
  11. ui->setupUi(this);
  12. }
  13. void StegaPanel::hideMessage()
  14. {
  15. ///~English
  16. /// Will be used to store the message in a binary string format
  17. ///~Spanish
  18. /// Se usara para almacenar el mensaje en un formato de caracteres binario
  19. string binMsg ;
  20. ///~English
  21. /// clear error text
  22. ///~Spanish
  23. /// despejar mensaje de error
  24. ui->error_msg_label->clear();
  25. ///~English
  26. /// obtain message from textEdit
  27. ///~Spanish
  28. /// obtener el mensaje de textEdit
  29. orig_msg = ui->textEdit->toPlainText();
  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. void StegaPanel::revealMessage()
  51. {
  52. string msg = ExtractMessage(new_image) ;
  53. if (msg.length() > 0){
  54. ui->textEdit->setText(QString::fromStdString(msg));
  55. ui->error_msg_label->setText("Message extracted!");
  56. }
  57. else{
  58. ui->error_msg_label->setText("Could not extract message!");
  59. }
  60. }
  61. void StegaPanel::on_loadImage_clicked()
  62. {
  63. QString fname = QFileDialog::getOpenFileName(this, tr("Choose an image"), QDir::homePath());
  64. if (!fname.isEmpty()){
  65. QImage image(fname);
  66. if (image.isNull())
  67. QMessageBox::information(this, tr("Choose an image"),tr("Cannot load %1.").arg(fname));
  68. old_image=image;
  69. new_image=image;
  70. repaint();
  71. }
  72. ui->old_image->setPixmap(QPixmap::fromImage(old_image));
  73. ui->new_image->setPixmap(QPixmap::fromImage(new_image));
  74. ui->textEdit->setText("");
  75. ui->error_msg_label->setText("Image loaded!");
  76. }
  77. void StegaPanel::on_hideMessage_clicked()
  78. {
  79. hideMessage();
  80. ui->new_image->setPixmap(QPixmap::fromImage(new_image));
  81. }
  82. void StegaPanel::on_getMessage_clicked()
  83. {
  84. revealMessage();
  85. }
  86. StegaPanel::~StegaPanel()
  87. {
  88. delete ui;
  89. }
  90. void StegaPanel::on_storeImage_clicked()
  91. {
  92. QPixmap out = QPixmap::grabWidget(this,361,10,481,481);
  93. QString fname = QFileDialog::getSaveFileName(this, tr("Save Edited Image"), (""), tr("PNG (*.png)" ));
  94. new_image.save(fname, "PNG");
  95. ui->error_msg_label->setText("Image saved to" + fname + " !");
  96. }