diff options
| author | Krzysztof Starecki <krzysztof.starecki@gmail.com> | 2018-12-31 23:21:01 +0100 |
|---|---|---|
| committer | Krzysztof Starecki <krzysztof.starecki@gmail.com> | 2018-12-31 23:24:19 +0100 |
| commit | 263a3f7d24f177bb28ad988ec70bc97106c0816b (patch) | |
| tree | 0753470342eb571c5bdd6a7fe6a39b8672bce724 /src/downloadlistwidget.cpp | |
| parent | 79a2f8477b02c506ff8ae18367d3739aa17307ad (diff) | |
Make download tab columns hideable by user
Diffstat (limited to 'src/downloadlistwidget.cpp')
| -rw-r--r-- | src/downloadlistwidget.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. #include <QMessageBox>
#include <QSortFilterProxyModel>
#include <QApplication>
+#include <QHeaderView>
+#include <QCheckBox>
+#include <QWidgetAction>
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<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 DownloadListWidget::onCustomContextMenu(const QPoint &point)
{
QMenu menu(this);
|
