diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-15 20:20:12 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-15 20:23:23 +0100 |
| commit | f28b501b30d13c581eaea72f1aeebc0dc4039cf3 (patch) | |
| tree | 45e477c27ef8ed5daeb9f061dc7bd493365f2d66 | |
| parent | 417dbff2de57ff3c62685d0ab4f47454d543ed8f (diff) | |
Handle enter and delete on download list.
| -rw-r--r-- | src/downloadlistview.cpp | 42 | ||||
| -rw-r--r-- | src/downloadlistview.h | 3 |
2 files changed, 41 insertions, 4 deletions
diff --git a/src/downloadlistview.cpp b/src/downloadlistview.cpp index 7f9516ee..a1f544a8 100644 --- a/src/downloadlistview.cpp +++ b/src/downloadlistview.cpp @@ -221,8 +221,7 @@ void DownloadListView::onCustomContextMenu(const QPoint &point) QModelIndex index = indexAt(point);
bool hidden = false;
- try
- {
+ try {
if (index.row() >= 0) {
const int row = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(index).row();
DownloadManager::DownloadState state = m_Manager->getState(row);
@@ -260,8 +259,8 @@ void DownloadListView::onCustomContextMenu(const QPoint &point) menu.addSeparator();
}
- } catch(std::exception&)
- {
+ }
+ catch(std::exception&) {
// this happens when the download index is not found, ignore it and don't
// display download-specific actions
}
@@ -282,6 +281,41 @@ void DownloadListView::onCustomContextMenu(const QPoint &point) menu.exec(viewport()->mapToGlobal(point));
}
+void DownloadListView::keyPressEvent(QKeyEvent* event)
+{
+ if (selectionModel()->hasSelection()) {
+ const int row = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(currentIndex()).row();
+ auto state = m_Manager->getState(row);
+ if (state >= DownloadManager::STATE_READY) {
+ if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
+ issueInstall(row);
+ }
+ else if (event->key() == Qt::Key_Delete) {
+ issueDelete(row);
+ }
+ }
+ else if (state == DownloadManager::STATE_DOWNLOADING) {
+ if (event->key() == Qt::Key_Delete) {
+ issueCancel(row);
+ }
+ else if (event->key() == Qt::Key_Space) {
+ issuePause(event->key());
+ }
+ }
+ else if (state == DownloadManager::STATE_PAUSED
+ || state == DownloadManager::STATE_ERROR
+ || state == DownloadManager::STATE_PAUSING) {
+ if (event->key() == Qt::Key_Delete) {
+ issueDelete(row);
+ }
+ else if (event->key() == Qt::Key_Space) {
+ issueResume(row);
+ }
+ }
+ }
+ QTreeView::keyPressEvent(event);
+}
+
void DownloadListView::issueInstall(int index)
{
emit installDownload(index);
diff --git a/src/downloadlistview.h b/src/downloadlistview.h index 0a3e575b..050c869f 100644 --- a/src/downloadlistview.h +++ b/src/downloadlistview.h @@ -90,6 +90,9 @@ signals: void openMetaFile(int index);
void openInDownloadsFolder(int index);
+protected:
+ void keyPressEvent(QKeyEvent* event) override;
+
private slots:
void onDoubleClick(const QModelIndex& index);
void onCustomContextMenu(const QPoint& point);
|
