summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/downloadlistview.cpp42
-rw-r--r--src/downloadlistview.h3
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);