From 40ca07f8f88670cf1dba78424e17caa3d98d3caf Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Fri, 12 Feb 2021 19:51:24 +0200 Subject: [PATCH] Extract YACReaderNavigationController::exitSearchMode() --- YACReaderLibrary/library_window.cpp | 9 ++++++++ YACReaderLibrary/library_window.h | 4 ++++ .../yacreader_navigation_controller.cpp | 21 +++++++------------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index a1088e99..ce531308 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -2726,3 +2726,12 @@ void LibraryWindow::updateComicsView(quint64 libraryId, const ComicDB &comic) comicsViewsManager->updateCurrentComicView(); } } + +bool LibraryWindow::exitSearchMode() +{ + if (status != LibraryWindow::Searching) + return false; + searchEdit->clearText(); + clearSearchFilter(); + return true; +} diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 6a4d7d9d..dc92b5bc 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -424,6 +424,10 @@ public slots: void afterLaunchTasks(); private: + //! @brief Exits search mode if it is active. + //! @return true If the search mode was active when this function was called. + bool exitSearchMode(); + // fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309 Qt::WindowFlags previousWindowFlags; QPoint previousPos; diff --git a/YACReaderLibrary/yacreader_navigation_controller.cpp b/YACReaderLibrary/yacreader_navigation_controller.cpp index 0f5766ff..ab2e5c43 100644 --- a/YACReaderLibrary/yacreader_navigation_controller.cpp +++ b/YACReaderLibrary/yacreader_navigation_controller.cpp @@ -34,10 +34,8 @@ void YACReaderNavigationController::selectedFolder(const QModelIndex &mi) // update history libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(modelIndex, YACReaderLibrarySourceContainer::Folder)); - if (libraryWindow->status == LibraryWindow::Searching) { - // when a folder is selected the search mode has to be reset - libraryWindow->searchEdit->clearText(); - libraryWindow->clearSearchFilter(); + // when a folder is selected the search mode has to be reset + if (libraryWindow->exitSearchMode()) { libraryWindow->foldersView->scrollTo(mi, QAbstractItemView::PositionAtTop); libraryWindow->foldersView->setCurrentIndex(mi); } @@ -182,10 +180,9 @@ void YACReaderNavigationController::selectedList(const QModelIndex &mi) // update history libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(modelIndex, YACReaderLibrarySourceContainer::List)); - if (libraryWindow->status == LibraryWindow::Searching) { - // when a list is selected the search mode has to be reset - libraryWindow->searchEdit->clearText(); - libraryWindow->clearSearchFilter(); + // when a list is selected the search mode has to be reset + if (libraryWindow->exitSearchMode()) { + libraryWindow->listsView->scrollTo(mi, QAbstractItemView::PositionAtTop); libraryWindow->listsView->setCurrentIndex(mi); } @@ -212,12 +209,8 @@ void YACReaderNavigationController::reselectCurrentSource() void YACReaderNavigationController::selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer) { // TODO NO searching allowed, just disable backward/forward actions in searching mode - if (libraryWindow->status == LibraryWindow::Searching) { - // when a folder is selected the search mode has to be reset - libraryWindow->searchEdit->clearText(); - libraryWindow->clearSearchFilter(); - } - + // when a folder or a list is selected the search mode has to be reset + libraryWindow->exitSearchMode(); loadIndexFromHistory(sourceContainer); libraryWindow->setToolbarTitle(sourceContainer.getSourceModelIndex()); }