From ff3f24ff9e0e6e0785fdb29cef0d58f232abfc1e Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Fri, 15 Jan 2021 20:12:19 +0100 Subject: Rename DownloadListWidget -> DownloadListView. Clean context menu. --- src/CMakeLists.txt | 2 +- src/downloadlistview.cpp | 419 +++++++++++++++++++++++++++++++++++++++++++++ src/downloadlistview.h | 126 ++++++++++++++ src/downloadlistwidget.cpp | 418 -------------------------------------------- src/downloadlistwidget.h | 126 -------------- src/downloadstab.cpp | 8 +- src/downloadstab.h | 4 +- src/mainwindow.cpp | 1 - src/mainwindow.ui | 12 +- 9 files changed, 558 insertions(+), 558 deletions(-) create mode 100644 src/downloadlistview.cpp create mode 100644 src/downloadlistview.h delete mode 100644 src/downloadlistwidget.cpp delete mode 100644 src/downloadlistwidget.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1092637..a5d15740 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,7 +63,7 @@ add_filter(NAME src/dialogs GROUPS add_filter(NAME src/downloads GROUPS downloadlist - downloadlistwidget + downloadlistview downloadmanager ) diff --git a/src/downloadlistview.cpp b/src/downloadlistview.cpp new file mode 100644 index 00000000..5e49f107 --- /dev/null +++ b/src/downloadlistview.cpp @@ -0,0 +1,419 @@ +/* +Copyright (C) 2012 Sebastian Herbord. All rights reserved. + +This file is part of Mod Organizer. + +Mod Organizer is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Mod Organizer is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Mod Organizer. If not, see . +*/ + +#include "downloadlist.h" +#include "downloadlistview.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace MOBase; + +DownloadProgressDelegate::DownloadProgressDelegate( + DownloadManager* manager, DownloadListView* list) + : QStyledItemDelegate(list), m_Manager(manager), m_List(list) +{ +} + +void DownloadProgressDelegate::paint( + QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QModelIndex sourceIndex; + + if (auto* proxy=dynamic_cast(m_List->model())) { + sourceIndex = proxy->mapToSource(index); + } else { + sourceIndex = index; + } + + bool pendingDownload = (sourceIndex.row() >= m_Manager->numTotalDownloads()); + if (sourceIndex.column() == DownloadList::COL_STATUS && !pendingDownload + && m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_DOWNLOADING) { + QProgressBar progressBar; + progressBar.setProperty("downloadView", option.widget->property("downloadView")); + progressBar.setProperty("downloadProgress", true); + progressBar.resize(option.rect.width(), option.rect.height()); + progressBar.setTextVisible(true); + progressBar.setAlignment(Qt::AlignCenter); + progressBar.setMinimum(0); + progressBar.setMaximum(100); + progressBar.setValue(m_Manager->getProgress(sourceIndex.row()).first); + progressBar.setFormat(m_Manager->getProgress(sourceIndex.row()).second); + progressBar.setStyle(QApplication::style()); + + // paint the background with default delegate first to preserve table cell styling + QStyledItemDelegate::paint(painter, option, index); + + painter->save(); + painter->translate(option.rect.topLeft()); + progressBar.render(painter); + painter->restore(); + } else { + QStyledItemDelegate::paint(painter, option, index); + } +} + +void DownloadListHeader::customResizeSections() +{ + // find the rightmost column that is not hidden + int rightVisible = count() - 1; + while (isSectionHidden(rightVisible) && rightVisible > 0) + rightVisible--; + + // if that column is already squashed, squash others to the right side -- + // otherwise to the left + if (sectionSize(rightVisible) == minimumSectionSize()) { + for (int idx = rightVisible; idx >= 0; idx--) { + if (!isSectionHidden(idx)) { + if (length() != width()) + resizeSection(idx, std::max(sectionSize(idx) + width() - length(), minimumSectionSize())); + else + break; + } + } + } else { + for (int idx = 0; idx <= rightVisible; idx++) { + if (!isSectionHidden(idx)) { + if (length() != width()) + resizeSection(idx, std::max(sectionSize(idx) + width() - length(), minimumSectionSize())); + else + break; + } + } + } +} + +void DownloadListHeader::mouseReleaseEvent(QMouseEvent *event) +{ + QHeaderView::mouseReleaseEvent(event); + customResizeSections(); +} + +DownloadListView::DownloadListView(QWidget *parent) + : QTreeView(parent) +{ + setHeader(new DownloadListHeader(Qt::Horizontal, this)); + + header()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); + header()->setSectionsMovable(true); + header()->setContextMenuPolicy(Qt::CustomContextMenu); + header()->setCascadingSectionResizes(true); + header()->setStretchLastSection(false); + header()->setSectionResizeMode(QHeaderView::Interactive); + header()->setDefaultSectionSize(100); + + setUniformRowHeights(true); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + sortByColumn(1, Qt::DescendingOrder); + + connect(header(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onHeaderCustomContextMenu(QPoint))); + connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClick(QModelIndex))); + connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenu(QPoint))); +} + +DownloadListView::~DownloadListView() +{ +} + +void DownloadListView::setManager(DownloadManager *manager) +{ + m_Manager = manager; + + // hide these columns by default + // + // note that this is overridden by the ini if MO has been started at least + // once before, which is handled in MainWindow::processUpdates() for older + // versions + header()->hideSection(DownloadList::COL_MODNAME); + header()->hideSection(DownloadList::COL_VERSION); + header()->hideSection(DownloadList::COL_ID); + header()->hideSection(DownloadList::COL_SOURCEGAME); +} + +void DownloadListView::setSourceModel(DownloadList *sourceModel) +{ + m_SourceModel = sourceModel; +} + +void DownloadListView::setMetaDisplay(bool metaDisplay) +{ + if (m_SourceModel != nullptr) + m_SourceModel->setMetaDisplay(metaDisplay); +} + +void DownloadListView::onDoubleClick(const QModelIndex &index) +{ + QModelIndex sourceIndex = qobject_cast(model())->mapToSource(index); + if (m_Manager->getState(sourceIndex.row()) >= DownloadManager::STATE_READY) + emit installDownload(sourceIndex.row()); + else if ((m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_PAUSED) + || (m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_PAUSING)) + emit resumeDownload(sourceIndex.row()); +} + +void DownloadListView::onHeaderCustomContextMenu(const QPoint &point) +{ + QMenu menu; + + // display a list of all headers as checkboxes + QAbstractItemModel *model = header()->model(); + for (int i = 1; i < model->columnCount(); ++i) { + QString columnName = model->headerData(i, Qt::Horizontal).toString(); + QCheckBox *checkBox = new QCheckBox(&menu); + checkBox->setText(columnName); + checkBox->setChecked(!header()->isSectionHidden(i)); + QWidgetAction *checkableAction = new QWidgetAction(&menu); + checkableAction->setDefaultWidget(checkBox); + menu.addAction(checkableAction); + } + + menu.exec(header()->viewport()->mapToGlobal(point)); + + // view/hide columns depending on check-state + int i = 1; + for (const QAction *action : menu.actions()) { + const QWidgetAction *widgetAction = qobject_cast(action); + if (widgetAction != nullptr) { + const QCheckBox *checkBox = qobject_cast(widgetAction->defaultWidget()); + if (checkBox != nullptr) { + header()->setSectionHidden(i, !checkBox->isChecked()); + } + } + ++i; + } + + qobject_cast(header())->customResizeSections(); +} + +void DownloadListView::resizeEvent(QResizeEvent *event) +{ + QTreeView::resizeEvent(event); + qobject_cast(header())->customResizeSections(); +} + +void DownloadListView::onCustomContextMenu(const QPoint &point) +{ + QMenu menu(this); + QModelIndex index = indexAt(point); + bool hidden = false; + + try + { + if (index.row() >= 0) { + const int row = qobject_cast(model())->mapToSource(index).row(); + DownloadManager::DownloadState state = m_Manager->getState(row); + + hidden = m_Manager->isHidden(row); + + if (state >= DownloadManager::STATE_READY) { + menu.addAction(tr("Install"), [=] { issueInstall(row); }); + if (m_Manager->isInfoIncomplete(row)) + menu.addAction(tr("Query Info"), [=] { issueQueryInfoMd5(row); }); + else + menu.addAction(tr("Visit on Nexus"), [=] { issueVisitOnNexus(row); }); + menu.addAction(tr("Open File"), [=] { issueOpenFile(row); }); + menu.addAction(tr("Open Meta File"), [=] { issueOpenMetaFile(row); }); + menu.addAction(tr("Reveal in Explorer"), [=] { issueOpenInDownloadsFolder(row); }); + + menu.addSeparator(); + + menu.addAction(tr("Delete..."), [=] { issueDelete(row); }); + if (hidden) + menu.addAction(tr("Un-Hide"), [=] { issueRestoreToView(row); }); + else + menu.addAction(tr("Hide"), [=] { issueRemoveFromView(row); }); + } else if (state == DownloadManager::STATE_DOWNLOADING) { + menu.addAction(tr("Cancel"), [=] { issueCancel(row); }); + menu.addAction(tr("Pause"), [=] { issuePause(row); }); + menu.addAction(tr("Reveal in Explorer"), [=] { issueOpenInDownloadsFolder(row); }); + } + else if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR) + || (state == DownloadManager::STATE_PAUSING)) { + menu.addAction(tr("Delete..."), [=] { issueDelete(row); }); + menu.addAction(tr("Resume"), [=] { issueResume(row); }); + menu.addAction(tr("Reveal in Explorer"), [=] { issueOpenInDownloadsFolder(row); }); + } + + menu.addSeparator(); + } + } catch(std::exception&) + { + // this happens when the download index is not found, ignore it and don't + // display download-specific actions + } + + menu.addAction(tr("Delete Installed Downloads..."), this, SLOT(issueDeleteCompleted())); + menu.addAction(tr("Delete Uninstalled Downloads..."), this, SLOT(issueDeleteUninstalled())); + menu.addAction(tr("Delete All Downloads..."), this, SLOT(issueDeleteAll())); + + menu.addSeparator(); + if (!hidden) { + menu.addAction(tr("Hide Installed..."), this, SLOT(issueRemoveFromViewCompleted())); + menu.addAction(tr("Hide Uninstalled..."), this, SLOT(issueRemoveFromViewUninstalled())); + menu.addAction(tr("Hide All..."), this, SLOT(issueRemoveFromViewAll())); + } else { + menu.addAction(tr("Un-Hide All..."), this, SLOT(issueRestoreToViewAll())); + } + + menu.exec(viewport()->mapToGlobal(point)); +} + +void DownloadListView::issueInstall(int index) +{ + emit installDownload(index); +} + +void DownloadListView::issueQueryInfo(int index) +{ + emit queryInfo(index); +} + +void DownloadListView::issueQueryInfoMd5(int index) +{ + emit queryInfoMd5(index); +} + +void DownloadListView::issueDelete(int index) +{ + const auto r = MOBase::TaskDialog(this, tr("Delete download")) + .main("Are you sure you want to delete this download?") + .content(m_Manager->getFilePath(index)) + .icon(QMessageBox::Question) + .button({tr("Move to the Recycle Bin"), QMessageBox::Yes}) + .button({tr("Cancel"), QMessageBox::Cancel}) + .exec(); + + if (r != QMessageBox::Yes) { + return; + } + + emit removeDownload(index, true); +} + +void DownloadListView::issueRemoveFromView(int index) +{ + log::debug("removing from view: {}", index); + emit removeDownload(index, false); +} + +void DownloadListView::issueRestoreToView(int index) +{ + emit restoreDownload(index); +} + +void DownloadListView::issueRestoreToViewAll() +{ + emit restoreDownload(-1); +} + +void DownloadListView::issueVisitOnNexus(int index) +{ + emit visitOnNexus(index); +} + +void DownloadListView::issueOpenFile(int index) +{ + emit openFile(index); +} + +void DownloadListView::issueOpenMetaFile(int index) { + emit openMetaFile(index); +} + +void DownloadListView::issueOpenInDownloadsFolder(int index) +{ + emit openInDownloadsFolder(index); +} + +void DownloadListView::issueCancel(int index) +{ + emit cancelDownload(index); +} + +void DownloadListView::issuePause(int index) +{ + emit pauseDownload(index); +} + +void DownloadListView::issueResume(int index) +{ + emit resumeDownload(index); +} + +void DownloadListView::issueDeleteAll() +{ + if (QMessageBox::warning(nullptr, tr("Delete Files?"), + tr("This will remove all finished downloads from this list and from disk.\n\nAre you absolutely sure you want to proceed?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + emit removeDownload(-1, true); + } +} + +void DownloadListView::issueDeleteCompleted() +{ + if (QMessageBox::warning(nullptr, tr("Delete Files?"), + tr("This will remove all installed downloads from this list and from disk.\n\nAre you absolutely sure you want to proceed?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + emit removeDownload(-2, true); + } +} + +void DownloadListView::issueDeleteUninstalled() +{ + if (QMessageBox::warning(nullptr, tr("Delete Files?"), + tr("This will remove all uninstalled downloads from this list and from disk.\n\nAre you absolutely sure you want to proceed?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + emit removeDownload(-3, true); + } +} + +void DownloadListView::issueRemoveFromViewAll() +{ + if (QMessageBox::question(nullptr, tr("Hide Files?"), + tr("This will remove all finished downloads from this list (but NOT from disk)."), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + emit removeDownload(-1, false); + } +} + +void DownloadListView::issueRemoveFromViewCompleted() +{ + if (QMessageBox::question(nullptr, tr("Hide Files?"), + tr("This will remove all installed downloads from this list (but NOT from disk)."), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + emit removeDownload(-2, false); + } +} + +void DownloadListView::issueRemoveFromViewUninstalled() +{ + if (QMessageBox::question(nullptr, tr("Hide Files?"), + tr("This will remove all uninstalled downloads from this list (but NOT from disk)."), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + emit removeDownload(-3, false); + } +} diff --git a/src/downloadlistview.h b/src/downloadlistview.h new file mode 100644 index 00000000..0a3e575b --- /dev/null +++ b/src/downloadlistview.h @@ -0,0 +1,126 @@ +/* +Copyright (C) 2012 Sebastian Herbord. All rights reserved. + +This file is part of Mod Organizer. + +Mod Organizer is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Mod Organizer is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Mod Organizer. If not, see . +*/ + +#ifndef DOWNLOADLISTWIDGET_H +#define DOWNLOADLISTWIDGET_H + +#include "downloadmanager.h" +#include "downloadlist.h" +#include +#include +#include +#include +#include +#include +#include + + +namespace Ui { + class DownloadListView; +} + +class DownloadListView; + +class DownloadProgressDelegate : public QStyledItemDelegate +{ + Q_OBJECT + +public: + DownloadProgressDelegate(DownloadManager* manager, DownloadListView* list); + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override; + +private: + DownloadManager* m_Manager; + DownloadListView* m_List; +}; + +class DownloadListHeader : public QHeaderView +{ + Q_OBJECT + +public: + explicit DownloadListHeader(Qt::Orientation orientation, QWidget *parent = nullptr) : QHeaderView(orientation, parent) {} + void customResizeSections(); + +private: + void mouseReleaseEvent(QMouseEvent *event) override; +}; + +class DownloadListView : public QTreeView +{ + Q_OBJECT + +public: + explicit DownloadListView(QWidget *parent = 0); + ~DownloadListView(); + + void setManager(DownloadManager *manager); + void setSourceModel(DownloadList *sourceModel); + void setMetaDisplay(bool metaDisplay); + +signals: + void installDownload(int index); + void queryInfo(int index); + void queryInfoMd5(int index); + void removeDownload(int index, bool deleteFile); + void restoreDownload(int index); + void cancelDownload(int index); + void pauseDownload(int index); + void resumeDownload(int index); + void visitOnNexus(int index); + void openFile(int index); + void openMetaFile(int index); + void openInDownloadsFolder(int index); + +private slots: + void onDoubleClick(const QModelIndex& index); + void onCustomContextMenu(const QPoint& point); + void onHeaderCustomContextMenu(const QPoint& point); + + void issueInstall(int index); + void issueDelete(int index); + void issueRemoveFromView(int index); + void issueRestoreToView(int index); + void issueRestoreToViewAll(); + void issueVisitOnNexus(int index); + void issueOpenFile(int index); + void issueOpenMetaFile(int index); + void issueOpenInDownloadsFolder(int index); + void issueCancel(int index); + void issuePause(int index); + void issueResume(int index); + void issueDeleteAll(); + void issueDeleteCompleted(); + void issueDeleteUninstalled(); + void issueRemoveFromViewAll(); + void issueRemoveFromViewCompleted(); + void issueRemoveFromViewUninstalled(); + void issueQueryInfo(int index); + void issueQueryInfoMd5(int index); + +private: + DownloadManager *m_Manager; + DownloadList *m_SourceModel = 0; + + void resizeEvent(QResizeEvent *event); +}; + +#endif // DOWNLOADLISTWIDGET_H diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp deleted file mode 100644 index 22e3a3b9..00000000 --- a/src/downloadlistwidget.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/* -Copyright (C) 2012 Sebastian Herbord. All rights reserved. - -This file is part of Mod Organizer. - -Mod Organizer is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Mod Organizer is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Mod Organizer. If not, see . -*/ - -#include "downloadlist.h" -#include "downloadlistwidget.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace MOBase; - -DownloadProgressDelegate::DownloadProgressDelegate( - DownloadManager* manager, DownloadListWidget* list) - : QStyledItemDelegate(list), m_Manager(manager), m_List(list) -{ -} - -void DownloadProgressDelegate::paint( - QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QModelIndex sourceIndex; - - if (auto* proxy=dynamic_cast(m_List->model())) { - sourceIndex = proxy->mapToSource(index); - } else { - sourceIndex = index; - } - - bool pendingDownload = (sourceIndex.row() >= m_Manager->numTotalDownloads()); - if (sourceIndex.column() == DownloadList::COL_STATUS && !pendingDownload - && m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_DOWNLOADING) { - QProgressBar progressBar; - progressBar.setProperty("downloadView", option.widget->property("downloadView")); - progressBar.setProperty("downloadProgress", true); - progressBar.resize(option.rect.width(), option.rect.height()); - progressBar.setTextVisible(true); - progressBar.setAlignment(Qt::AlignCenter); - progressBar.setMinimum(0); - progressBar.setMaximum(100); - progressBar.setValue(m_Manager->getProgress(sourceIndex.row()).first); - progressBar.setFormat(m_Manager->getProgress(sourceIndex.row()).second); - progressBar.setStyle(QApplication::style()); - - // paint the background with default delegate first to preserve table cell styling - QStyledItemDelegate::paint(painter, option, index); - - painter->save(); - painter->translate(option.rect.topLeft()); - progressBar.render(painter); - painter->restore(); - } else { - QStyledItemDelegate::paint(painter, option, index); - } -} - -void DownloadListHeader::customResizeSections() -{ - // find the rightmost column that is not hidden - int rightVisible = count() - 1; - while (isSectionHidden(rightVisible) && rightVisible > 0) - rightVisible--; - - // if that column is already squashed, squash others to the right side -- - // otherwise to the left - if (sectionSize(rightVisible) == minimumSectionSize()) { - for (int idx = rightVisible; idx >= 0; idx--) { - if (!isSectionHidden(idx)) { - if (length() != width()) - resizeSection(idx, std::max(sectionSize(idx) + width() - length(), minimumSectionSize())); - else - break; - } - } - } else { - for (int idx = 0; idx <= rightVisible; idx++) { - if (!isSectionHidden(idx)) { - if (length() != width()) - resizeSection(idx, std::max(sectionSize(idx) + width() - length(), minimumSectionSize())); - else - break; - } - } - } -} - -void DownloadListHeader::mouseReleaseEvent(QMouseEvent *event) -{ - QHeaderView::mouseReleaseEvent(event); - customResizeSections(); -} - -DownloadListWidget::DownloadListWidget(QWidget *parent) - : QTreeView(parent) -{ - setHeader(new DownloadListHeader(Qt::Horizontal, this)); - - header()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); - header()->setSectionsMovable(true); - header()->setContextMenuPolicy(Qt::CustomContextMenu); - header()->setCascadingSectionResizes(true); - header()->setStretchLastSection(false); - header()->setSectionResizeMode(QHeaderView::Interactive); - header()->setDefaultSectionSize(100); - - setUniformRowHeights(true); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - sortByColumn(1, Qt::DescendingOrder); - - connect(header(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onHeaderCustomContextMenu(QPoint))); - connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClick(QModelIndex))); - connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenu(QPoint))); -} - -DownloadListWidget::~DownloadListWidget() -{ -} - -void DownloadListWidget::setManager(DownloadManager *manager) -{ - m_Manager = manager; - - // hide these columns by default - // - // note that this is overridden by the ini if MO has been started at least - // once before, which is handled in MainWindow::processUpdates() for older - // versions - header()->hideSection(DownloadList::COL_MODNAME); - header()->hideSection(DownloadList::COL_VERSION); - header()->hideSection(DownloadList::COL_ID); - header()->hideSection(DownloadList::COL_SOURCEGAME); -} - -void DownloadListWidget::setSourceModel(DownloadList *sourceModel) -{ - m_SourceModel = sourceModel; -} - -void DownloadListWidget::setMetaDisplay(bool metaDisplay) -{ - if (m_SourceModel != nullptr) - m_SourceModel->setMetaDisplay(metaDisplay); -} - -void DownloadListWidget::onDoubleClick(const QModelIndex &index) -{ - QModelIndex sourceIndex = qobject_cast(model())->mapToSource(index); - if (m_Manager->getState(sourceIndex.row()) >= DownloadManager::STATE_READY) - emit installDownload(sourceIndex.row()); - else if ((m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_PAUSED) - || (m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_PAUSING)) - emit resumeDownload(sourceIndex.row()); -} - -void DownloadListWidget::onHeaderCustomContextMenu(const QPoint &point) -{ - QMenu menu; - - // display a list of all headers as checkboxes - QAbstractItemModel *model = header()->model(); - for (int i = 1; i < model->columnCount(); ++i) { - QString columnName = model->headerData(i, Qt::Horizontal).toString(); - QCheckBox *checkBox = new QCheckBox(&menu); - checkBox->setText(columnName); - checkBox->setChecked(!header()->isSectionHidden(i)); - QWidgetAction *checkableAction = new QWidgetAction(&menu); - checkableAction->setDefaultWidget(checkBox); - menu.addAction(checkableAction); - } - - menu.exec(header()->viewport()->mapToGlobal(point)); - - // view/hide columns depending on check-state - int i = 1; - for (const QAction *action : menu.actions()) { - const QWidgetAction *widgetAction = qobject_cast(action); - if (widgetAction != nullptr) { - const QCheckBox *checkBox = qobject_cast(widgetAction->defaultWidget()); - if (checkBox != nullptr) { - header()->setSectionHidden(i, !checkBox->isChecked()); - } - } - ++i; - } - - qobject_cast(header())->customResizeSections(); -} - -void DownloadListWidget::resizeEvent(QResizeEvent *event) -{ - QTreeView::resizeEvent(event); - qobject_cast(header())->customResizeSections(); -} - -void DownloadListWidget::onCustomContextMenu(const QPoint &point) -{ - QMenu menu(this); - QModelIndex index = indexAt(point); - bool hidden = false; - - try - { - if (index.row() >= 0) { - m_ContextRow = qobject_cast(model())->mapToSource(index).row(); - DownloadManager::DownloadState state = m_Manager->getState(m_ContextRow); - - hidden = m_Manager->isHidden(m_ContextRow); - - if (state >= DownloadManager::STATE_READY) { - menu.addAction(tr("Install"), this, SLOT(issueInstall())); - if (m_Manager->isInfoIncomplete(m_ContextRow)) - menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfoMd5())); - else - menu.addAction(tr("Visit on Nexus"), this, SLOT(issueVisitOnNexus())); - menu.addAction(tr("Open File"), this, SLOT(issueOpenFile())); - menu.addAction(tr("Open Meta File"), this, SLOT(issueOpenMetaFile())); - menu.addAction(tr("Reveal in Explorer"), this, SLOT(issueOpenInDownloadsFolder())); - - menu.addSeparator(); - - menu.addAction(tr("Delete..."), this, SLOT(issueDelete())); - if (hidden) - menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); - else - menu.addAction(tr("Hide"), this, SLOT(issueRemoveFromView())); - } else if (state == DownloadManager::STATE_DOWNLOADING) { - menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); - menu.addAction(tr("Pause"), this, SLOT(issuePause())); - menu.addAction(tr("Reveal in Explorer"), this, SLOT(issueOpenInDownloadsFolder())); - } else if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR) - || (state == DownloadManager::STATE_PAUSING)) { - menu.addAction(tr("Delete..."), this, SLOT(issueDelete())); - menu.addAction(tr("Resume"), this, SLOT(issueResume())); - menu.addAction(tr("Reveal in Explorer"), this, SLOT(issueOpenInDownloadsFolder())); - } - - menu.addSeparator(); - } - } catch(std::exception&) - { - // this happens when the download index is not found, ignore it and don't - // display download-specific actions - } - - menu.addAction(tr("Delete Installed Downloads..."), this, SLOT(issueDeleteCompleted())); - menu.addAction(tr("Delete Uninstalled Downloads..."), this, SLOT(issueDeleteUninstalled())); - menu.addAction(tr("Delete All Downloads..."), this, SLOT(issueDeleteAll())); - - menu.addSeparator(); - if (!hidden) { - menu.addAction(tr("Hide Installed..."), this, SLOT(issueRemoveFromViewCompleted())); - menu.addAction(tr("Hide Uninstalled..."), this, SLOT(issueRemoveFromViewUninstalled())); - menu.addAction(tr("Hide All..."), this, SLOT(issueRemoveFromViewAll())); - } else { - menu.addAction(tr("Un-Hide All..."), this, SLOT(issueRestoreToViewAll())); - } - - menu.exec(viewport()->mapToGlobal(point)); -} - -void DownloadListWidget::issueInstall() -{ - emit installDownload(m_ContextRow); -} - -void DownloadListWidget::issueQueryInfo() -{ - emit queryInfo(m_ContextRow); -} - -void DownloadListWidget::issueQueryInfoMd5() -{ - emit queryInfoMd5(m_ContextRow); -} - -void DownloadListWidget::issueDelete() -{ - const auto r = MOBase::TaskDialog(this, tr("Delete download")) - .main("Are you sure you want to delete this download?") - .content(m_Manager->getFilePath(m_ContextRow)) - .icon(QMessageBox::Question) - .button({tr("Move to the Recycle Bin"), QMessageBox::Yes}) - .button({tr("Cancel"), QMessageBox::Cancel}) - .exec(); - - if (r != QMessageBox::Yes) { - return; - } - - emit removeDownload(m_ContextRow, true); -} - -void DownloadListWidget::issueRemoveFromView() -{ - log::debug("removing from view: {}", m_ContextRow); - emit removeDownload(m_ContextRow, false); -} - -void DownloadListWidget::issueRestoreToView() -{ - emit restoreDownload(m_ContextRow); -} - -void DownloadListWidget::issueRestoreToViewAll() -{ - emit restoreDownload(-1); -} - -void DownloadListWidget::issueVisitOnNexus() -{ - emit visitOnNexus(m_ContextRow); -} - -void DownloadListWidget::issueOpenFile() -{ - emit openFile(m_ContextRow); -} - -void DownloadListWidget::issueOpenMetaFile() { - emit openMetaFile(m_ContextRow); -} - -void DownloadListWidget::issueOpenInDownloadsFolder() -{ - emit openInDownloadsFolder(m_ContextRow); -} - -void DownloadListWidget::issueCancel() -{ - emit cancelDownload(m_ContextRow); -} - -void DownloadListWidget::issuePause() -{ - emit pauseDownload(m_ContextRow); -} - -void DownloadListWidget::issueResume() -{ - emit resumeDownload(m_ContextRow); -} - -void DownloadListWidget::issueDeleteAll() -{ - if (QMessageBox::warning(nullptr, tr("Delete Files?"), - tr("This will remove all finished downloads from this list and from disk.\n\nAre you absolutely sure you want to proceed?"), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - emit removeDownload(-1, true); - } -} - -void DownloadListWidget::issueDeleteCompleted() -{ - if (QMessageBox::warning(nullptr, tr("Delete Files?"), - tr("This will remove all installed downloads from this list and from disk.\n\nAre you absolutely sure you want to proceed?"), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - emit removeDownload(-2, true); - } -} - -void DownloadListWidget::issueDeleteUninstalled() -{ - if (QMessageBox::warning(nullptr, tr("Delete Files?"), - tr("This will remove all uninstalled downloads from this list and from disk.\n\nAre you absolutely sure you want to proceed?"), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - emit removeDownload(-3, true); - } -} - -void DownloadListWidget::issueRemoveFromViewAll() -{ - if (QMessageBox::question(nullptr, tr("Hide Files?"), - tr("This will remove all finished downloads from this list (but NOT from disk)."), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - emit removeDownload(-1, false); - } -} - -void DownloadListWidget::issueRemoveFromViewCompleted() -{ - if (QMessageBox::question(nullptr, tr("Hide Files?"), - tr("This will remove all installed downloads from this list (but NOT from disk)."), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - emit removeDownload(-2, false); - } -} - -void DownloadListWidget::issueRemoveFromViewUninstalled() -{ - if (QMessageBox::question(nullptr, tr("Hide Files?"), - tr("This will remove all uninstalled downloads from this list (but NOT from disk)."), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - emit removeDownload(-3, false); - } -} diff --git a/src/downloadlistwidget.h b/src/downloadlistwidget.h deleted file mode 100644 index 64e1a6e8..00000000 --- a/src/downloadlistwidget.h +++ /dev/null @@ -1,126 +0,0 @@ -/* -Copyright (C) 2012 Sebastian Herbord. All rights reserved. - -This file is part of Mod Organizer. - -Mod Organizer is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Mod Organizer is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Mod Organizer. If not, see . -*/ - -#ifndef DOWNLOADLISTWIDGET_H -#define DOWNLOADLISTWIDGET_H - -#include "downloadmanager.h" -#include "downloadlist.h" -#include -#include -#include -#include -#include -#include -#include - - -namespace Ui { - class DownloadListWidget; -} - -class DownloadListWidget; - -class DownloadProgressDelegate : public QStyledItemDelegate -{ - Q_OBJECT - -public: - DownloadProgressDelegate(DownloadManager* manager, DownloadListWidget* list); - - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const override; - -private: - DownloadManager* m_Manager; - DownloadListWidget* m_List; -}; - -class DownloadListHeader : public QHeaderView -{ - Q_OBJECT - -public: - explicit DownloadListHeader(Qt::Orientation orientation, QWidget *parent = nullptr) : QHeaderView(orientation, parent) {} - void customResizeSections(); - -private: - void mouseReleaseEvent(QMouseEvent *event) override; -}; - -class DownloadListWidget : public QTreeView -{ - Q_OBJECT - -public: - explicit DownloadListWidget(QWidget *parent = 0); - ~DownloadListWidget(); - - void setManager(DownloadManager *manager); - void setSourceModel(DownloadList *sourceModel); - void setMetaDisplay(bool metaDisplay); - -signals: - void installDownload(int index); - void queryInfo(int index); - void queryInfoMd5(int index); - void removeDownload(int index, bool deleteFile); - void restoreDownload(int index); - void cancelDownload(int index); - void pauseDownload(int index); - void resumeDownload(int index); - void visitOnNexus(int index); - void openFile(int index); - void openMetaFile(int index); - void openInDownloadsFolder(int index); - -private slots: - void onDoubleClick(const QModelIndex &index); - void onCustomContextMenu(const QPoint &point); - void onHeaderCustomContextMenu(const QPoint &point); - void issueInstall(); - void issueDelete(); - void issueRemoveFromView(); - void issueRestoreToView(); - void issueRestoreToViewAll(); - void issueVisitOnNexus(); - void issueOpenFile(); - void issueOpenMetaFile(); - void issueOpenInDownloadsFolder(); - void issueCancel(); - void issuePause(); - void issueResume(); - void issueDeleteAll(); - void issueDeleteCompleted(); - void issueDeleteUninstalled(); - void issueRemoveFromViewAll(); - void issueRemoveFromViewCompleted(); - void issueRemoveFromViewUninstalled(); - void issueQueryInfo(); - void issueQueryInfoMd5(); - -private: - DownloadManager *m_Manager; - DownloadList *m_SourceModel = 0; - int m_ContextRow; - - void resizeEvent(QResizeEvent *event); -}; - -#endif // DOWNLOADLISTWIDGET_H diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp index a0602ede..ab7a1c9a 100644 --- a/src/downloadstab.cpp +++ b/src/downloadstab.cpp @@ -1,6 +1,6 @@ #include "downloadstab.h" #include "downloadlist.h" -#include "downloadlistwidget.h" +#include "downloadlistview.h" #include "organizercore.h" #include "ui_mainwindow.h" @@ -37,7 +37,7 @@ DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) connect(ui.list, SIGNAL(restoreDownload(int)), m_core.downloadManager(), SLOT(restoreDownload(int))); connect(ui.list, SIGNAL(cancelDownload(int)), m_core.downloadManager(), SLOT(cancelDownload(int))); connect(ui.list, SIGNAL(pauseDownload(int)), m_core.downloadManager(), SLOT(pauseDownload(int))); - connect(ui.list, &DownloadListWidget::resumeDownload, [&](int i){ resumeDownload(i); }); + connect(ui.list, &DownloadListView::resumeDownload, [&](int i){ resumeDownload(i); }); } void DownloadsTab::update() @@ -50,10 +50,10 @@ void DownloadsTab::update() // set the view attribute and default row sizes if (m_core.settings().interface().compactDownloads()) { ui.list->setProperty("downloadView", "compact"); - ui.list->setStyleSheet("DownloadListWidget::item { padding: 4px 2px; }"); + ui.list->setStyleSheet("DownloadListView::item { padding: 4px 2px; }"); } else { ui.list->setProperty("downloadView", "standard"); - ui.list->setStyleSheet("DownloadListWidget::item { padding: 16px 4px; }"); + ui.list->setStyleSheet("DownloadListView::item { padding: 16px 4px; }"); } ui.list->setMetaDisplay(m_core.settings().interface().metaDownloads()); diff --git a/src/downloadstab.h b/src/downloadstab.h index ac0cf0e2..f39f4ba5 100644 --- a/src/downloadstab.h +++ b/src/downloadstab.h @@ -5,7 +5,7 @@ namespace Ui { class MainWindow; } class OrganizerCore; -class DownloadListWidget; +class DownloadListView; class DownloadsTab : public QObject { @@ -20,7 +20,7 @@ private: struct DownloadsTabUi { QPushButton* refresh; - DownloadListWidget* list; + DownloadListView* list; QCheckBox* showHidden; QLineEdit* filter; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c9824a24..9c049efa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -46,7 +46,6 @@ along with Mod Organizer. If not, see . #include "categoriesdialog.h" #include "overwriteinfodialog.h" #include "downloadlist.h" -#include "downloadlistwidget.h" #include "messagedialog.h" #include "installationmanager.h" #include "motddialog.h" diff --git a/src/mainwindow.ui b/src/mainwindow.ui index a0900542..4317b6c0 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1282,7 +1282,7 @@ p, li { white-space: pre-wrap; } - + 320 @@ -1941,11 +1941,6 @@ p, li { white-space: pre-wrap; } QLCDNumber
lcdnumber.h
- - DownloadListWidget - QTreeView -
downloadlistwidget.h
-
MOBase::SortableTreeWidget QWidget @@ -1961,6 +1956,11 @@ p, li { white-space: pre-wrap; } QStatusBar
statusbar.h
+ + DownloadListView + QTreeView +
downloadlistview.h
+
-- cgit v1.3.1