Add "Auto resize columns" functionality

This commit is contained in:
Chocobo1 2022-01-18 15:45:31 +08:00
parent 208234b934
commit 7ae68b20e7
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
8 changed files with 115 additions and 0 deletions

View file

@ -30,6 +30,7 @@
#include <algorithm>
#include <QAction>
#include <QDebug>
#include <QDir>
#include <QFileDialog>
@ -235,7 +236,11 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
if (category != defaultCategory && category != m_torrentParams.category)
m_ui->categoryComboBox->addItem(category);
m_ui->contentTreeView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
m_ui->contentTreeView->header()->setSortIndicator(0, Qt::AscendingOrder);
connect(m_ui->contentTreeView->header(), &QWidget::customContextMenuRequested, this, &AddNewTorrentDialog::displayColumnHeaderMenu);
loadState();
// Signal / slots
connect(m_ui->doNotDeleteTorrentCheckBox, &QCheckBox::clicked, this, &AddNewTorrentDialog::doNotDeleteTorrentClicked);
@ -705,6 +710,7 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
if (selectedRows.size() == 1)
{
menu->addAction(UIThemeManager::instance()->getIcon("edit-rename"), tr("Rename..."), this, &AddNewTorrentDialog::renameSelectedFile);
@ -755,6 +761,25 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
menu->popup(QCursor::pos());
}
void AddNewTorrentDialog::displayColumnHeaderMenu()
{
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setToolTipsVisible(true);
QAction *resizeAction = menu->addAction(tr("Resize columns"), this, [this]()
{
for (int i = 0, count = m_ui->contentTreeView->header()->count(); i < count; ++i)
{
if (!m_ui->contentTreeView->isColumnHidden(i))
m_ui->contentTreeView->resizeColumnToContents(i);
}
});
resizeAction->setToolTip(tr("Resize all non-hidden columns to the size of their contents"));
menu->popup(QCursor::pos());
}
void AddNewTorrentDialog::accept()
{
// TODO: Check if destination actually exists

View file

@ -28,9 +28,11 @@
#include "previewselectdialog.h"
#include <QAction>
#include <QDir>
#include <QFile>
#include <QHeaderView>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QShowEvent>
@ -104,9 +106,12 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr
}
m_previewListModel->sort(NAME);
m_ui->previewList->header()->setContextMenuPolicy(Qt::CustomContextMenu);
m_ui->previewList->header()->setSortIndicator(0, Qt::AscendingOrder);
m_ui->previewList->selectionModel()->select(m_previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows);
connect(m_ui->previewList->header(), &QWidget::customContextMenuRequested, this, &PreviewSelectDialog::displayColumnHeaderMenu);
// Restore dialog state
loadWindowState();
}
@ -145,6 +150,25 @@ void PreviewSelectDialog::previewButtonClicked()
accept();
}
void PreviewSelectDialog::displayColumnHeaderMenu()
{
auto menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setToolTipsVisible(true);
QAction *resizeAction = menu->addAction(tr("Resize columns"), this, [this]()
{
for (int i = 0, count = m_ui->previewList->header()->count(); i < count; ++i)
{
if (!m_ui->previewList->isColumnHidden(i))
m_ui->previewList->resizeColumnToContents(i);
}
});
resizeAction->setToolTip(tr("Resize all non-hidden columns to the size of their contents"));
menu->popup(QCursor::pos());
}
void PreviewSelectDialog::saveWindowState()
{
// Persist dialog size

View file

@ -68,6 +68,7 @@ signals:
private slots:
void previewButtonClicked();
void displayColumnHeaderMenu();
private:
void showEvent(QShowEvent *event) override;

View file

@ -182,6 +182,7 @@ void PeerListWidget::displayColumnHeaderMenu()
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i)
{
@ -205,6 +206,18 @@ void PeerListWidget::displayColumnHeaderMenu()
action->setChecked(!isColumnHidden(i));
}
menu->addSeparator();
QAction *resizeAction = menu->addAction(tr("Resize columns"), this, [this]()
{
for (int i = 0, count = header()->count(); i < count; ++i)
{
if (!isColumnHidden(i))
resizeColumnToContents(i);
}
saveSettings();
});
resizeAction->setToolTip(tr("Resize all non-hidden columns to the size of their contents"));
menu->popup(QCursor::pos());
}

View file

@ -182,6 +182,7 @@ void PropertiesWidget::displayColumnHeaderMenu()
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < TorrentContentModelItem::TreeItemColumns::NB_COL; ++i)
{
@ -202,6 +203,18 @@ void PropertiesWidget::displayColumnHeaderMenu()
action->setEnabled(false);
}
menu->addSeparator();
QAction *resizeAction = menu->addAction(tr("Resize columns"), this, [this]()
{
for (int i = 0, count = m_ui->filesList->header()->count(); i < count; ++i)
{
if (!m_ui->filesList->isColumnHidden(i))
m_ui->filesList->resizeColumnToContents(i);
}
saveSettings();
});
resizeAction->setToolTip(tr("Resize all non-hidden columns to the size of their contents"));
menu->popup(QCursor::pos());
}

View file

@ -656,6 +656,7 @@ void TrackerListWidget::displayColumnHeaderMenu()
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < COL_COUNT; ++i)
{
@ -675,5 +676,17 @@ void TrackerListWidget::displayColumnHeaderMenu()
action->setChecked(!isColumnHidden(i));
}
menu->addSeparator();
QAction *resizeAction = menu->addAction(tr("Resize columns"), this, [this]()
{
for (int i = 0, count = header()->count(); i < count; ++i)
{
if (!isColumnHidden(i))
resizeColumnToContents(i);
}
saveSettings();
});
resizeAction->setToolTip(tr("Resize all non-hidden columns to the size of their contents"));
menu->popup(QCursor::pos());
}

View file

@ -469,6 +469,7 @@ void SearchJobWidget::displayColumnHeaderMenu()
auto menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < SearchSortModel::DL_LINK; ++i)
{
@ -489,6 +490,18 @@ void SearchJobWidget::displayColumnHeaderMenu()
action->setChecked(!m_ui->resultsBrowser->isColumnHidden(i));
}
menu->addSeparator();
QAction *resizeAction = menu->addAction(tr("Resize columns"), this, [this]()
{
for (int i = 0, count = m_ui->resultsBrowser->header()->count(); i < count; ++i)
{
if (!m_ui->resultsBrowser->isColumnHidden(i))
m_ui->resultsBrowser->resizeColumnToContents(i);
}
saveSettings();
});
resizeAction->setToolTip(tr("Resize all non-hidden columns to the size of their contents"));
menu->popup(QCursor::pos());
}

View file

@ -643,6 +643,7 @@ void TransferListWidget::displayColumnHeaderMenu()
auto menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < TransferListModel::NB_COLUMNS; ++i)
{
@ -666,6 +667,18 @@ void TransferListWidget::displayColumnHeaderMenu()
action->setChecked(!isColumnHidden(i));
}
menu->addSeparator();
QAction *resizeAction = menu->addAction(tr("Resize columns"), this, [this]()
{
for (int i = 0, count = header()->count(); i < count; ++i)
{
if (!isColumnHidden(i))
resizeColumnToContents(i);
}
saveSettings();
});
resizeAction->setToolTip(tr("Resize all non-hidden columns to the size of their contents"));
menu->popup(QCursor::pos());
}