Skip to content

Commit

Permalink
Merge pull request #625 from jdpurcell/reloadimage
Browse files Browse the repository at this point in the history
Add "Reload File" feature
  • Loading branch information
jurplel authored Aug 27, 2023
2 parents e0b3e4a + 0334910 commit 6e091fd
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/actionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,11 @@ void MainWindow::pickUrl()
inputDialog->open();
}

void MainWindow::reloadFile()
{
graphicsView->reloadFile();
}

void MainWindow::openWith(const OpenWith::OpenWithItem &openWithItem)
{
OpenWith::openWith(getCurrentFileDetails().fileInfo.absoluteFilePath(), openWithItem);
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class MainWindow : public QMainWindow

void pickUrl();

void reloadFile();

void openContainingFolder();

void openWith(const OpenWith::OpenWithItem &exec);
Expand Down
8 changes: 8 additions & 0 deletions src/qvgraphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/qvgraphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/qvimagecore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/qvimagecore.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class QVImageCore : public QObject

explicit QVImageCore(QObject *parent = nullptr);

void loadFile(const QString &fileName);
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();
Expand Down
6 changes: 5 additions & 1 deletion src/shortcutmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,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());

Expand Down

0 comments on commit 6e091fd

Please sign in to comment.