Skip to content

Commit

Permalink
[core] ask when editing from folderview #339
Browse files Browse the repository at this point in the history
  • Loading branch information
easymodo committed Sep 26, 2021
1 parent 8ec2417 commit 153795b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions qimgv/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,11 @@ std::shared_ptr<ImageStatic> Core::getEditableImage(const QString &filePath) {
}

template<typename... Args>
void Core::edit_template(bool save, const std::function<QImage*(std::shared_ptr<const QImage>, Args...)>& editFunc, Args&&... as) {
void Core::edit_template(bool save, QString action, const std::function<QImage*(std::shared_ptr<const QImage>, Args...)>& editFunc, Args&&... as) {
if(model->isEmpty())
return;
if(save && !mw->showConfirmation(action, "Perform action \""+ action +"\"? \n\nChanges will be saved immediately."))
return;
for(auto path : currentSelection()) {
auto img = getEditableImage(path);
if(!img)
Expand All @@ -874,31 +876,33 @@ void Core::edit_template(bool save, const std::function<QImage*(std::shared_ptr<
}

void Core::flipH() {
edit_template((mw->currentViewMode() == MODE_FOLDERVIEW), { ImageLib::flippedH });
edit_template((mw->currentViewMode() == MODE_FOLDERVIEW), "Flip horizontal", { ImageLib::flippedH });
}

void Core::flipV() {
edit_template((mw->currentViewMode() == MODE_FOLDERVIEW), { ImageLib::flippedV });
edit_template((mw->currentViewMode() == MODE_FOLDERVIEW), "Flip vertical", { ImageLib::flippedV });
}

void Core::rotateByDegrees(int degrees) {
edit_template((mw->currentViewMode() == MODE_FOLDERVIEW), { ImageLib::rotated }, degrees);
edit_template((mw->currentViewMode() == MODE_FOLDERVIEW), "Rotate", { ImageLib::rotated }, degrees);
}

void Core::resize(QSize size) {
edit_template(false, { ImageLib::scaled }, size, QI_FILTER_BILINEAR);
edit_template(false, "Resize", { ImageLib::scaled }, size, QI_FILTER_BILINEAR);
}

void Core::crop(QRect rect) {
if(mw->currentViewMode() == MODE_FOLDERVIEW)
return;
edit_template(false, { ImageLib::cropped }, rect);
edit_template(false, "Crop", { ImageLib::cropped }, rect);
}

void Core::cropAndSave(QRect rect) {
if(mw->currentViewMode() == MODE_FOLDERVIEW)
return;
edit_template(true, { ImageLib::cropped }, rect);
edit_template(false, "Crop", { ImageLib::cropped }, rect);
saveFile(selectedPath());
updateInfoString();
}

// ---------------------------------------------------------------- image operations ^
Expand Down
2 changes: 1 addition & 1 deletion qimgv/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public slots:
QList<QString> currentSelection();

template<typename... Args>
void edit_template(bool save, const std::function<QImage*(std::shared_ptr<const QImage>, Args...)>& func, Args&&... as);
void edit_template(bool save, QString actionName, const std::function<QImage*(std::shared_ptr<const QImage>, Args...)>& func, Args&&... as);

void doInteractiveCopy(QString path, QString destDirectory, DialogResult &overwriteAllFiles);
void doInteractiveMove(QString path, QString destDirectory, DialogResult &overwriteAllFiles);
Expand Down

0 comments on commit 153795b

Please sign in to comment.