From 263a3f7d24f177bb28ad988ec70bc97106c0816b Mon Sep 17 00:00:00 2001 From: Krzysztof Starecki Date: Mon, 31 Dec 2018 23:21:01 +0100 Subject: Make download tab columns hideable by user --- src/downloadlistwidget.cpp | 38 ++++++++++ src/downloadlistwidget.h | 1 + src/organizer_en.ts | 168 ++++++++++++++++++++++----------------------- 3 files changed, 123 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 393a8a98..24695032 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -25,6 +25,9 @@ along with Mod Organizer. If not, see . #include #include #include +#include +#include +#include void DownloadProgressDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { @@ -73,6 +76,9 @@ DownloadListWidget::DownloadListWidget(QWidget *parent) { connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClick(QModelIndex))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenu(QPoint))); + + header()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(header(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onHeaderCustomContextMenu(QPoint))); } DownloadListWidget::~DownloadListWidget() @@ -105,6 +111,38 @@ void DownloadListWidget::onDoubleClick(const QModelIndex &index) 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; + } +} + void DownloadListWidget::onCustomContextMenu(const QPoint &point) { QMenu menu(this); diff --git a/src/downloadlistwidget.h b/src/downloadlistwidget.h index bfe504aa..0002e2b4 100644 --- a/src/downloadlistwidget.h +++ b/src/downloadlistwidget.h @@ -77,6 +77,7 @@ signals: private slots: void onDoubleClick(const QModelIndex &index); void onCustomContextMenu(const QPoint &point); + void onHeaderCustomContextMenu(const QPoint &point); void issueInstall(); void issueDelete(); void issueRemoveFromView(); diff --git a/src/organizer_en.ts b/src/organizer_en.ts index 82fe46e8..ace06361 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -395,145 +395,145 @@ p, li { white-space: pre-wrap; } DownloadListWidget - + Install - + Query Info - + Visit on Nexus - + Open File - - - + + + Show in Folder - - + + Delete - + Un-Hide - + Hide - + Cancel - + Pause - + Resume - + Delete Installed... - + Delete Uninstalled... - + Delete All... - + Hide Installed... - + Hide Uninstalled... - + Hide All... - + Un-Hide All... - - - - + + + + Delete Files? - + This will permanently delete the selected download. - + This will remove all finished downloads from this list and from disk. - + This will remove all installed downloads from this list and from disk. - + This will remove all uninstalled downloads from this list and from disk. - - - + + + Are you sure? - + This will remove all finished downloads from this list (but NOT from disk). - + This will remove all installed downloads from this list (but NOT from disk). - + This will remove all uninstalled downloads from this list (but NOT from disk). @@ -593,7 +593,7 @@ p, li { white-space: pre-wrap; } - + remove: invalid download index %1 @@ -613,234 +613,234 @@ p, li { white-space: pre-wrap; } - + cancel: invalid download index %1 - + pause: invalid download index %1 - + resume: invalid download index %1 - + resume (int): invalid download index %1 - + No known download urls. Sorry, this download can't be resumed. - + query: invalid download index %1 - + Please enter the nexus mod id - + Mod ID: - + Please select the source game code for %1 - + VisitNexus: invalid download index %1 - + Nexus ID for this Mod is unknown - + OpenFile: invalid download index %1 - + OpenFileInDownloadsFolder: invalid download index %1 - + get pending: invalid download index %1 - + get path: invalid download index %1 - + Main - + Update - + Optional - + Old - + Misc - + Unknown - + display name: invalid download index %1 - + file name: invalid download index %1 - + file time: invalid download index %1 - + file size: invalid download index %1 - + progress: invalid download index %1 - + state: invalid download index %1 - + infocomplete: invalid download index %1 - - + + mod id: invalid download index %1 - + ishidden: invalid download index %1 - + file info: invalid download index %1 - + mark installed: invalid download index %1 - + mark uninstalled: invalid download index %1 - + Memory allocation error (in processing progress event). - + Memory allocation error (in processing downloaded data). - + Information updated - - + + No matching file found on Nexus! Maybe this file is no longer available or it was renamed? - + No file on Nexus matches the selected file by name. Please manually choose the correct one. - + No download server available. Please try again later. - + Failed to request file info from nexus: %1 - + Warning: Content type is: %1 - + Download header content length: %1 downloaded file size: %2 - + Download failed: %1 (%2) - + We were unable to download the file due to errors after four retries. There may be an issue with the Nexus servers. - + failed to re-open %1 - + Unable to write download to drive (return %1). Check the drive's available storage. -- cgit v1.3.1