123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- // RAN 2015-07-03 - Initialized invertColor variable. Eliminated some unneeeded arguments from
- // the filter functions. Added the convertToFormat(QImage::Format_ARGB32)
- // so that filters work even on images that have a predefined color table.
- // Change the name of the variable color to changeColor.
-
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
-
- /// \fn MainWindow::MainWindow(QWidget *parent)
- /// \~English
- /// \brief Constructor
- /// \~Spanish
- /// \brief Constructor
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- ui->thresholdSlider->setDisabled(true);
- invertColor = false;
- ///
- /// KEYBOARD SHORTCUTS
- /// Loads a image with cmd + o
- /// Carga una imagen con cmd + o
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_O), this, SLOT(on_btnLoadImage_clicked()));
- ///
- /// Saves a image with cmd + s
- /// Guarda una imagen con cmd + s
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this, SLOT(on_btnSaveImage_clicked()));
- ///
- /// Closes window with cmd + w
- /// Cierra la ventana con cmd + w
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(close()));
- ///
- /// Inverts threshold color with cmd + t
- /// Invierte el color umbral con cmd + t
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_T), this, SLOT(on_btnInvertThreshold_clicked()));
- ///
- /// Flips horizontally a image with cmd + f
- /// Rota horizontalmente una imagen con cmd + f
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F), this, SLOT(on_btnFlipImageHorizontally_clicked()));
- ///
- /// Flips vertically a image with cmd + v
- /// Rota verticalmente una imagen con cmd + v
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_V), this, SLOT(on_btnFlipImageVertically_clicked()));
- ///
- /// Applies greyscale filter to a image with cmd + g
- /// Aplica el filtro de tonos grises a una imagen con cmd + g
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_G), this, SLOT(on_btnGreyScaleFilter_clicked()));
- ///
- /// Resets an edited image to the orignal one to a image with cmd + r
- /// Devuelve la imagen editada a su estado original con cmd + r
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_R), this, SLOT(on_btnRevertImage_clicked()));
- ///
- /// Display the instructions with cmd + i
- /// Despliega las instrucciones con cmd + i
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_I), this, SLOT(instructions()));
- }
-
- /// \fn MainWindow::MainWindow(QWidget *parent)
- /// \~English
- /// \brief Destructor
- /// \~Spanish
- /// \brief Destructor
- MainWindow::~MainWindow(){
- delete ui;
- }
-
- ///
- /// ACTION FUNCTIONS
- ///
-
- /// \fn void MainWindow::on_actionLoad_Image_triggered()
- /// \~English
- /// \brief Invokes function on_btnLoadImage_clicked()
- /// \~Spanish
- /// \brief Invoca la funcion on_btnLoadImage_clicked()
- void MainWindow::on_actionLoad_Image_triggered(){
- on_btnLoadImage_clicked();
- }
-
- /// \fn void MainWindow::on_actionSave_Image_triggered()
- /// \~English
- /// \brief Invokes function on_btnSaveImage_clicked()
- /// \~Spanish
- /// \brief Invoca la funcion on_btnSaveImage_clicked()
- void MainWindow::on_actionSave_Image_triggered(){
- on_btnSaveImage_clicked();
- }
-
- /// \fn void MainWindow::on_actionClose_Image_triggered()
- /// \~English
- /// \brief Invokes function close()
- /// \~Spanish
- /// \brief Invoca la funcion close()
- void MainWindow::on_actionClose_Window_triggered(){
- close();
- }
-
- /// \fn void MainWindow::on_actionInvert_Threshold_Colors_triggered()
- /// \~English
- /// \brief Invokes function on_btnInvertThreshold_clicked()
- /// \~Spanish
- /// \brief Invoca la funcion on_btnInvertThreshold_clicked()
- void MainWindow::on_actionInvert_Threshold_Colors_triggered(){
- on_btnInvertThreshold_clicked();
- }
-
- /// \fn void MainWindow::on_actionFlip_Image_Horizontally_triggered()
- /// \~English
- /// \brief Invokes function on_btnFlipImageHorizontally_clicked()
- /// \~Spanish
- /// \brief Invoca la funcion on_btnFlipImageHorizontally_clicked()
- void MainWindow::on_actionFlip_Image_Horizontally_triggered(){
- on_btnFlipImageHorizontally_clicked();
- }
-
- /// \fn void MainWindow::on_actionFlip_Image_Vertically_triggered()
- /// \~English
- /// \brief Invokes function on_btnFlipImageVertically_clicked()
- /// \~Spanish
- /// \brief Invoca la funcion on_btnFlipImageVertically_clicked()
- void MainWindow::on_actionFlip_Image_Vertically_triggered(){
- on_btnFlipImageVertically_clicked();
- }
-
- /// \fn void MainWindow::on_actionApply_Grey_Scale_Filter_triggered()
- /// \~English
- /// \brief Invokes function on_btnGreyScaleFilter_clicked()
- /// \~Spanish
- /// \brief Invoca la funcion on_btnGreyScaleFilter_clicked()
- void MainWindow::on_actionApply_Grey_Scale_Filter_triggered(){
- on_btnGreyScaleFilter_clicked();
- }
-
- /// \fn void MainWindow::on_actionRevert_Edited_Image_to_Original_triggered()
- /// \~English
- /// \brief Invokes function on_btnRevertImage_clicked()
- /// \~Spanish
- /// \brief Invoca la funcion on_btnRevertImage_clicked()
- void MainWindow::on_actionRevert_Edited_Image_to_Original_triggered(){
- on_btnRevertImage_clicked();
- }
-
- /// \fn void MainWindow::on_actionInstructions_triggered()
- /// \~English
- /// \brief To display the instructions.
- /// \~Spanish
- /// \brief Para desplegar las instrucciones.
- void MainWindow::on_actionInstructions_triggered(){
- instructions();
- }
-
- /// \fn void MainWindow::on_chboxThreshold_clicked()
- /// \~English
- /// \brief To apply the threshold filter and load the edited image to the GUI.
- /// \~Spanish
- /// \brief Para aplicar el filtro de umbral y cargar la imagen editada al GUI.
- void MainWindow::on_chboxThreshold_clicked(){
- if (ui->chboxThreshold->isChecked()){
- ui->thresholdSlider->setEnabled(true);
- applyThresholdFilter();
- ui->lblEditedImage->setPixmap(QPixmap::fromImage(editedImage));
- }
- else
- ui->thresholdSlider->setDisabled(true);
- }
-
- /// \fn void MainWindow::applyThresholdFilter()
- /// \~English
- /// \brief To apply the threshold filter.
- /// \~Spanish
- /// \brief Para aplicar el filtro de umbral.
- void MainWindow::applyThresholdFilter(){
- ThresholdFilter(originalImage, editedImage, ui->thresholdSlider->value(), invertColor) ;
- }
-
- /// \fn void MainWindow::on_thresholdSlider_sliderReleased()
- /// \~English
- /// \brief To apply the threshold filter and load the edited image to the GUI when
- /// the GUI slider is moved.
- /// \~Spanish
- /// \brief Para aplicar el filtro de umbral y cargar la imagen editada al GUI cuando
- /// el deslizador del GUI es movido.
- void MainWindow::on_thresholdSlider_sliderReleased(){
- applyThresholdFilter();
- ui->lblEditedImage->setPixmap(QPixmap::fromImage(editedImage));
- }
-
- /// \fn void MainWindow::on_btnInvertThreshold_clicked()
- /// \~English
- /// \brief To apply the threshold filter and load the edited image to the GUI when
- /// the threshold color is inverted.
- /// \~Spanish
- /// \brief Para aplicar el filtro de umbral y cargar la imagen editada al GUI cuando
- /// el color del umbral es invertido.
- void MainWindow::on_btnInvertThreshold_clicked(){
- invertColor = !invertColor;
- if(ui->chboxThreshold->isChecked()){
- applyThresholdFilter();
- ui->lblEditedImage->setPixmap(QPixmap::fromImage(editedImage));
- }
- }
-
- /// \fn void MainWindow::on_btnLoadImage_clicked()
- /// \~English
- /// \brief To load an image to the GUI when the load image option is selected.
- /// \~Spanish
- /// \brief Para cargar una imagen al GUI cuando se marca opcion de cargar imagen.
- void MainWindow::on_btnLoadImage_clicked(){
- QString fname = QFileDialog::getOpenFileName(this, tr("Choose an image"), QDir::homePath());
- if (!fname.isEmpty()){
- QImage image(fname);
- if (image.isNull())
- QMessageBox::information(this, tr("Choose an image"),tr("Cannot load %1.").arg(fname));
- originalImage = image;
- // This ensures that the resulting image accepts all the pixel values that
- // will be accessed using pixel.
- editedImage = image.convertToFormat(QImage::Format_ARGB32);
- }
- ui->lblOriginalImage->setPixmap(QPixmap::fromImage(originalImage));
- ui->lblEditedImage->setPixmap(QPixmap::fromImage(editedImage));
- }
-
- /// \fn void MainWindow::on_btnSaveImage_clicked()
- /// \~English
- /// \brief To save an image to the file system when the save image option is selected.
- /// \~Spanish
- /// \brief Para guardar una imagen al sistema de archivos cuando se marca opcion de guardar imagen.
- void MainWindow::on_btnSaveImage_clicked()
- {
- QPixmap out = QPixmap::grabWidget(this,361,10,481,481);
- QString fname = QFileDialog::getSaveFileName(this, tr("Save Edited Image"), (""), tr("PNG (*.png)" ));
- editedImage.save(fname, "PNG");
- }
-
- /// \fn void MainWindow::on_btnFlipImageHorizontally_clicked()
- /// \~English
- /// \brief To call the horizontal flip image filter.
- /// \~Spanish
- /// \brief Para llamar al filtro de imagen flip horizontal.
- void MainWindow::on_btnFlipImageHorizontally_clicked(){
-
- HorizontalFlip(editedImage) ;
- ui->lblEditedImage->setPixmap(QPixmap::fromImage(editedImage));
- }
-
- /// \fn void MainWindow::on_btnFlipImageVertically_clicked()
- /// \~English
- /// \brief To call the vertical flip image filter.
- /// \~Spanish
- /// \brief Para llamar al filtro de imagen flip vertical.
- void MainWindow::on_btnFlipImageVertically_clicked(){
-
- VerticalFlip(editedImage) ;
- ui->lblEditedImage->setPixmap(QPixmap::fromImage(editedImage));
- }
-
- /// \fn void MainWindow::on_btnGreyScaleFilter_clicked()
- /// \~English
- /// \brief To call the Gray Scale image filter.
- /// \~Spanish
- /// \brief Para llamar al filtro de imagen de escalas grises.
- void MainWindow::on_btnGreyScaleFilter_clicked(){
-
- GrayScale(editedImage) ;
- ui->lblEditedImage->setPixmap(QPixmap::fromImage(editedImage));
- }
-
- /// \fn void MainWindow::on_btnRevertImage_clicked()()
- /// \~English
- /// \brief To reset the edited image to the original image.
- /// \~Spanish
- /// \brief Para reajustar la imagen editada a la imagen original.
- void MainWindow::on_btnRevertImage_clicked(){
- // This ensures that the resulting image accepts all the pixel values that
- // will be accessed using pixel.
- editedImage = originalImage.convertToFormat(QImage::Format_ARGB32);
- ui->lblEditedImage->setPixmap(QPixmap::fromImage(editedImage));
- }
-
- /// \fn void MainWindow::instructions()
- /// \~English
- /// \brief To display the instructions.
- /// \~Spanish
- /// \brief Para desplegar las instrucciones.
- void MainWindow::instructions(){
- QString h[8];
- h[0]="1. Load an image by pressing the \"Load Image\" button, this can also be done from the edit menu or using a keyboard shortcut.";
- h[1]="\n\n2. To apply a greyscale filter to the image click the \"Greyscale Filter\" button, this can also be done from the edit menu or using a keyboard shortcut.";
- h[2]="\n\n3. To apply a threshold filter to the image click the \"Threshold\" check box. If you wish to invert the black and white colors you can press the \"Invert Threshold Colors\" button, this can also be done from the edit menu or using a keyboard shortcut.";
- h[3]=" You can change the value of the threshold with the slider below the check box.";
- h[4]="\n\n4. To flip the image horizontally click the \"Flip Image Horizontally\" button, this can also be done from the edit menu or using a keyboard shortcut.";
- h[5]="\n\n5. To flip the image vertically click the \"Flip Image Horizontally\" button, this can also be done from the edit menu or using a keyboard shortcut.";
- h[6]="\n\n6. If you feel like you did not create a masterpiece, you can revert the image back to original by clicking the button \"Revert Image to Original\", this can also be done from the edit menu or using a keyboard shortcut.";
- h[7]="\n\n7. When you are satisfied with the results you can save the image as a PNG by clicking the button \" Save edited image\", this can also be done from the edit menu or using a keyboard shortcut.";
- QMessageBox mbox;
- mbox.setWindowTitle("How to use the Simple Image Editor");
- mbox.setText(h[0]+h[1]+h[2]+h[3]+h[4]+h[5]+h[6]+h[7]);
- mbox.exec();
- }
|