From 81e40dabec18c050b6762f46422078df9acad156 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sun, 19 May 2019 15:54:59 +0300 Subject: [PATCH 1/5] Library: add a shortcut to focus search line The Ctrl+F shortcut gives focus to a search bar in many applications. In this case it allows to search the library without touching a mouse. YACReaderMacOSXSearchLineEdit::setFocus() will have to be implemented to make the shortcut work on macOS. --- YACReaderLibrary/library_window.cpp | 8 ++++++++ YACReaderLibrary/library_window.h | 1 + custom_widgets/yacreader_macosx_toolbar.h | 1 + custom_widgets/yacreader_macosx_toolbar.mm | 6 ++++++ shortcuts_management/shortcuts_manager.cpp | 1 + shortcuts_management/shortcuts_manager.h | 1 + 6 files changed, 18 insertions(+) diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 65f5a76b..3a5b67f4 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -377,6 +377,7 @@ void LibraryWindow::setUpShortcutsManagement() tmpList = QList() << backAction << forwardAction + << focusSearchLineAction << helpAboutAction << optionsAction << serverConfigAction @@ -719,6 +720,12 @@ void LibraryWindow::createActions() getInfoAction->setIcon(QIcon(":/images/comics_view_toolbar/getInfo.png")); //------------------------------------------------------------------------- + focusSearchLineAction = new QAction(tr("Focus search line"), this); + focusSearchLineAction->setData(FOCUS_SEARCH_LINE_ACTION_YL); + focusSearchLineAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(FOCUS_SEARCH_LINE_ACTION_YL)); + focusSearchLineAction->setIcon(QIcon(":/images/iconSearch.png")); + addAction(focusSearchLineAction); + showEditShortcutsAction = new QAction(tr("Edit shortcuts"), this); showEditShortcutsAction->setData(SHOW_EDIT_SHORTCUTS_ACTION_YL); showEditShortcutsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_EDIT_SHORTCUTS_ACTION_YL)); @@ -1147,6 +1154,7 @@ void LibraryWindow::createConnections() //connect(comicsModel,SIGNAL(searchNumResults(int)),this,SLOT(checkSearchNumResults(int))); //connect(emptyFolderWidget,SIGNAL(subfolderSelected(QModelIndex,int)),this,SLOT(selectSubfolder(QModelIndex,int))); + connect(focusSearchLineAction, &QAction::triggered, searchEdit, [this] { searchEdit->setFocus(Qt::ShortcutFocusReason); }); connect(showEditShortcutsAction, SIGNAL(triggered()), editShortcutsDialog, SLOT(show())); //update folders (partial updates) diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index af9664e2..8a88f1f0 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -213,6 +213,7 @@ public: QAction *forceCoverExtractedAction; QAction *deleteComicsAction; + QAction *focusSearchLineAction; QAction *showEditShortcutsAction; QAction *updateFolderAction; diff --git a/custom_widgets/yacreader_macosx_toolbar.h b/custom_widgets/yacreader_macosx_toolbar.h index c6fe9000..b49e6e8b 100644 --- a/custom_widgets/yacreader_macosx_toolbar.h +++ b/custom_widgets/yacreader_macosx_toolbar.h @@ -12,6 +12,7 @@ class YACReaderMacOSXSearchLineEdit : public QObject Q_OBJECT public: YACReaderMacOSXSearchLineEdit(); + void setFocus(Qt::FocusReason reason); void *getNSTextField(); public slots: diff --git a/custom_widgets/yacreader_macosx_toolbar.mm b/custom_widgets/yacreader_macosx_toolbar.mm index 229e825a..3e9d786a 100644 --- a/custom_widgets/yacreader_macosx_toolbar.mm +++ b/custom_widgets/yacreader_macosx_toolbar.mm @@ -316,6 +316,12 @@ YACReaderMacOSXSearchLineEdit::YACReaderMacOSXSearchLineEdit() nstextfield = searchEdit; } +void YACReaderMacOSXSearchLineEdit::setFocus(Qt::FocusReason reason) +{ + Q_UNUSED(reason) + // TODO: implement +} + void *YACReaderMacOSXSearchLineEdit::getNSTextField() { return nstextfield; diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp index 541e4efd..67e645e4 100644 --- a/shortcuts_management/shortcuts_manager.cpp +++ b/shortcuts_management/shortcuts_manager.cpp @@ -13,6 +13,7 @@ void ShortcutsManager::initDefaultShorcuts() { #ifdef YACREADER_LIBRARY //ACTIONS + defaultShorcuts.insert(FOCUS_SEARCH_LINE_ACTION_YL, Qt::CTRL | Qt::Key_F); defaultShorcuts.insert(CREATE_LIBRARY_ACTION_YL, Qt::Key_A); defaultShorcuts.insert(OPEN_LIBRARY_ACTION_YL, Qt::Key_O); defaultShorcuts.insert(UPDATE_LIBRARY_ACTION_YL, Qt::Key_U); diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index d07a926c..dbcd8eb0 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -75,6 +75,7 @@ public: #define DELETE_COMICS_ACTION_YL "DELETE_COMICS_ACTION_YL" #define HIDE_COMIC_VIEW_ACTION_YL "HIDE_COMIC_VIEW_ACTION_YL" #define GET_INFO_ACTION_YL "GET_INFO_ACTION_YL" +#define FOCUS_SEARCH_LINE_ACTION_YL "FOCUS_SEARCH_LINE_ACTION_YL" #define SHOW_EDIT_SHORTCUTS_ACTION_YL "SHOW_EDIT_SHORTCUTS_ACTION_YL" #define UPDATE_CURRENT_FOLDER_ACTION_YL "UPDATE_CURRENT_FOLDER_ACTION_YL" #define ADD_FOLDER_ACTION_YL "ADD_FOLDER_ACTION_YL" From 8a541008042ab0b21cb18bc3382918d3dee2df0e Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 22 May 2019 14:12:31 +0300 Subject: [PATCH 2/5] Library: allow configuring a shortcut to focus comics view Focusing the current comics view allows to use keyboard arrow keys to choose among the visible comics. The shortcut for this new action should not be a single character without modifiers because it won't work when the search line has focus. The Qt::FocusReason parameter in ComicsView::focusComicsNavigation() allows to reuse this function for other keyboard navigation features. For instance the search line can transfer focus to comics navigation when the user presses Return or Enter key. In this case Qt::OtherFocusReason can be used (an application-specific reason). --- YACReaderLibrary/classic_comics_view.cpp | 9 +++++++++ YACReaderLibrary/classic_comics_view.h | 1 + YACReaderLibrary/comics_view.h | 1 + YACReaderLibrary/grid_comics_view.cpp | 5 +++++ YACReaderLibrary/grid_comics_view.h | 1 + YACReaderLibrary/info_comics_view.cpp | 5 +++++ YACReaderLibrary/info_comics_view.h | 1 + YACReaderLibrary/library_window.cpp | 8 ++++++++ YACReaderLibrary/library_window.h | 2 ++ YACReaderLibrary/yacreader_comics_views_manager.cpp | 5 +++++ YACReaderLibrary/yacreader_comics_views_manager.h | 1 + shortcuts_management/shortcuts_manager.h | 1 + 12 files changed, 40 insertions(+) diff --git a/YACReaderLibrary/classic_comics_view.cpp b/YACReaderLibrary/classic_comics_view.cpp index 56d35fc1..113a6381 100644 --- a/YACReaderLibrary/classic_comics_view.cpp +++ b/YACReaderLibrary/classic_comics_view.cpp @@ -258,6 +258,15 @@ void ClassicComicsView::updateCurrentComicView() { } +void ClassicComicsView::focusComicsNavigation(Qt::FocusReason reason) +{ + const bool comicFlowVisible = stack->currentWidget() == comicFlow && sVertical->sizes().constFirst() != 0; + if (comicFlowVisible) + comicFlow->setFocus(reason); + else // Let the user navigate the table. + tableView->setFocus(reason); +} + void ClassicComicsView::selectAll() { tableView->selectAll(); diff --git a/YACReaderLibrary/classic_comics_view.h b/YACReaderLibrary/classic_comics_view.h index a5d51f14..4b09ca96 100644 --- a/YACReaderLibrary/classic_comics_view.h +++ b/YACReaderLibrary/classic_comics_view.h @@ -32,6 +32,7 @@ public: void enableFilterMode(bool enabled) override; void selectIndex(int index) override; void updateCurrentComicView() override; + void focusComicsNavigation(Qt::FocusReason reason) override; public slots: void setCurrentIndex(const QModelIndex &index) override; diff --git a/YACReaderLibrary/comics_view.h b/YACReaderLibrary/comics_view.h index 54e49ee6..9b98eee7 100644 --- a/YACReaderLibrary/comics_view.h +++ b/YACReaderLibrary/comics_view.h @@ -29,6 +29,7 @@ public: virtual void enableFilterMode(bool enabled) = 0; virtual void selectIndex(int index) = 0; virtual void updateCurrentComicView() = 0; + virtual void focusComicsNavigation(Qt::FocusReason reason) = 0; public slots: virtual void updateInfoForIndex(int index); diff --git a/YACReaderLibrary/grid_comics_view.cpp b/YACReaderLibrary/grid_comics_view.cpp index cfeadb85..feb24ae2 100644 --- a/YACReaderLibrary/grid_comics_view.cpp +++ b/YACReaderLibrary/grid_comics_view.cpp @@ -491,6 +491,11 @@ void GridComicsView::updateCurrentComicView() setCurrentComicIfNeeded(); } +void GridComicsView::focusComicsNavigation(Qt::FocusReason reason) +{ + view->setFocus(reason); +} + void GridComicsView::startDrag() { auto drag = new QDrag(this); diff --git a/YACReaderLibrary/grid_comics_view.h b/YACReaderLibrary/grid_comics_view.h index 73e0e2b6..1d7ca65e 100644 --- a/YACReaderLibrary/grid_comics_view.h +++ b/YACReaderLibrary/grid_comics_view.h @@ -34,6 +34,7 @@ public: QSize sizeHint(); QByteArray getMimeDataFromSelection(); void updateCurrentComicView() override; + void focusComicsNavigation(Qt::FocusReason reason) override; public slots: //ComicsView diff --git a/YACReaderLibrary/info_comics_view.cpp b/YACReaderLibrary/info_comics_view.cpp index f4d0c87e..5aa5191c 100644 --- a/YACReaderLibrary/info_comics_view.cpp +++ b/YACReaderLibrary/info_comics_view.cpp @@ -208,6 +208,11 @@ void InfoComicsView::updateCurrentComicView() { } +void InfoComicsView::focusComicsNavigation(Qt::FocusReason reason) +{ + view->setFocus(reason); +} + void InfoComicsView::setShowMarks(bool show) { QQmlContext *ctxt = view->rootContext(); diff --git a/YACReaderLibrary/info_comics_view.h b/YACReaderLibrary/info_comics_view.h index a3f8c288..d4fe38d6 100644 --- a/YACReaderLibrary/info_comics_view.h +++ b/YACReaderLibrary/info_comics_view.h @@ -26,6 +26,7 @@ public: void enableFilterMode(bool enabled) override; void selectIndex(int index) override; void updateCurrentComicView() override; + void focusComicsNavigation(Qt::FocusReason reason) override; public slots: void setShowMarks(bool show); diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 3a5b67f4..c13df18b 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -378,6 +378,7 @@ void LibraryWindow::setUpShortcutsManagement() << backAction << forwardAction << focusSearchLineAction + << focusComicsViewAction << helpAboutAction << optionsAction << serverConfigAction @@ -726,6 +727,11 @@ void LibraryWindow::createActions() focusSearchLineAction->setIcon(QIcon(":/images/iconSearch.png")); addAction(focusSearchLineAction); + focusComicsViewAction = new QAction(tr("Focus comics view"), this); + focusComicsViewAction->setData(FOCUS_COMICS_VIEW_ACTION_YL); + focusComicsViewAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(FOCUS_COMICS_VIEW_ACTION_YL)); + addAction(focusComicsViewAction); + showEditShortcutsAction = new QAction(tr("Edit shortcuts"), this); showEditShortcutsAction->setData(SHOW_EDIT_SHORTCUTS_ACTION_YL); showEditShortcutsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_EDIT_SHORTCUTS_ACTION_YL)); @@ -1155,6 +1161,8 @@ void LibraryWindow::createConnections() //connect(emptyFolderWidget,SIGNAL(subfolderSelected(QModelIndex,int)),this,SLOT(selectSubfolder(QModelIndex,int))); connect(focusSearchLineAction, &QAction::triggered, searchEdit, [this] { searchEdit->setFocus(Qt::ShortcutFocusReason); }); + connect(focusComicsViewAction, &QAction::triggered, comicsViewsManager, &YACReaderComicsViewsManager::focusComicsViewViaShortcut); + connect(showEditShortcutsAction, SIGNAL(triggered()), editShortcutsDialog, SLOT(show())); //update folders (partial updates) diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 8a88f1f0..7a433004 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -214,6 +214,8 @@ public: QAction *deleteComicsAction; QAction *focusSearchLineAction; + QAction *focusComicsViewAction; + QAction *showEditShortcutsAction; QAction *updateFolderAction; diff --git a/YACReaderLibrary/yacreader_comics_views_manager.cpp b/YACReaderLibrary/yacreader_comics_views_manager.cpp index 63ff90db..45301831 100644 --- a/YACReaderLibrary/yacreader_comics_views_manager.cpp +++ b/YACReaderLibrary/yacreader_comics_views_manager.cpp @@ -121,6 +121,11 @@ void YACReaderComicsViewsManager::toggleComicsView() } } +void YACReaderComicsViewsManager::focusComicsViewViaShortcut() +{ + comicsView->focusComicsNavigation(Qt::ShortcutFocusReason); +} + //PROTECTED void YACReaderComicsViewsManager::disconnectComicsViewConnections(ComicsView *widget) diff --git a/YACReaderLibrary/yacreader_comics_views_manager.h b/YACReaderLibrary/yacreader_comics_views_manager.h index b93fed05..4e79dd25 100644 --- a/YACReaderLibrary/yacreader_comics_views_manager.h +++ b/YACReaderLibrary/yacreader_comics_views_manager.h @@ -55,6 +55,7 @@ signals: public slots: void toggleComicsView(); + void focusComicsViewViaShortcut(); void showComicsView(); void showEmptyFolderView(); diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index dbcd8eb0..787eee2a 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -76,6 +76,7 @@ public: #define HIDE_COMIC_VIEW_ACTION_YL "HIDE_COMIC_VIEW_ACTION_YL" #define GET_INFO_ACTION_YL "GET_INFO_ACTION_YL" #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 UPDATE_CURRENT_FOLDER_ACTION_YL "UPDATE_CURRENT_FOLDER_ACTION_YL" #define ADD_FOLDER_ACTION_YL "ADD_FOLDER_ACTION_YL" From fc57378a85469e9dd51701b0cde5a157f2130e15 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Thu, 11 Feb 2021 17:28:39 +0200 Subject: [PATCH 3/5] Remove unused sizeHint() from GridComicsView and ComicsViewTransition QWidget::sizeHint() is const-qualified, so Clang warns that non-const sizeHint() member functions merely hide the virtual function of the base class. 664dac34010c946db4477065abd077a7f7145bcd and 9f53ae6efcfb63c90308f86d4d30230c8750e66c introduced these member functions in 2014 without const qualifiers. QWidget::sizeHint() was const-qualified even in Qt 3. Since these member functions have never had any effect, they should be removed rather than const-qualified to preserve the long-standing behaviors of the two classes. Add a TODO for a similar but less straightforward issue with PropertiesDialog::sizeHint(). --- YACReaderLibrary/comics_view_transition.cpp | 5 ----- YACReaderLibrary/comics_view_transition.h | 1 - YACReaderLibrary/grid_comics_view.cpp | 5 ----- YACReaderLibrary/grid_comics_view.h | 1 - YACReaderLibrary/properties_dialog.h | 3 +++ 5 files changed, 3 insertions(+), 12 deletions(-) diff --git a/YACReaderLibrary/comics_view_transition.cpp b/YACReaderLibrary/comics_view_transition.cpp index c22bbc8a..447e86cc 100644 --- a/YACReaderLibrary/comics_view_transition.cpp +++ b/YACReaderLibrary/comics_view_transition.cpp @@ -20,11 +20,6 @@ ComicsViewTransition::ComicsViewTransition(QWidget *parent) #endif } -QSize ComicsViewTransition::sizeHint() -{ - return QSize(450, 350); -} - void ComicsViewTransition::paintEvent(QPaintEvent *) { QPainter painter(this); diff --git a/YACReaderLibrary/comics_view_transition.h b/YACReaderLibrary/comics_view_transition.h index 7f2cc7b0..78a08c3e 100644 --- a/YACReaderLibrary/comics_view_transition.h +++ b/YACReaderLibrary/comics_view_transition.h @@ -8,7 +8,6 @@ class ComicsViewTransition : public QWidget Q_OBJECT public: explicit ComicsViewTransition(QWidget *parent = nullptr); - QSize sizeHint(); protected: void paintEvent(QPaintEvent *) override; diff --git a/YACReaderLibrary/grid_comics_view.cpp b/YACReaderLibrary/grid_comics_view.cpp index feb24ae2..f442bece 100644 --- a/YACReaderLibrary/grid_comics_view.cpp +++ b/YACReaderLibrary/grid_comics_view.cpp @@ -469,11 +469,6 @@ void GridComicsView::resetScroll() QMetaObject::invokeMethod(scrollView, "scrollToOrigin"); } -QSize GridComicsView::sizeHint() -{ - return QSize(1280, 768); -} - QByteArray GridComicsView::getMimeDataFromSelection() { QByteArray data; diff --git a/YACReaderLibrary/grid_comics_view.h b/YACReaderLibrary/grid_comics_view.h index 1d7ca65e..8b39f1d3 100644 --- a/YACReaderLibrary/grid_comics_view.h +++ b/YACReaderLibrary/grid_comics_view.h @@ -31,7 +31,6 @@ public: void toNormal() override; void updateConfig(QSettings *settings) override; void enableFilterMode(bool enabled) override; - QSize sizeHint(); QByteArray getMimeDataFromSelection(); void updateCurrentComicView() override; void focusComicsNavigation(Qt::FocusReason reason) override; diff --git a/YACReaderLibrary/properties_dialog.h b/YACReaderLibrary/properties_dialog.h index ad32320f..56505dcf 100644 --- a/YACReaderLibrary/properties_dialog.h +++ b/YACReaderLibrary/properties_dialog.h @@ -122,6 +122,9 @@ public: PropertiesDialog(QWidget *parent = nullptr); QString databasePath; QString basePath; + // TODO: this non-const member function hides rather than overrides + // QWidget::sizeHint(). But the function cannot be simply removed as it is used + // in our constructor. Will have to investigate and decide how to fix this. QSize sizeHint(); void paintEvent(QPaintEvent *event) override; From 288b9cbec6fe460a6653427d3b3ab2cec50dd612 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Thu, 11 Feb 2021 17:40:24 +0200 Subject: [PATCH 4/5] ComicsView's derived classes: use explicit, nullptr, override --- YACReaderLibrary/classic_comics_view.h | 2 +- YACReaderLibrary/grid_comics_view.h | 4 ++-- YACReaderLibrary/info_comics_view.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/YACReaderLibrary/classic_comics_view.h b/YACReaderLibrary/classic_comics_view.h index 4b09ca96..87122dc7 100644 --- a/YACReaderLibrary/classic_comics_view.h +++ b/YACReaderLibrary/classic_comics_view.h @@ -19,7 +19,7 @@ class ClassicComicsView : public ComicsView { Q_OBJECT public: - ClassicComicsView(QWidget *parent = 0); + explicit ClassicComicsView(QWidget *parent = nullptr); void setToolBar(QToolBar *toolBar) override; void setModel(ComicModel *model) override; diff --git a/YACReaderLibrary/grid_comics_view.h b/YACReaderLibrary/grid_comics_view.h index 8b39f1d3..7ff0e702 100644 --- a/YACReaderLibrary/grid_comics_view.h +++ b/YACReaderLibrary/grid_comics_view.h @@ -19,8 +19,8 @@ class GridComicsView : public ComicsView { Q_OBJECT public: - explicit GridComicsView(QWidget *parent = 0); - virtual ~GridComicsView(); + explicit GridComicsView(QWidget *parent = nullptr); + ~GridComicsView() override; void setToolBar(QToolBar *toolBar) override; void setModel(ComicModel *model) override; void setCurrentIndex(const QModelIndex &index) override; diff --git a/YACReaderLibrary/info_comics_view.h b/YACReaderLibrary/info_comics_view.h index d4fe38d6..3cc925c8 100644 --- a/YACReaderLibrary/info_comics_view.h +++ b/YACReaderLibrary/info_comics_view.h @@ -29,7 +29,7 @@ public: void focusComicsNavigation(Qt::FocusReason reason) override; public slots: - void setShowMarks(bool show); + void setShowMarks(bool show) override; void selectAll() override; protected slots: From efd9f478caafc6cd5e5b16959561c5dbfd95113b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sat, 13 Mar 2021 16:32:27 +0100 Subject: [PATCH 5/5] Make underlying NSTextField the first responder on setFocus --- custom_widgets/yacreader_macosx_toolbar.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_widgets/yacreader_macosx_toolbar.mm b/custom_widgets/yacreader_macosx_toolbar.mm index 3e9d786a..51ea4d76 100644 --- a/custom_widgets/yacreader_macosx_toolbar.mm +++ b/custom_widgets/yacreader_macosx_toolbar.mm @@ -319,7 +319,8 @@ YACReaderMacOSXSearchLineEdit::YACReaderMacOSXSearchLineEdit() void YACReaderMacOSXSearchLineEdit::setFocus(Qt::FocusReason reason) { Q_UNUSED(reason) - // TODO: implement + + [((NSTextField *)nstextfield) becomeFirstResponder]; } void *YACReaderMacOSXSearchLineEdit::getNSTextField()