From ddf59849cce1f827bf1ba392b401d528064cdbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 28 Aug 2017 18:33:44 +0200 Subject: [PATCH] Added new action for opening the latest issue opened, by default CTRL+R. --- YACReader/main_window_viewer.cpp | 77 ++++++++++++++-------- YACReader/main_window_viewer.h | 3 + shortcuts_management/shortcuts_manager.cpp | 1 + shortcuts_management/shortcuts_manager.h | 1 + 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index e3da7210..454d62e8 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -84,6 +84,7 @@ MainWindowViewer::~MainWindowViewer() //delete sliderAction; delete openAction; delete openFolderAction; + delete openLatestComicAction; delete saveImageAction; delete openPreviousComicAction; delete openNextComicAction; @@ -222,7 +223,13 @@ void MainWindowViewer::createActions() openFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_FOLDER_ACTION_Y)); connect(openFolderAction, SIGNAL(triggered()), this, SLOT(openFolder())); - QAction* recentFileAction = 0; + openLatestComicAction = new QAction(tr("Open latest comic"), this); + openLatestComicAction->setToolTip(tr("Open the latest comic opened in the previous reading session")); + openLatestComicAction->setData(OPEN_LATEST_COMIC_Y); + openLatestComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_LATEST_COMIC_Y)); + connect(openLatestComicAction, SIGNAL(triggered()), this, SLOT(openLatestComic())); + + QAction* recentFileAction = nullptr; //TODO: Replace limit with a configurable value for (int i = 0; i < 10; i++) { @@ -516,10 +523,6 @@ void MainWindowViewer::createToolBars() comicToolBar->setStyleSheet("QToolBar{border:none;}"); #endif -#ifdef Q_OS_MAC - comicToolBar->addAction(openAction); - comicToolBar->addAction(openFolderAction); -#else QMenu * recentmenu = new QMenu(tr("Open recent")); recentmenu->addActions(recentFilesActionList); recentmenu->addSeparator(); @@ -528,13 +531,14 @@ void MainWindowViewer::createToolBars() QToolButton * tb = new QToolButton(); tb->addAction(openAction); + tb->addAction(openLatestComicAction); tb->addAction(openFolderAction); tb->addAction(recentmenu->menuAction()); tb->setPopupMode(QToolButton::MenuButtonPopup); tb->setDefaultAction(openAction); comicToolBar->addWidget(tb); -#endif + comicToolBar->addAction(saveImageAction); comicToolBar->addAction(openPreviousComicAction); comicToolBar->addAction(openNextComicAction); @@ -757,22 +761,39 @@ void MainWindowViewer::clearRecentFiles() void MainWindowViewer::openRecent() { QAction *action = qobject_cast(sender()); - if (action) - { - QFileInfo info1 (action->data().toString()); - if (info1.exists()) - { - if (info1.isFile()) - { - openComicFromPath(action->data().toString()); - } - else if (info1.isDir()) - { - openFolderFromPath(action->data().toString()); - } - } - - } + + openComicFromRecentAction(action); +} + +void MainWindowViewer::openLatestComic() +{ + if (recentFilesActionList.isEmpty()) + { + return; + } + + openComicFromRecentAction(recentFilesActionList[0]); +} + +void MainWindowViewer::openComicFromRecentAction(QAction *action) +{ + if (action == nullptr) + { + return; + } + + QFileInfo info1 (action->data().toString()); + if (info1.exists()) + { + if (info1.isFile()) + { + openComicFromPath(action->data().toString()); + } + else if (info1.isDir()) + { + openFolderFromPath(action->data().toString()); + } + } } void MainWindowViewer::reloadOptions() @@ -1245,12 +1266,12 @@ void MainWindowViewer::setUpShortcutsManagement() editShortcutsDialog->addActionsGroup(tr("Comics"),QIcon(":/images/shortcuts_group_comics.png"), - tmpList = QList() - << openAction - << openFolderAction - << saveImageAction - << openPreviousComicAction - << openNextComicAction); + tmpList = { openAction, + openLatestComicAction, + openFolderAction, + saveImageAction, + openPreviousComicAction, + openNextComicAction }); allActions << tmpList; diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index e18aa901..a0a697b7 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -35,6 +35,8 @@ class EditShortcutsDialog; void open(QString path, qint64 comicId, qint64 libraryId); void openFolder(); void openRecent(); + void openLatestComic(); + void openComicFromRecentAction(QAction *action); void saveImage(); void toggleToolBars(); void hideToolBars(); @@ -106,6 +108,7 @@ class EditShortcutsDialog; //! Actions QAction *openAction; QAction *openFolderAction; + QAction *openLatestComicAction; QList recentFilesActionList; QAction *clearRecentFilesAction; QAction *saveImageAction; diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp index 33e5be92..9286b1ed 100644 --- a/shortcuts_management/shortcuts_manager.cpp +++ b/shortcuts_management/shortcuts_manager.cpp @@ -31,6 +31,7 @@ void ShortcutsManager::initDefaultShorcuts() //COMMANDS (used in keypressevent) #else defaultShorcuts.insert(OPEN_ACTION_Y, Qt::Key_O); + defaultShorcuts.insert(OPEN_LATEST_COMIC_Y, Qt::CTRL | Qt::Key_R); defaultShorcuts.insert(OPEN_FOLDER_ACTION_Y, Qt::CTRL | Qt::Key_O); defaultShorcuts.insert(OPEN_PREVIOUS_COMIC_ACTION_Y, Qt::CTRL | Qt::Key_Left); defaultShorcuts.insert(OPEN_NEXT_COMIC_ACTION_Y, Qt::CTRL | Qt::Key_Right); diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index 7997a4f2..3094339b 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -113,6 +113,7 @@ public: #define FIT_TO_PAGE_ACTION_Y "FIT_TO_PAGE_ACTION_Y" #define SHOW_FLOW_ACTION_Y "SHOW_FLOW_ACTION_Y" #define SHOW_EDIT_SHORTCUTS_ACTION_Y "SHOW_EDIT_SHORTCUTS_ACTION_Y" +#define OPEN_LATEST_COMIC_Y "OPEN_LATEST_COMIC_Y" //COMMANDS YACReader //main_viewer_window