mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Add context menu to toggle content tab columns (#15164)
This commit is contained in:
parent
d3497148c5
commit
abd6eb2ff3
@ -81,6 +81,9 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
|
||||
|
||||
m_state = VISIBLE;
|
||||
|
||||
// Files list
|
||||
m_ui->filesList->header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
// Set Properties list model
|
||||
m_propListModel = new TorrentContentFilterModel(this);
|
||||
m_ui->filesList->setModel(m_propListModel);
|
||||
@ -108,6 +111,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
|
||||
, m_ui->filesList, qOverload<const QModelIndex &>(&QAbstractItemView::edit));
|
||||
connect(m_ui->filesList, &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayFilesListMenu);
|
||||
connect(m_ui->filesList, &QAbstractItemView::doubleClicked, this, &PropertiesWidget::openItem);
|
||||
connect(m_ui->filesList->header(), &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayFileListHeaderMenu);
|
||||
connect(m_ui->filesList->header(), &QHeaderView::sectionMoved, this, &PropertiesWidget::saveSettings);
|
||||
connect(m_ui->filesList->header(), &QHeaderView::sectionResized, this, &PropertiesWidget::saveSettings);
|
||||
connect(m_ui->filesList->header(), &QHeaderView::sortIndicatorChanged, this, &PropertiesWidget::saveSettings);
|
||||
@ -173,6 +177,33 @@ PropertiesWidget::~PropertiesWidget()
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void PropertiesWidget::displayFileListHeaderMenu()
|
||||
{
|
||||
QMenu *menu = new QMenu(this);
|
||||
menu->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
for (int i = 0; i < TorrentContentModelItem::TreeItemColumns::NB_COL; ++i)
|
||||
{
|
||||
QAction *myAct = menu->addAction(m_propListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
myAct->setCheckable(true);
|
||||
myAct->setChecked(!m_ui->filesList->isColumnHidden(i));
|
||||
if (i == TorrentContentModelItem::TreeItemColumns::COL_NAME)
|
||||
myAct->setEnabled(false);
|
||||
|
||||
connect(myAct, &QAction::toggled, this, [this, i](const bool checked)
|
||||
{
|
||||
m_ui->filesList->setColumnHidden(i, !checked);
|
||||
|
||||
if (!m_ui->filesList->isColumnHidden(i) && (m_ui->filesList->columnWidth(i) <= 5))
|
||||
m_ui->filesList->resizeColumnToContents(i);
|
||||
|
||||
saveSettings();
|
||||
});
|
||||
}
|
||||
|
||||
menu->popup(QCursor::pos());
|
||||
}
|
||||
|
||||
void PropertiesWidget::showPiecesAvailability(bool show)
|
||||
{
|
||||
m_ui->labelPiecesAvailability->setVisible(show);
|
||||
|
@ -81,6 +81,7 @@ public slots:
|
||||
void readSettings();
|
||||
void saveSettings();
|
||||
void reloadPreferences();
|
||||
void displayFileListHeaderMenu();
|
||||
void openItem(const QModelIndex &index) const;
|
||||
void loadTrackers(BitTorrent::Torrent *const torrent);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user