Fix keyboard search

This commit is contained in:
reionwong 2021-09-28 12:00:19 +08:00
parent fefbe8a738
commit 3a4257c51f
6 changed files with 33 additions and 40 deletions

View file

@ -70,7 +70,8 @@ bool ShortCut::eventFilter(QObject *obj, QEvent *e)
emit refresh(); emit refresh();
} else if (keyEvent->key() >= Qt::Key_A && keyEvent->key() <= Qt::Key_Z) { } else if (keyEvent->key() >= Qt::Key_A && keyEvent->key() <= Qt::Key_Z) {
// Handle select // Handle select
KeyboardSearchManager::self()->addKeys(keyEvent->text()); // KeyboardSearchManager::self()->addKeys(keyEvent->text());
emit keyPressed(keyEvent->text());
keyEvent->ignore(); keyEvent->ignore();
} }
} }

View file

@ -44,6 +44,7 @@ signals:
void selectAll(); void selectAll();
void backspace(); void backspace();
void deleteFile(); void deleteFile();
void keyPressed(const QString &text);
protected: protected:
bool eventFilter(QObject *obj, QEvent *e) override; bool eventFilter(QObject *obj, QEvent *e) override;

View file

@ -90,7 +90,6 @@ FolderModel::FolderModel(QObject *parent)
, m_viewAdapter(nullptr) , m_viewAdapter(nullptr)
, m_mimeAppManager(MimeAppManager::self()) , m_mimeAppManager(MimeAppManager::self())
, m_sizeJob(nullptr) , m_sizeJob(nullptr)
, m_keyboardSearchManager(KeyboardSearchManager::self())
{ {
QSettings settings("cutefishos", qApp->applicationName()); QSettings settings("cutefishos", qApp->applicationName());
m_showHiddenFiles = settings.value("showHiddenFiles", false).toBool(); m_showHiddenFiles = settings.value("showHiddenFiles", false).toBool();
@ -120,9 +119,6 @@ FolderModel::FolderModel(QObject *parent)
connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SIGNAL(countChanged())); connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SIGNAL(countChanged()));
connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SIGNAL(countChanged())); connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SIGNAL(countChanged()));
connect(this, SIGNAL(modelReset()), SIGNAL(countChanged())); connect(this, SIGNAL(modelReset()), SIGNAL(countChanged()));
connect(m_keyboardSearchManager, &KeyboardSearchManager::searchTextChanged,
this, &FolderModel::keyboardSearchChanged);
} }
FolderModel::~FolderModel() FolderModel::~FolderModel()
@ -1164,6 +1160,29 @@ void FolderModel::updateSelectedItemsSize()
{ {
} }
void FolderModel::keyboardSearch(const QString &text)
{
if (rowCount() == 0)
return;
int index;
int currentIndex = -1;
if (m_selectionModel->hasSelection()) {
currentIndex = m_selectionModel->selectedIndexes().first().row();
}
index = indexForKeyboardSearch(text, (currentIndex + 1) % rowCount());
if (index < 0 || currentIndex == index)
return;
if (index >= 0) {
clearSelection();
setSelected(index);
}
}
void FolderModel::restoreFromTrash() void FolderModel::restoreFromTrash()
{ {
if (!m_selectionModel->hasSelection()) if (!m_selectionModel->hasSelection())
@ -1298,37 +1317,6 @@ void FolderModel::dragSelectedInternal(int x, int y)
} }
} }
void FolderModel::keyboardSearchChanged(const QString &text, bool searchFromNextItem)
{
Q_UNUSED(searchFromNextItem);
if (rowCount() == 0)
return;
int index;
int currentIndex = -1;
if (m_selectionModel->hasSelection()) {
currentIndex = m_selectionModel->selectedIndexes().first().row();
}
// if (searchFromNextItem) {
// index = indexForKeyboardSearch(text, (currentIndex + 1) % rowCount());
// } else {
// index = indexForKeyboardSearch(text, 0);
// }
index = indexForKeyboardSearch(text, (currentIndex + 1) % rowCount());
if (index < 0 || currentIndex == index)
return;
if (index >= 0) {
clearSelection();
setSelected(index);
}
}
bool FolderModel::isSupportThumbnails(const QString &mimeType) const bool FolderModel::isSupportThumbnails(const QString &mimeType) const
{ {
const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web", const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web",

View file

@ -26,7 +26,6 @@
#define FOLDERMODEL_H #define FOLDERMODEL_H
#include "../widgets/itemviewadapter.h" #include "../widgets/itemviewadapter.h"
#include "../helper/keyboardsearchmanager.h"
#include "../helper/pathhistory.h" #include "../helper/pathhistory.h"
#include "../mimetype/mimeappmanager.h" #include "../mimetype/mimeappmanager.h"
@ -207,6 +206,7 @@ public:
Q_INVOKABLE void openDeleteDialog(); Q_INVOKABLE void openDeleteDialog();
Q_INVOKABLE void updateSelectedItemsSize(); Q_INVOKABLE void updateSelectedItemsSize();
Q_INVOKABLE void keyboardSearch(const QString &text);
void restoreFromTrash(); void restoreFromTrash();
@ -242,7 +242,6 @@ signals:
private slots: private slots:
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void dragSelectedInternal(int x, int y); void dragSelectedInternal(int x, int y);
void keyboardSearchChanged(const QString &text, bool searchFromNextItem);
private: private:
void invalidateIfComplete(); void invalidateIfComplete();
@ -299,8 +298,6 @@ private:
MimeAppManager *m_mimeAppManager; MimeAppManager *m_mimeAppManager;
CFileSizeJob *m_sizeJob; CFileSizeJob *m_sizeJob;
KeyboardSearchManager *m_keyboardSearchManager;
}; };
#endif // FOLDERMODEL_H #endif // FOLDERMODEL_H

View file

@ -134,6 +134,9 @@ Item {
onDeleteFile: { onDeleteFile: {
dirModel.keyDeletePress() dirModel.keyDeletePress()
} }
onKeyPressed: {
dirModel.keyboardSearch(text)
}
} }
Component { Component {

View file

@ -394,6 +394,9 @@ Item {
onRefresh: { onRefresh: {
dirModel.refresh() dirModel.refresh()
} }
onKeyPressed: {
dirModel.keyboardSearch(text)
}
} }
function openUrl(url) { function openUrl(url) {