Browse Source

Add context menu to toggle content tab columns (#15164)

adaptive-webui-19844
AbeniMatteo 3 years ago committed by GitHub
parent
commit
abd6eb2ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      src/gui/properties/propertieswidget.cpp
  2. 1
      src/gui/properties/propertieswidget.h

31
src/gui/properties/propertieswidget.cpp

@ -81,6 +81,9 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) @@ -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) @@ -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() @@ -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);

1
src/gui/properties/propertieswidget.h

@ -81,6 +81,7 @@ public slots: @@ -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…
Cancel
Save