From b0c4be231622666eab9253c6e5700e5157559c9c Mon Sep 17 00:00:00 2001 From: dteviot Date: Mon, 4 May 2015 14:52:47 +1200 Subject: [PATCH] Multi-select + context menu. (Fixes #2480) Content selector, added multi-select + context menu to allow check/uncheck the multi-selected items. --- .../contentselector/view/contentselector.cpp | 40 +++++++++++++++++++ .../contentselector/view/contentselector.hpp | 6 +++ files/ui/contentselector.ui | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index e3093d568..2fae8e74b 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -57,6 +57,17 @@ void ContentSelectorView::ContentSelector::buildAddonView() connect(ui.addonView, SIGNAL(activated(const QModelIndex&)), this, SLOT(slotAddonTableItemActivated(const QModelIndex&))); connect(mContentModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SIGNAL(signalAddonDataChanged(QModelIndex,QModelIndex))); + buildContextMenu(); +} + +void ContentSelectorView::ContentSelector::buildContextMenu() +{ + ui.addonView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui.addonView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(slotShowContextMenu(const QPoint&))); + + mContextMenu = new QMenu(ui.addonView); + mContextMenu->addAction(tr("&Check Selected"), this, SLOT(slotCheckMultiSelectedItems())); + mContextMenu->addAction(tr("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems())); } void ContentSelectorView::ContentSelector::setProfileContent(const QStringList &fileList) @@ -196,3 +207,32 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QMo mContentModel->setData(sourceIndex, checkState, Qt::CheckStateRole); } + +void ContentSelectorView::ContentSelector::slotShowContextMenu(const QPoint& pos) +{ + QPoint globalPos = ui.addonView->viewport()->mapToGlobal(pos); + mContextMenu->exec(globalPos); +} + +void ContentSelectorView::ContentSelector::setCheckStateForMultiSelectedItems(bool checked) +{ + Qt::CheckState checkState = checked ? Qt::Checked : Qt::Unchecked; + foreach(const QModelIndex& index, ui.addonView->selectionModel()->selectedIndexes()) + { + QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index); + if (mContentModel->data(sourceIndex, Qt::CheckStateRole).toInt() != checkState) + { + mContentModel->setData(sourceIndex, checkState, Qt::CheckStateRole); + } + } +} + +void ContentSelectorView::ContentSelector::slotUncheckMultiSelectedItems() +{ + setCheckStateForMultiSelectedItems(false); +} + +void ContentSelectorView::ContentSelector::slotCheckMultiSelectedItems() +{ + setCheckStateForMultiSelectedItems(true); +} diff --git a/components/contentselector/view/contentselector.hpp b/components/contentselector/view/contentselector.hpp index 2507cf6ad..e455807c9 100644 --- a/components/contentselector/view/contentselector.hpp +++ b/components/contentselector/view/contentselector.hpp @@ -14,6 +14,7 @@ namespace ContentSelectorView { Q_OBJECT + QMenu *mContextMenu; QStringList mFilePaths; protected: @@ -51,7 +52,9 @@ namespace ContentSelectorView void buildContentModel(); void buildGameFileView(); void buildAddonView(); + void buildContextMenu(); void setGameFileSelected(int index, bool selected); + void setCheckStateForMultiSelectedItems(bool checked); signals: void signalCurrentGamefileIndexChanged (int); @@ -62,6 +65,9 @@ namespace ContentSelectorView void slotCurrentGameFileIndexChanged(int index); void slotAddonTableItemActivated(const QModelIndex& index); + void slotShowContextMenu(const QPoint& pos); + void slotCheckMultiSelectedItems(); + void slotUncheckMultiSelectedItems(); }; } diff --git a/files/ui/contentselector.ui b/files/ui/contentselector.ui index b9b5ba5a0..7832239b5 100644 --- a/files/ui/contentselector.ui +++ b/files/ui/contentselector.ui @@ -72,7 +72,7 @@ true - QAbstractItemView::SingleSelection + QAbstractItemView::ExtendedSelection QAbstractItemView::SelectRows