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 @@ @@ -30,6 +30,7 @@
#include <algorithm>
#include <QAction>
#include <QDebug>
#include <QDir>
#include <QFileDialog>
@ -235,7 +236,11 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP @@ -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 &) @@ -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 &) @@ -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

24
src/gui/previewselectdialog.cpp

@ -28,9 +28,11 @@ @@ -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 @@ -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() @@ -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

1
src/gui/previewselectdialog.h

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

13
src/gui/properties/peerlistwidget.cpp

@ -182,6 +182,7 @@ void PeerListWidget::displayColumnHeaderMenu() @@ -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() @@ -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());
}

13
src/gui/properties/propertieswidget.cpp

@ -182,6 +182,7 @@ void PropertiesWidget::displayColumnHeaderMenu() @@ -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() @@ -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());
}

13
src/gui/properties/trackerlistwidget.cpp

@ -656,6 +656,7 @@ void TrackerListWidget::displayColumnHeaderMenu() @@ -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() @@ -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());
}

13
src/gui/search/searchjobwidget.cpp

@ -469,6 +469,7 @@ void SearchJobWidget::displayColumnHeaderMenu() @@ -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() @@ -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());
}

13
src/gui/transferlistwidget.cpp

@ -643,6 +643,7 @@ void TransferListWidget::displayColumnHeaderMenu() @@ -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() @@ -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());
}

Loading…
Cancel
Save