Skip to content

Commit

Permalink
added : delete image with Delete key
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharindam committed Feb 25, 2020
1 parent bb94080 commit 6c8d08e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
53 changes: 42 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "filters.h"
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QFileInfo>
#include <QPainter>
#include <QDesktopWidget>
Expand Down Expand Up @@ -63,6 +64,10 @@ Window:: Window()
fxMenu->addAction("White Balance", this, SLOT(whiteBalance()));
fxMenu->addAction("Enhance Colors", this, SLOT(enhanceColors()));
effectsBtn->setMenu(fxMenu);
QAction *delAction = new QAction(this);
delAction->setShortcut(QString("Delete"));
connect(delAction, SIGNAL(triggered()), this, SLOT(deleteFile()));
this->addAction(delAction);
QHBoxLayout *layout = new QHBoxLayout(scrollAreaWidgetContents);
layout->setContentsMargins(0, 0, 0, 0);
canvas = new Canvas(this, scrollArea);
Expand Down Expand Up @@ -214,6 +219,23 @@ Window:: saveACopy() // generate a new filename and save
saveImage(path);
}

void
Window:: deleteFile()
{
QString nextfile = getNextFilename(filename); // must be called before deleting
QFile fi(filename);
if (not fi.exists()) return;
if (QMessageBox::warning(this, "Delete File?", "Are you sure to permanently delete this image?",
QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
return;
if (!fi.remove()) {
QMessageBox::warning(this, "Delete Failed !", "Could not delete the image");
return;
}
if (!nextfile.isNull())
openImage(nextfile);
}

void
Window:: resizeImage()
{
Expand Down Expand Up @@ -392,17 +414,9 @@ Window:: openPrevImage()
void
Window:: openNextImage()
{
QFileInfo fi(filename);
if (not fi.exists()) return;
QString filename = fi.fileName();
QString basedir = fi.absolutePath(); // This does not include filename
QString file_filter("*.jpg *.jpeg *.png *.gif *.svg *.bmp *.tiff");
QStringList image_list = fi.dir().entryList(file_filter.split(" "));

int index = image_list.indexOf(filename);
if (index == image_list.count()-1) index = -1;
QString nextfile = image_list[index+1];
openImage(basedir + '/' + nextfile);
QString nextfile = getNextFilename(filename);
if (!nextfile.isNull())
openImage(nextfile);
}

void
Expand Down Expand Up @@ -610,6 +624,23 @@ Window:: closeEvent(QCloseEvent *ev)
QMainWindow::closeEvent(ev);
}

// other functions
QString getNextFilename(QString current)
{
QFileInfo fi(current);
if (not fi.exists())
return QString();
QString filename = fi.fileName();
QString basedir = fi.absolutePath(); // This does not include filename
QString file_filter("*.jpg *.jpeg *.png *.gif *.svg *.bmp *.tiff");
QStringList image_list = fi.dir().entryList(file_filter.split(" "));
if (image_list.count()<2)
return QString();
int index = image_list.indexOf(filename);
if (index >= image_list.count()-1) index = -1;
return basedir + '/' + image_list[index+1];
}

// ************* main function ****************

int main(int argc, char *argv[])
Expand Down
6 changes: 2 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public slots:
void overwrite();
void saveAs();
void saveACopy();
void deleteFile();
void resizeImage();
void cropImage();
void mirror();
Expand Down Expand Up @@ -61,7 +62,4 @@ public slots:
void updateStatus();
};

void waitFor(int millisec);
// rounds up a number to given decimal point
float roundOff(float num, int dec);

QString getNextFilename(QString current);
5 changes: 1 addition & 4 deletions src/photoquick.pro
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
######################################################################
# Automatically generated by qmake (2.01a) Sun Oct 29 20:36:57 2017
######################################################################

TEMPLATE = app
TARGET = photoquick
DEPENDPATH += .
INCLUDEPATH += .
QMAKE_CXXFLAGS = -fopenmp -std=c++11
QMAKE_LFLAGS += -s
LIBS += -lgomp
win32:DEFINES += WIN32

Expand Down
2 changes: 1 addition & 1 deletion src/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ void calcArc(QPoint center, QPoint from, QPoint to, QPoint through,
float &start, float &span);

// _____________________________________________________________________

// ResizeDialog object to get required image size

class ResizeDialog : public QDialog, public Ui_ResizeDialog
{
Q_OBJECT
Expand Down

0 comments on commit 6c8d08e

Please sign in to comment.