Fix clicking on the folders treeview when it shown results from search

This was a bug introduced when support for folder navigation using the keyboard was added.
This commit is contained in:
Luis Ángel San Martín 2022-03-28 22:32:52 +02:00
parent 9e9f035f35
commit 4c54f2a07c
3 changed files with 19 additions and 2 deletions

View File

@ -263,6 +263,7 @@ void YACReaderNavigationController::loadPreviousStatus()
void YACReaderNavigationController::setupConnections()
{
connect(libraryWindow->foldersView, &YACReaderTreeView::currentIndexChanged, this, &YACReaderNavigationController::selectedFolder);
connect(libraryWindow->foldersView, &YACReaderTreeView::clicked, this, &YACReaderNavigationController::selectedFolder);
connect(libraryWindow->listsView, &QAbstractItemView::clicked, this, &YACReaderNavigationController::selectedList);
connect(libraryWindow->historyController, &YACReaderHistoryController::modelIndexSelected, this, &YACReaderNavigationController::selectedIndexFromHistory);
connect(comicsViewsManager->emptyFolderWidget, &EmptyFolderWidget::subfolderSelected, this, &YACReaderNavigationController::selectSubfolder);

View File

@ -1,7 +1,7 @@
#include "yacreader_treeview.h"
YACReaderTreeView::YACReaderTreeView(QWidget *parent)
: QTreeView(parent)
: QTreeView(parent), clicking(false)
{
setAcceptDrops(true);
setDragDropMode(QAbstractItemView::DropOnly);
@ -54,6 +54,8 @@ YACReaderTreeView::YACReaderTreeView(QWidget *parent)
void YACReaderTreeView::mousePressEvent(QMouseEvent *event)
{
clicking = true;
QTreeView::mousePressEvent(event);
QModelIndex destinationIndex = indexAt(event->pos());
@ -63,6 +65,13 @@ void YACReaderTreeView::mousePressEvent(QMouseEvent *event)
}
}
void YACReaderTreeView::mouseReleaseEvent(QMouseEvent *event)
{
QTreeView::mouseReleaseEvent(event);
clicking = false;
}
void YACReaderTreeView::expandCurrent()
{
QModelIndex index = indexAt(expandPos);
@ -112,5 +121,10 @@ void YACReaderTreeView::currentChanged(const QModelIndex &current, const QModelI
{
QTreeView::currentChanged(current, previous);
// This is a custom signal emitted to ensure that we know when an item in the tree view is selected (e.g. when keyboard navigation is used)
// By default Qt calls currentChanged while the left mouse button is pressed down an you move the mouse around,
// this causes troubles when the tree view is showing a filtered model and the model changes under the mouse cursor (e.g. after clicking on an item when the view is showing search results)
// so this view filters `currentIndexChanged` calls when the mouse is being pressed down.
if (!clicking)
emit currentIndexChanged(current);
}

View File

@ -9,6 +9,7 @@ class YACReaderTreeView : public QTreeView
public:
explicit YACReaderTreeView(QWidget *parent = 0);
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
signals:
void currentIndexChanged(const QModelIndex &);
protected slots:
@ -28,6 +29,7 @@ protected:
QTimer expandTimer;
QTimer t;
QPoint expandPos;
boolean clicking;
};
#endif // YACREADER_TREEVIEW_H