Browse Source

Add "Auto resize columns" functionality

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
7ae68b20e7
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 25
      src/gui/addnewtorrentdialog.cpp
  2. 24
      src/gui/previewselectdialog.cpp
  3. 1
      src/gui/previewselectdialog.h
  4. 13
      src/gui/properties/peerlistwidget.cpp
  5. 13
      src/gui/properties/propertieswidget.cpp
  6. 13
      src/gui/properties/trackerlistwidget.cpp
  7. 13
      src/gui/search/searchjobwidget.cpp
  8. 13
      src/gui/transferlistwidget.cpp

25
src/gui/addnewtorrentdialog.cpp

@ -30,6 +30,7 @@
#include <algorithm> #include <algorithm>
#include <QAction>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
@ -235,7 +236,11 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
if (category != defaultCategory && category != m_torrentParams.category) if (category != defaultCategory && category != m_torrentParams.category)
m_ui->categoryComboBox->addItem(category); m_ui->categoryComboBox->addItem(category);
m_ui->contentTreeView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
m_ui->contentTreeView->header()->setSortIndicator(0, Qt::AscendingOrder); m_ui->contentTreeView->header()->setSortIndicator(0, Qt::AscendingOrder);
connect(m_ui->contentTreeView->header(), &QWidget::customContextMenuRequested, this, &AddNewTorrentDialog::displayColumnHeaderMenu);
loadState(); loadState();
// Signal / slots // Signal / slots
connect(m_ui->doNotDeleteTorrentCheckBox, &QCheckBox::clicked, this, &AddNewTorrentDialog::doNotDeleteTorrentClicked); connect(m_ui->doNotDeleteTorrentCheckBox, &QCheckBox::clicked, this, &AddNewTorrentDialog::doNotDeleteTorrentClicked);
@ -705,6 +710,7 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
if (selectedRows.size() == 1) if (selectedRows.size() == 1)
{ {
menu->addAction(UIThemeManager::instance()->getIcon("edit-rename"), tr("Rename..."), this, &AddNewTorrentDialog::renameSelectedFile); 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()); 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() void AddNewTorrentDialog::accept()
{ {
// TODO: Check if destination actually exists // TODO: Check if destination actually exists

24
src/gui/previewselectdialog.cpp

@ -28,9 +28,11 @@
#include "previewselectdialog.h" #include "previewselectdialog.h"
#include <QAction>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QHeaderView> #include <QHeaderView>
#include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QShowEvent> #include <QShowEvent>
@ -104,9 +106,12 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr
} }
m_previewListModel->sort(NAME); m_previewListModel->sort(NAME);
m_ui->previewList->header()->setContextMenuPolicy(Qt::CustomContextMenu);
m_ui->previewList->header()->setSortIndicator(0, Qt::AscendingOrder); m_ui->previewList->header()->setSortIndicator(0, Qt::AscendingOrder);
m_ui->previewList->selectionModel()->select(m_previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows); 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 // Restore dialog state
loadWindowState(); loadWindowState();
} }
@ -145,6 +150,25 @@ void PreviewSelectDialog::previewButtonClicked()
accept(); 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() void PreviewSelectDialog::saveWindowState()
{ {
// Persist dialog size // Persist dialog size

1
src/gui/previewselectdialog.h

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

13
src/gui/properties/peerlistwidget.cpp

@ -182,6 +182,7 @@ void PeerListWidget::displayColumnHeaderMenu()
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility")); menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i)
{ {
@ -205,6 +206,18 @@ void PeerListWidget::displayColumnHeaderMenu()
action->setChecked(!isColumnHidden(i)); 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()); menu->popup(QCursor::pos());
} }

13
src/gui/properties/propertieswidget.cpp

@ -182,6 +182,7 @@ void PropertiesWidget::displayColumnHeaderMenu()
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility")); menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < TorrentContentModelItem::TreeItemColumns::NB_COL; ++i) for (int i = 0; i < TorrentContentModelItem::TreeItemColumns::NB_COL; ++i)
{ {
@ -202,6 +203,18 @@ void PropertiesWidget::displayColumnHeaderMenu()
action->setEnabled(false); 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()); menu->popup(QCursor::pos());
} }

13
src/gui/properties/trackerlistwidget.cpp

@ -656,6 +656,7 @@ void TrackerListWidget::displayColumnHeaderMenu()
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility")); menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < COL_COUNT; ++i) for (int i = 0; i < COL_COUNT; ++i)
{ {
@ -675,5 +676,17 @@ void TrackerListWidget::displayColumnHeaderMenu()
action->setChecked(!isColumnHidden(i)); 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()); menu->popup(QCursor::pos());
} }

13
src/gui/search/searchjobwidget.cpp

@ -469,6 +469,7 @@ void SearchJobWidget::displayColumnHeaderMenu()
auto menu = new QMenu(this); auto menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility")); menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < SearchSortModel::DL_LINK; ++i) for (int i = 0; i < SearchSortModel::DL_LINK; ++i)
{ {
@ -489,6 +490,18 @@ void SearchJobWidget::displayColumnHeaderMenu()
action->setChecked(!m_ui->resultsBrowser->isColumnHidden(i)); 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()); menu->popup(QCursor::pos());
} }

13
src/gui/transferlistwidget.cpp

@ -643,6 +643,7 @@ void TransferListWidget::displayColumnHeaderMenu()
auto menu = new QMenu(this); auto menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility")); menu->setTitle(tr("Column visibility"));
menu->setToolTipsVisible(true);
for (int i = 0; i < TransferListModel::NB_COLUMNS; ++i) for (int i = 0; i < TransferListModel::NB_COLUMNS; ++i)
{ {
@ -666,6 +667,18 @@ void TransferListWidget::displayColumnHeaderMenu()
action->setChecked(!isColumnHidden(i)); 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()); menu->popup(QCursor::pos());
} }

Loading…
Cancel
Save