From 2acfbbfac77a5f4ff131918c2b8f9ab59cf71341 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 20 Mar 2021 18:09:11 +0200 Subject: [PATCH] Library: add Quit shortcut The Ctrl+Q shortcut is assigned to Quit action in most applications on GNU/Linux. Command+Q is used on macOS. The added shortcut should be automatically mapped to Command+Q on macOS judging by the following quote from QKeySequence class documentation: Note: On macOS, references to "Ctrl", Qt::CTRL, Qt::Key_Control and Qt::ControlModifier correspond to the Command keys on the Macintosh keyboard QKeySequence::Quit could be used as the default key sequence in place of `Qt::CTRL | Qt::Key_Q`. This would leave the shortcut unassigned by default on Windows. But YACReader doesn't use QKeySequence::StandardKey anywhere, so perhaps this shortcut should be hard-coded too. The shortcut is particularly useful when Close to tray option is enabled, because in this case closing the Library window with a system window manager shortcut simply hides it. --- YACReaderLibrary/images_osx.qrc | 2 ++ YACReaderLibrary/images_win.qrc | 1 + YACReaderLibrary/library_window.cpp | 12 +++++++++++- YACReaderLibrary/library_window.h | 2 ++ YACReaderLibrary/trayicon_controller.cpp | 5 +---- shortcuts_management/shortcuts_manager.cpp | 1 + shortcuts_management/shortcuts_manager.h | 1 + 7 files changed, 19 insertions(+), 5 deletions(-) diff --git a/YACReaderLibrary/images_osx.qrc b/YACReaderLibrary/images_osx.qrc index 60489bfb..3a48539b 100644 --- a/YACReaderLibrary/images_osx.qrc +++ b/YACReaderLibrary/images_osx.qrc @@ -71,6 +71,8 @@ ../images/sidebar/delete_sidebar_osx@2x.png ../images/sidebar/addLabelIcon_osx@2x.png ../images/sidebar/renameListIcon_osx@2x.png + ../images/viewer_toolbar/close_osx.png + ../images/viewer_toolbar/close_osx@2x.png macostrayicon.svg diff --git a/YACReaderLibrary/images_win.qrc b/YACReaderLibrary/images_win.qrc index cb87e0cf..8828bf78 100644 --- a/YACReaderLibrary/images_win.qrc +++ b/YACReaderLibrary/images_win.qrc @@ -41,6 +41,7 @@ ../images/lists/label_yellow.png ../images/lists/list.png ../images/empty_reading_list.png + ../images/viewer_toolbar/close.png icon.ico diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index e2c17ca2..e359f8fb 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -396,7 +396,8 @@ void LibraryWindow::setUpShortcutsManagement() << helpAboutAction << optionsAction << serverConfigAction - << showEditShortcutsAction); + << showEditShortcutsAction + << quitAction); allActions << tmpList; @@ -752,6 +753,13 @@ void LibraryWindow::createActions() showEditShortcutsAction->setShortcutContext(Qt::ApplicationShortcut); addAction(showEditShortcutsAction); + quitAction = new QAction(tr("&Quit"), this); + quitAction->setIcon(QIcon(":/images/viewer_toolbar/close.png")); + quitAction->setData(QUIT_ACTION_YL); + quitAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(QUIT_ACTION_YL)); + // TODO: is `quitAction->setMenuRole(QAction::QuitRole);` useful on macOS? + addAction(quitAction); + updateFolderAction = new QAction(tr("Update folder"), this); updateFolderAction->setIcon(QIcon(":/images/menus_icons/updateLibraryIcon.png")); @@ -1179,6 +1187,8 @@ void LibraryWindow::createConnections() connect(showEditShortcutsAction, SIGNAL(triggered()), editShortcutsDialog, SLOT(show())); + connect(quitAction, &QAction::triggered, this, &LibraryWindow::closeApp); + //update folders (partial updates) connect(updateCurrentFolderAction, SIGNAL(triggered()), this, SLOT(updateCurrentFolder())); connect(updateFolderAction, SIGNAL(triggered()), this, SLOT(updateCurrentFolder())); diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 969c10a8..7b0a14e8 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -218,6 +218,8 @@ public: QAction *showEditShortcutsAction; + QAction *quitAction; + QAction *updateFolderAction; QAction *updateCurrentFolderAction; diff --git a/YACReaderLibrary/trayicon_controller.cpp b/YACReaderLibrary/trayicon_controller.cpp index c30f5af2..d1ca2faa 100644 --- a/YACReaderLibrary/trayicon_controller.cpp +++ b/YACReaderLibrary/trayicon_controller.cpp @@ -52,13 +52,10 @@ TrayIconController::TrayIconController(QSettings *settings, LibraryWindow *windo auto restoreAction = new QAction(tr("&Restore"), this); connect(restoreAction, &QAction::triggered, this, &TrayIconController::showWindow); - auto quitAction = new QAction(tr("&Quit"), this); - connect(quitAction, &QAction::triggered, window, &LibraryWindow::closeApp); - trayIconMenu = new QMenu(this->window); trayIconMenu->addAction(restoreAction); trayIconMenu->addSeparator(); - trayIconMenu->addAction(quitAction); + trayIconMenu->addAction(this->window->quitAction); trayIcon.setContextMenu(trayIconMenu); diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp index 67e645e4..2ffc4c31 100644 --- a/shortcuts_management/shortcuts_manager.cpp +++ b/shortcuts_management/shortcuts_manager.cpp @@ -27,6 +27,7 @@ void ShortcutsManager::initDefaultShorcuts() defaultShorcuts.insert(COLAPSE_ALL_NODES_ACTION_YL, Qt::Key_Minus); defaultShorcuts.insert(OPTIONS_ACTION_YL, Qt::Key_C); defaultShorcuts.insert(SERVER_CONFIG_ACTION_YL, Qt::Key_S); + defaultShorcuts.insert(QUIT_ACTION_YL, Qt::CTRL | Qt::Key_Q); defaultShorcuts.insert(TOGGLE_COMICS_VIEW_ACTION_YL, Qt::Key_V); //COMMANDS (used in keypressevent) diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index 787eee2a..166830ad 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -78,6 +78,7 @@ public: #define FOCUS_SEARCH_LINE_ACTION_YL "FOCUS_SEARCH_LINE_ACTION_YL" #define FOCUS_COMICS_VIEW_ACTION_YL "FOCUS_COMICS_VIEW_ACTION_YL" #define SHOW_EDIT_SHORTCUTS_ACTION_YL "SHOW_EDIT_SHORTCUTS_ACTION_YL" +#define QUIT_ACTION_YL "QUIT_ACTION_YL" #define UPDATE_CURRENT_FOLDER_ACTION_YL "UPDATE_CURRENT_FOLDER_ACTION_YL" #define ADD_FOLDER_ACTION_YL "ADD_FOLDER_ACTION_YL" #define REMOVE_FOLDER_ACTION_YL "REMOVE_FOLDER_ACTION_YL"