From 4dfdabe47eaa7d24ef0582910e5a82a033104d3a Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Sat, 26 Aug 2023 20:37:02 -0400 Subject: [PATCH 1/2] Add "Reload File" feature --- src/actionmanager.cpp | 7 +++++++ src/mainwindow.cpp | 5 +++++ src/mainwindow.h | 2 ++ src/qvgraphicsview.cpp | 8 ++++++++ src/qvgraphicsview.h | 2 ++ src/qvimagecore.cpp | 4 ++-- src/qvimagecore.h | 2 +- src/shortcutmanager.cpp | 1 + 8 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index bc62c753..6c22948d 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -177,6 +177,7 @@ QMenuBar *ActionManager::buildMenuBar(QWidget *parent) addCloneOfAction(fileMenu, "open"); addCloneOfAction(fileMenu, "openurl"); fileMenu->addMenu(buildRecentsMenu(true, fileMenu)); + addCloneOfAction(fileMenu, "reloadfile"); fileMenu->addSeparator(); #ifdef Q_OS_MACOS fileMenu->addSeparator(); @@ -585,6 +586,8 @@ void ActionManager::actionTriggered(QAction *triggeredAction, MainWindow *releva relevantWindow->openWith(openWithItem); } else if (key == "openurl") { relevantWindow->pickUrl(); + } else if (key == "reloadfile") { + relevantWindow->reloadFile(); } else if (key == "opencontainingfolder") { relevantWindow->openContainingFolder(); } else if (key == "showfileinfo") { @@ -660,6 +663,10 @@ void ActionManager::initializeActionLibrary() auto *openUrlAction = new QAction(QIcon::fromTheme("document-open-remote", QIcon::fromTheme("folder-remote")), tr("Open &URL...")); actionLibrary.insert("openurl", openUrlAction); + auto *reloadFileAction = new QAction(QIcon::fromTheme("view-refresh"), tr("Re&load File")); + reloadFileAction->setData({"disable"}); + actionLibrary.insert("reloadfile", reloadFileAction); + auto *closeWindowAction = new QAction(QIcon::fromTheme("window-close"), tr("Close Window")); actionLibrary.insert("closewindow", closeWindowAction); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e431516f..17fcad0a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -667,6 +667,11 @@ void MainWindow::pickUrl() inputDialog->open(); } +void MainWindow::reloadFile() +{ + graphicsView->reloadFile(); +} + void MainWindow::openWith(const OpenWith::OpenWithItem &openWithItem) { OpenWith::openWith(getCurrentFileDetails().fileInfo.absoluteFilePath(), openWithItem); diff --git a/src/mainwindow.h b/src/mainwindow.h index 9bae41c5..19c82bca 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -51,6 +51,8 @@ class MainWindow : public QMainWindow void pickUrl(); + void reloadFile(); + void openContainingFolder(); void openWith(const OpenWith::OpenWithItem &exec); diff --git a/src/qvgraphicsview.cpp b/src/qvgraphicsview.cpp index 3e25ca0f..b5c604f9 100644 --- a/src/qvgraphicsview.cpp +++ b/src/qvgraphicsview.cpp @@ -244,6 +244,14 @@ void QVGraphicsView::loadFile(const QString &fileName) imageCore.loadFile(fileName); } +void QVGraphicsView::reloadFile() +{ + if (!getCurrentFileDetails().isPixmapLoaded) + return; + + imageCore.loadFile(getCurrentFileDetails().fileInfo.absoluteFilePath(), true); +} + void QVGraphicsView::postLoad() { updateLoadedPixmapItem(); diff --git a/src/qvgraphicsview.h b/src/qvgraphicsview.h index 8299dbf1..d2fb8624 100644 --- a/src/qvgraphicsview.h +++ b/src/qvgraphicsview.h @@ -38,6 +38,8 @@ class QVGraphicsView : public QGraphicsView void loadMimeData(const QMimeData *mimeData); void loadFile(const QString &fileName); + void reloadFile(); + void zoomIn(const QPoint &pos = QPoint(-1, -1)); void zoomOut(const QPoint &pos = QPoint(-1, -1)); diff --git a/src/qvimagecore.cpp b/src/qvimagecore.cpp index 0a933997..8a940abb 100644 --- a/src/qvimagecore.cpp +++ b/src/qvimagecore.cpp @@ -68,7 +68,7 @@ QVImageCore::QVImageCore(QObject *parent) : QObject(parent) settingsUpdated(); } -void QVImageCore::loadFile(const QString &fileName) +void QVImageCore::loadFile(const QString &fileName, bool isReloading) { if (waitingOnLoad) { @@ -105,7 +105,7 @@ void QVImageCore::loadFile(const QString &fileName) QString cacheKey = getPixmapCacheKey(sanitaryFileName, fileInfo.size(), targetColorSpace); //check if cached already before loading the long way - auto *cachedData = QVImageCore::pixmapCache.take(cacheKey); + auto *cachedData = isReloading ? nullptr : QVImageCore::pixmapCache.take(cacheKey); if (cachedData != nullptr) { ReadData readData = *cachedData; diff --git a/src/qvimagecore.h b/src/qvimagecore.h index 2cf443e4..92796af7 100644 --- a/src/qvimagecore.h +++ b/src/qvimagecore.h @@ -60,7 +60,7 @@ class QVImageCore : public QObject explicit QVImageCore(QObject *parent = nullptr); - void loadFile(const QString &fileName); + void loadFile(const QString &fileName, bool isReloaing = false); ReadData readFile(const QString &fileName, const QColorSpace &targetColorSpace, bool forCache); void loadPixmap(const ReadData &readData); void closeImage(); diff --git a/src/shortcutmanager.cpp b/src/shortcutmanager.cpp index 3bd7c155..f1d88535 100644 --- a/src/shortcutmanager.cpp +++ b/src/shortcutmanager.cpp @@ -44,6 +44,7 @@ void ShortcutManager::initializeShortcutsList() { shortcutsList.append({tr("Open"), "open", keyBindingsToStringList(QKeySequence::Open), {}}); shortcutsList.append({tr("Open URL"), "openurl", QStringList(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_O).toString()), {}}); + shortcutsList.append({tr("Reload File"), "reloadfile", keyBindingsToStringList(QKeySequence::Refresh), {}}); shortcutsList.append({tr("Open Containing Folder"), "opencontainingfolder", {}, {}}); //Sets open containing folder action name to platform-appropriate alternative #ifdef Q_OS_WIN From 0334910b03bbdc0e96f4775ea7a638d96741e473 Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Sun, 27 Aug 2023 16:41:18 -0400 Subject: [PATCH 2/2] CR feedback for "Reload File" --- src/qvimagecore.h | 2 +- src/shortcutmanager.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qvimagecore.h b/src/qvimagecore.h index 92796af7..20e5f0fd 100644 --- a/src/qvimagecore.h +++ b/src/qvimagecore.h @@ -60,7 +60,7 @@ class QVImageCore : public QObject explicit QVImageCore(QObject *parent = nullptr); - void loadFile(const QString &fileName, bool isReloaing = false); + void loadFile(const QString &fileName, bool isReloading = false); ReadData readFile(const QString &fileName, const QColorSpace &targetColorSpace, bool forCache); void loadPixmap(const ReadData &readData); void closeImage(); diff --git a/src/shortcutmanager.cpp b/src/shortcutmanager.cpp index f1d88535..84f2d00c 100644 --- a/src/shortcutmanager.cpp +++ b/src/shortcutmanager.cpp @@ -59,7 +59,10 @@ void ShortcutManager::initializeShortcutsList() #endif shortcutsList.append({tr("Copy"), "copy", keyBindingsToStringList(QKeySequence::Copy), {}}); shortcutsList.append({tr("Paste"), "paste", keyBindingsToStringList(QKeySequence::Paste), {}}); - shortcutsList.append({tr("Rename"), "rename", QStringList({QKeySequence(Qt::Key_F2).toString(), QKeySequence(Qt::CTRL | Qt::Key_R).toString()}), {}}); + shortcutsList.append({tr("Rename"), "rename", QStringList(QKeySequence(Qt::Key_F2).toString()), {}}); + // ctrl+r for renaming, unless it conflicts with refresh (i.e. reload file) + if (!QKeySequence::keyBindings(QKeySequence::Refresh).contains(QKeySequence(Qt::CTRL | Qt::Key_R))) + shortcutsList.last().defaultShortcuts << QKeySequence(Qt::CTRL | Qt::Key_R).toString(); // cmd+enter for renaming, mac-style shortcutsList.last().defaultShortcuts.prepend(QKeySequence(Qt::CTRL | Qt::Key_Return).toString());