mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-03-13 05:41:17 +00:00
Trackerlist: Allow to toggle columns
This commit is contained in:
parent
d9555a9e9d
commit
14f50f1038
@ -58,25 +58,33 @@ TrackerList::TrackerList(PropertiesWidget *properties)
|
|||||||
: QTreeWidget()
|
: QTreeWidget()
|
||||||
, properties(properties)
|
, properties(properties)
|
||||||
{
|
{
|
||||||
|
// Set header
|
||||||
|
// Must be set before calling loadSettings() otherwise the header is reset on restart
|
||||||
|
setHeaderLabels(headerLabels());
|
||||||
|
// Load settings
|
||||||
|
loadSettings();
|
||||||
// Graphical settings
|
// Graphical settings
|
||||||
setRootIsDecorated(false);
|
setRootIsDecorated(false);
|
||||||
setAllColumnsShowFocus(true);
|
setAllColumnsShowFocus(true);
|
||||||
setItemsExpandable(false);
|
setItemsExpandable(false);
|
||||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
header()->setStretchLastSection(false); // Must be set after loadSettings() in order to work
|
||||||
|
// Ensure that at least one column is visible at all times
|
||||||
|
if (visibleColumnsCount() == 0)
|
||||||
|
setColumnHidden(COL_URL, false);
|
||||||
|
// To also mitigate the above issue, we have to resize each column when
|
||||||
|
// its size is 0, because explicitly 'showing' the column isn't enough
|
||||||
|
// in the above scenario.
|
||||||
|
for (unsigned int i = 0; i < COL_COUNT; ++i)
|
||||||
|
if ((columnWidth(i) <= 0) && !isColumnHidden(i))
|
||||||
|
resizeColumnToContents(i);
|
||||||
// Context menu
|
// Context menu
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint)));
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint)));
|
||||||
// Set header
|
// Header context menu
|
||||||
QStringList header;
|
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
header << "#";
|
connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayToggleColumnsMenu(const QPoint&)));
|
||||||
header << tr("URL");
|
// Set DHT, PeX, LSD items
|
||||||
header << tr("Status");
|
|
||||||
header << tr("Received");
|
|
||||||
header << tr("Seeds");
|
|
||||||
header << tr("Peers");
|
|
||||||
header << tr("Downloaded");
|
|
||||||
header << tr("Message");
|
|
||||||
setHeaderItem(new QTreeWidgetItem(header));
|
|
||||||
dht_item = new QTreeWidgetItem({ "", "** [DHT] **", "", "0", "", "", "0" });
|
dht_item = new QTreeWidgetItem({ "", "** [DHT] **", "", "0", "", "", "0" });
|
||||||
insertTopLevelItem(0, dht_item);
|
insertTopLevelItem(0, dht_item);
|
||||||
setRowColor(0, QColor("grey"));
|
setRowColor(0, QColor("grey"));
|
||||||
@ -114,11 +122,9 @@ TrackerList::TrackerList(PropertiesWidget *properties)
|
|||||||
// This hack fixes reordering of first column with Qt5.
|
// This hack fixes reordering of first column with Qt5.
|
||||||
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
|
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
|
||||||
QTableView unused;
|
QTableView unused;
|
||||||
unused.setVerticalHeader(this->header());
|
unused.setVerticalHeader(header());
|
||||||
this->header()->setParent(this);
|
header()->setParent(this);
|
||||||
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
|
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
|
||||||
|
|
||||||
loadSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackerList::~TrackerList()
|
TrackerList::~TrackerList()
|
||||||
@ -552,13 +558,63 @@ void TrackerList::showTrackerListMenu(QPoint) {
|
|||||||
|
|
||||||
void TrackerList::loadSettings()
|
void TrackerList::loadSettings()
|
||||||
{
|
{
|
||||||
if (!header()->restoreState(Preferences::instance()->getPropTrackerListState())) {
|
header()->restoreState(Preferences::instance()->getPropTrackerListState());
|
||||||
setColumnWidth(0, 30);
|
|
||||||
setColumnWidth(1, 300);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackerList::saveSettings() const
|
void TrackerList::saveSettings() const
|
||||||
{
|
{
|
||||||
Preferences::instance()->setPropTrackerListState(header()->saveState());
|
Preferences::instance()->setPropTrackerListState(header()->saveState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList TrackerList::headerLabels()
|
||||||
|
{
|
||||||
|
static const QStringList header {
|
||||||
|
"#"
|
||||||
|
, tr("URL")
|
||||||
|
, tr("Status")
|
||||||
|
, tr("Received")
|
||||||
|
, tr("Seeds")
|
||||||
|
, tr("Peers")
|
||||||
|
, tr("Downloaded")
|
||||||
|
, tr("Message")
|
||||||
|
};
|
||||||
|
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TrackerList::visibleColumnsCount() const
|
||||||
|
{
|
||||||
|
int visibleCols = 0;
|
||||||
|
for (unsigned int i = 0; i < COL_COUNT; ++i) {
|
||||||
|
if (!isColumnHidden(i))
|
||||||
|
++visibleCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
return visibleCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackerList::displayToggleColumnsMenu(const QPoint &)
|
||||||
|
{
|
||||||
|
QMenu hideshowColumn(this);
|
||||||
|
hideshowColumn.setTitle(tr("Column visibility"));
|
||||||
|
for (int i = 0; i < COL_COUNT; ++i) {
|
||||||
|
QAction *myAct = hideshowColumn.addAction(headerLabels().at(i));
|
||||||
|
myAct->setCheckable(true);
|
||||||
|
myAct->setChecked(!isColumnHidden(i));
|
||||||
|
myAct->setData(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call menu
|
||||||
|
QAction *act = hideshowColumn.exec(QCursor::pos());
|
||||||
|
if (!act) return;
|
||||||
|
|
||||||
|
int col = act->data().toInt();
|
||||||
|
Q_ASSERT(visibleColumnsCount() > 0);
|
||||||
|
if (!isColumnHidden(col) && (visibleColumnsCount() == 1))
|
||||||
|
return;
|
||||||
|
qDebug("Toggling column %d visibility", col);
|
||||||
|
setColumnHidden(col, !isColumnHidden(col));
|
||||||
|
if (!isColumnHidden(col) && (columnWidth(col) <= 5))
|
||||||
|
setColumnWidth(col, 100);
|
||||||
|
saveSettings();
|
||||||
|
}
|
||||||
|
@ -60,12 +60,16 @@ public:
|
|||||||
COL_SEEDS,
|
COL_SEEDS,
|
||||||
COL_PEERS,
|
COL_PEERS,
|
||||||
COL_DOWNLOADED,
|
COL_DOWNLOADED,
|
||||||
COL_MSG
|
COL_MSG,
|
||||||
|
|
||||||
|
COL_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
TrackerList(PropertiesWidget *properties);
|
TrackerList(PropertiesWidget *properties);
|
||||||
~TrackerList();
|
~TrackerList();
|
||||||
|
|
||||||
|
int visibleColumnsCount() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setRowColor(int row, QColor color);
|
void setRowColor(int row, QColor color);
|
||||||
|
|
||||||
@ -81,6 +85,7 @@ public slots:
|
|||||||
void deleteSelectedTrackers();
|
void deleteSelectedTrackers();
|
||||||
void editSelectedTracker();
|
void editSelectedTracker();
|
||||||
void showTrackerListMenu(QPoint);
|
void showTrackerListMenu(QPoint);
|
||||||
|
void displayToggleColumnsMenu(const QPoint &);
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings() const;
|
void saveSettings() const;
|
||||||
|
|
||||||
@ -96,6 +101,8 @@ private:
|
|||||||
QShortcut *editHotkey;
|
QShortcut *editHotkey;
|
||||||
QShortcut *deleteHotkey;
|
QShortcut *deleteHotkey;
|
||||||
QShortcut *copyHotkey;
|
QShortcut *copyHotkey;
|
||||||
|
|
||||||
|
static QStringList headerLabels();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRACKERLIST_H
|
#endif // TRACKERLIST_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user