diff options
| author | LostDragonist <lost.dragonist@gmail.com> | 2019-05-03 21:32:33 -0500 |
|---|---|---|
| committer | LostDragonist <lost.dragonist@gmail.com> | 2019-05-03 21:32:33 -0500 |
| commit | 179a73857125ee604f42b0d5c2d765183c86d2c7 (patch) | |
| tree | b9b3f9d62bd5640de839d150a53ab8ef119dab9c /src/downloadlistwidget.cpp | |
| parent | e2b799bd6b5cfd51969fefd1dab5e5b1b7e5f81c (diff) | |
| parent | 907c5468424b48774f5da2a6b5f96f26590987b0 (diff) | |
Merge pull request #695 from ModOrganizer2/Develop
Stage for Release 2.2.0
Diffstat (limited to 'src/downloadlistwidget.cpp')
| -rw-r--r-- | src/downloadlistwidget.cpp | 476 |
1 files changed, 206 insertions, 270 deletions
diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 34a90534..f0c4da1a 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -17,287 +17,302 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "downloadlist.h"
#include "downloadlistwidget.h"
-#include "ui_downloadlistwidget.h"
#include <QPainter>
#include <QMouseEvent>
#include <QMenu>
#include <QMessageBox>
#include <QSortFilterProxyModel>
+#include <QApplication>
+#include <QHeaderView>
+#include <QCheckBox>
+#include <QWidgetAction>
-
-DownloadListWidget::DownloadListWidget(QWidget *parent)
- : QWidget(parent), ui(new Ui::DownloadListWidget)
+void DownloadProgressDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
- ui->setupUi(this);
-}
+ QModelIndex sourceIndex = m_SortProxy->mapToSource(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);
-DownloadListWidget::~DownloadListWidget()
+ painter->save();
+ painter->translate(option.rect.topLeft());
+ progressBar.render(painter);
+ painter->restore();
+ } else {
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+}
+
+void DownloadListHeader::customResizeSections()
{
- delete ui;
+ // 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();
+}
-DownloadListWidgetDelegate::DownloadListWidgetDelegate(DownloadManager *manager, bool metaDisplay, QTreeView *view, QObject *parent)
- : QItemDelegate(parent)
- , m_Manager(manager)
- , m_MetaDisplay(metaDisplay)
- , m_ItemWidget(new DownloadListWidget)
- , m_ContextRow(0)
- , m_View(view)
+DownloadListWidget::DownloadListWidget(QWidget *parent)
+ : QTreeView(parent)
{
- m_NameLabel = m_ItemWidget->findChild<QLabel*>("nameLabel");
- m_SizeLabel = m_ItemWidget->findChild<QLabel*>("sizeLabel");
- m_Progress = m_ItemWidget->findChild<QProgressBar*>("downloadProgress");
- m_InstallLabel = m_ItemWidget->findChild<QLabel*>("installLabel");
+ setHeader(new DownloadListHeader(Qt::Horizontal, this));
- m_InstallLabel->setVisible(false);
- m_Progress->setTextVisible(true);
+ header()->setSectionsMovable(true);
+ header()->setContextMenuPolicy(Qt::CustomContextMenu);
+ header()->setCascadingSectionResizes(true);
+ header()->setStretchLastSection(false);
+ header()->setSectionResizeMode(QHeaderView::Interactive);
+ header()->setDefaultSectionSize(100);
- connect(manager, SIGNAL(stateChanged(int,DownloadManager::DownloadState)), this, SLOT(stateChanged(int,DownloadManager::DownloadState)));
- connect(manager, SIGNAL(downloadRemoved(int)), this, SLOT(resetCache(int)));
-}
+ 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)));
+}
-DownloadListWidgetDelegate::~DownloadListWidgetDelegate()
+DownloadListWidget::~DownloadListWidget()
{
- delete m_ItemWidget;
}
-
-void DownloadListWidgetDelegate::stateChanged(int row,DownloadManager::DownloadState)
+void DownloadListWidget::setManager(DownloadManager *manager)
{
- m_Cache.remove(row);
+ m_Manager = manager;
}
-
-void DownloadListWidgetDelegate::resetCache(int)
+void DownloadListWidget::setSourceModel(DownloadList *sourceModel)
{
- m_Cache.clear();
+ m_SourceModel = sourceModel;
}
-
-void DownloadListWidgetDelegate::drawCache(QPainter *painter, const QStyleOptionViewItem &option, const QPixmap &cache) const
+void DownloadListWidget::setMetaDisplay(bool metaDisplay)
{
- QRect rect = option.rect;
- rect.setLeft(0);
- rect.setWidth(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2) + m_View->columnWidth(3));
- painter->drawPixmap(rect, cache);
+ if (m_SourceModel != nullptr)
+ m_SourceModel->setMetaDisplay(metaDisplay);
}
-
-QString DownloadListWidgetDelegate::sizeFormat(quint64 size) const
+void DownloadListWidget::onDoubleClick(const QModelIndex &index)
{
- qreal calc = size;
- QStringList list;
- list << "KB" << "MB" << "GB" << "TB";
+ QModelIndex sourceIndex = qobject_cast<QSortFilterProxyModel*>(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());
+}
- QStringListIterator i(list);
- QString unit("byte(s)");
+void DownloadListWidget::onHeaderCustomContextMenu(const QPoint &point)
+{
+ QMenu menu;
- while (calc >= 1024.0 && i.hasNext())
- {
- unit = i.next();
- calc /= 1024.0;
- }
+ // 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);
+ }
- return QString().setNum(calc, 'f', 2) + " " + unit;
-}
+ 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<const QWidgetAction*>(action);
+ if (widgetAction != nullptr) {
+ const QCheckBox *checkBox = qobject_cast<const QCheckBox*>(widgetAction->defaultWidget());
+ if (checkBox != nullptr) {
+ header()->setSectionHidden(i, !checkBox->isChecked());
+ }
+ }
+ ++i;
+ }
-void DownloadListWidgetDelegate::paintPendingDownload(int downloadIndex) const
-{
- std::tuple<QString, int, int> nexusids = m_Manager->getPendingDownload(downloadIndex);
- m_NameLabel->setText(tr("< game %1 mod %2 file %3 >").arg(std::get<0>(nexusids)).arg(std::get<1>(nexusids)).arg(std::get<2>(nexusids)));
- m_SizeLabel->setText("???");
- m_InstallLabel->setVisible(true);
- m_InstallLabel->setText(tr("Pending"));
- m_Progress->setVisible(false);
+ qobject_cast<DownloadListHeader*>(header())->customResizeSections();
}
-
-void DownloadListWidgetDelegate::paintRegularDownload(int downloadIndex) const
+void DownloadListWidget::resizeEvent(QResizeEvent *event)
{
- QString name = m_MetaDisplay ? m_Manager->getDisplayName(downloadIndex) : m_Manager->getFileName(downloadIndex);
- if (name.length() > 53) {
- name.truncate(50);
- name.append("...");
- }
- m_NameLabel->setText(name);
- m_SizeLabel->setText(sizeFormat(m_Manager->getFileSize(downloadIndex) ));
- DownloadManager::DownloadState state = m_Manager->getState(downloadIndex);
- if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR) || (state == DownloadManager::STATE_PAUSING)) {
- QPalette labelPalette;
- m_InstallLabel->setVisible(true);
- m_Progress->setVisible(false);
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
- m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Paused - Double Click to resume", 0));
-#else
- m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Paused - Double Click to resume", 0, QApplication::UnicodeUTF8));
-#endif
- labelPalette.setColor(QPalette::WindowText, Qt::darkRed);
- m_InstallLabel->setPalette(labelPalette);
- } else if (state == DownloadManager::STATE_FETCHINGMODINFO) {
- m_InstallLabel->setText(tr("Fetching Info 1"));
- m_Progress->setVisible(false);
- } else if (state == DownloadManager::STATE_FETCHINGFILEINFO) {
- m_InstallLabel->setText(tr("Fetching Info 2"));
- m_Progress->setVisible(false);
- } else if (state >= DownloadManager::STATE_READY) {
- QPalette labelPalette;
- m_InstallLabel->setVisible(true);
- m_Progress->setVisible(false);
- if (state == DownloadManager::STATE_INSTALLED) {
- // the tr-macro doesn't work here, maybe because the translation is actually associated with DownloadListWidget instead
- // of DownloadListWidgetDelegate?
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
- m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Installed - Double Click to re-install", 0));
-#else
- m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Installed - Double Click to re-install", 0, QApplication::UnicodeUTF8));
-#endif
- labelPalette.setColor(QPalette::WindowText, Qt::darkGray);
- } else if (state == DownloadManager::STATE_UNINSTALLED) {
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
- m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Uninstalled - Double Click to re-install", 0));
-#else
- m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Uninstalled - Double Click to re-install", 0, QApplication::UnicodeUTF8));
-#endif
- labelPalette.setColor(QPalette::WindowText, Qt::lightGray);
- } else {
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
- m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Done - Double Click to install", 0));
-#else
- m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Done - Double Click to install", 0, QApplication::UnicodeUTF8));
-#endif
- labelPalette.setColor(QPalette::WindowText, Qt::darkGreen);
- }
- m_InstallLabel->setPalette(labelPalette);
- if (m_Manager->isInfoIncomplete(downloadIndex)) {
- m_NameLabel->setText("<img src=\":/MO/gui/warning_16\" /> " + m_NameLabel->text());
- }
- } else {
- m_InstallLabel->setVisible(false);
- m_Progress->setVisible(true);
- m_Progress->setValue(m_Manager->getProgress(downloadIndex).first);
- m_Progress->setFormat(m_Manager->getProgress(downloadIndex).second);
- }
+ QTreeView::resizeEvent(event);
+ qobject_cast<DownloadListHeader*>(header())->customResizeSections();
}
-void DownloadListWidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+void DownloadListWidget::onCustomContextMenu(const QPoint &point)
{
- try {
- auto iter = m_Cache.find(index.row());
- if (iter != m_Cache.end()) {
- drawCache(painter, option, *iter);
- return;
- }
+ QMenu menu(this);
+ QModelIndex index = indexAt(point);
+ bool hidden = false;
+
+ if (index.row() >= 0) {
+ m_ContextRow = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(index).row();
+ DownloadManager::DownloadState state = m_Manager->getState(m_ContextRow);
+ hidden = m_Manager->isHidden(m_ContextRow);
- m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2) + m_View->columnWidth(3), option.rect.height()));
+ 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("Show in Folder"), this, SLOT(issueOpenInDownloadsFolder()));
- int downloadIndex = index.data().toInt();
+ menu.addSeparator();
- if (downloadIndex >= m_Manager->numTotalDownloads()) {
- paintPendingDownload(downloadIndex - m_Manager->numTotalDownloads());
- } else {
- paintRegularDownload(downloadIndex);
+ 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("Show in Folder"), 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("Show in Folder"), this, SLOT(issueOpenInDownloadsFolder()));
}
-#pragma message("caching disabled because changes in the list (including resorting) doesn't work correctly")
-// if (state >= DownloadManager::STATE_READY) {
- if (false) {
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
- QPixmap cache = m_ItemWidget->grab();
-#else
- QPixmap cache = QPixmap::grabWidget(m_ItemWidget);
-#endif
- m_Cache[index.row()] = cache;
- drawCache(painter, option, cache);
- } else {
- painter->save();
- painter->translate(QPoint(0, option.rect.topLeft().y()));
+ menu.addSeparator();
+ }
+ menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted()));
+ menu.addAction(tr("Delete Uninstalled..."), this, SLOT(issueDeleteUninstalled()));
+ menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll()));
- m_ItemWidget->render(painter);
- painter->restore();
- }
- } catch (const std::exception &e) {
- qCritical("failed to paint download list: %s", e.what());
+ 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()));
}
-}
-QSize DownloadListWidgetDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
-{
- const int width = m_ItemWidget->minimumWidth();
- const int height = m_ItemWidget->height();
- return QSize(width, height);
+ menu.exec(viewport()->mapToGlobal(point));
}
-
-void DownloadListWidgetDelegate::issueInstall()
+void DownloadListWidget::issueInstall()
{
emit installDownload(m_ContextRow);
}
-void DownloadListWidgetDelegate::issueQueryInfo()
+void DownloadListWidget::issueQueryInfo()
{
emit queryInfo(m_ContextRow);
}
-void DownloadListWidgetDelegate::issueDelete()
+void DownloadListWidget::issueQueryInfoMd5()
{
- if (QMessageBox::question(nullptr, tr("Delete Files?"),
- tr("This will permanently delete the selected download."),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- emit removeDownload(m_ContextRow, true);
- }
+ emit queryInfoMd5(m_ContextRow);
+}
+
+void DownloadListWidget::issueDelete()
+{
+ if (QMessageBox::question(nullptr, tr("Delete Files?"),
+ tr("This will permanently delete the selected download."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ emit removeDownload(m_ContextRow, true);
+ }
}
-void DownloadListWidgetDelegate::issueRemoveFromView()
+void DownloadListWidget::issueRemoveFromView()
{
+ qDebug() << "removing from view: " << m_ContextRow;
emit removeDownload(m_ContextRow, false);
}
-void DownloadListWidgetDelegate::issueRestoreToView()
+void DownloadListWidget::issueRestoreToView()
{
- emit restoreDownload(m_ContextRow);
+ emit restoreDownload(m_ContextRow);
}
-void DownloadListWidgetDelegate::issueRestoreToViewAll()
+void DownloadListWidget::issueRestoreToViewAll()
{
emit restoreDownload(-1);
}
-void DownloadListWidgetDelegate::issueVisitOnNexus()
+void DownloadListWidget::issueVisitOnNexus()
{
emit visitOnNexus(m_ContextRow);
}
-void DownloadListWidgetDelegate::issueOpenFile()
+void DownloadListWidget::issueOpenFile()
{
emit openFile(m_ContextRow);
}
-void DownloadListWidgetDelegate::issueOpenInDownloadsFolder()
+void DownloadListWidget::issueOpenInDownloadsFolder()
{
emit openInDownloadsFolder(m_ContextRow);
}
-void DownloadListWidgetDelegate::issueCancel()
+void DownloadListWidget::issueCancel()
{
emit cancelDownload(m_ContextRow);
}
-void DownloadListWidgetDelegate::issuePause()
+void DownloadListWidget::issuePause()
{
emit pauseDownload(m_ContextRow);
}
-void DownloadListWidgetDelegate::issueResume()
+void DownloadListWidget::issueResume()
{
emit resumeDownload(m_ContextRow);
}
-void DownloadListWidgetDelegate::issueDeleteAll()
+void DownloadListWidget::issueDeleteAll()
{
if (QMessageBox::question(nullptr, tr("Delete Files?"),
tr("This will remove all finished downloads from this list and from disk."),
@@ -306,7 +321,7 @@ void DownloadListWidgetDelegate::issueDeleteAll() }
}
-void DownloadListWidgetDelegate::issueDeleteCompleted()
+void DownloadListWidget::issueDeleteCompleted()
{
if (QMessageBox::question(nullptr, tr("Delete Files?"),
tr("This will remove all installed downloads from this list and from disk."),
@@ -315,16 +330,16 @@ void DownloadListWidgetDelegate::issueDeleteCompleted() }
}
-void DownloadListWidgetDelegate::issueDeleteUninstalled()
+void DownloadListWidget::issueDeleteUninstalled()
{
if (QMessageBox::question(nullptr, tr("Delete Files?"),
- tr("This will remove all uninstalled downloads from this list and from disk."),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ tr("This will remove all uninstalled downloads from this list and from disk."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
emit removeDownload(-3, true);
}
}
-void DownloadListWidgetDelegate::issueRemoveFromViewAll()
+void DownloadListWidget::issueRemoveFromViewAll()
{
if (QMessageBox::question(nullptr, tr("Are you sure?"),
tr("This will remove all finished downloads from this list (but NOT from disk)."),
@@ -333,7 +348,7 @@ void DownloadListWidgetDelegate::issueRemoveFromViewAll() }
}
-void DownloadListWidgetDelegate::issueRemoveFromViewCompleted()
+void DownloadListWidget::issueRemoveFromViewCompleted()
{
if (QMessageBox::question(nullptr, tr("Are you sure?"),
tr("This will remove all installed downloads from this list (but NOT from disk)."),
@@ -342,90 +357,11 @@ void DownloadListWidgetDelegate::issueRemoveFromViewCompleted() }
}
-void DownloadListWidgetDelegate::issueRemoveFromViewUninstalled()
+void DownloadListWidget::issueRemoveFromViewUninstalled()
{
if (QMessageBox::question(nullptr, tr("Are you sure?"),
- tr("This will remove all uninstalled downloads from this list (but NOT from disk)."),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ tr("This will remove all uninstalled downloads from this list (but NOT from disk)."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
emit removeDownload(-3, false);
}
}
-
-bool DownloadListWidgetDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
- const QStyleOptionViewItem &option, const QModelIndex &index)
-{
- try {
- if (event->type() == QEvent::MouseButtonDblClick) {
- QModelIndex sourceIndex = qobject_cast<QSortFilterProxyModel*>(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());
- }
- return true;
- } else if (event->type() == QEvent::MouseButtonRelease) {
- QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
- if (mouseEvent->button() == Qt::RightButton) {
- QMenu menu(m_View);
- bool hidden = false;
- m_ContextRow = qobject_cast<QSortFilterProxyModel*>(model)->mapToSource(index).row();
- if (m_ContextRow < m_Manager->numTotalDownloads()) {
- 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(issueQueryInfo()));
- }else {
- menu.addAction(tr("Visit on Nexus"), this,SLOT(issueVisitOnNexus()));
- }
-
- menu.addAction(tr("Open File"), this, SLOT(issueOpenFile()));
- menu.addAction(tr("Show in Folder"), 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("Show in Folder"), 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("Show in Folder"), this, SLOT(issueOpenInDownloadsFolder()));
- }
-
- menu.addSeparator();
- }
- menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted()));
- menu.addAction(tr("Delete Uninstalled..."), this, SLOT(issueDeleteUninstalled()));
- menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll()));
-
- if (!hidden) {
- menu.addSeparator();
- menu.addAction(tr("Hide Installed..."), this, SLOT(issueRemoveFromViewCompleted()));
- menu.addAction(tr("Hide Uninstalled..."), this, SLOT(issueRemoveFromViewUninstalled()));
- menu.addAction(tr("Hide All..."), this, SLOT(issueRemoveFromViewAll()));
- }
- if (hidden) {
- menu.addSeparator();
- menu.addAction(tr("Un-Hide All..."), this, SLOT(issueRestoreToViewAll()));
- }
-
- menu.exec(mouseEvent->globalPos());
-
- event->accept();
- return true;
- }
- }
- } catch (const std::exception &e) {
- qCritical("failed to handle editor event: %s", e.what());
- }
- return QItemDelegate::editorEvent(event, model, option, index);
-}
|
