Add option to disable torrent state colors
Some checks are pending
CI - File health / Check (push) Waiting to run
CI - macOS / Build (push) Waiting to run
CI - Python / Check (push) Waiting to run
CI - Ubuntu / Build (push) Waiting to run
CI - WebUI / Check (push) Waiting to run
CI - Windows / Build (push) Waiting to run

PR #22976.
This commit is contained in:
Vladimir Golovnev 2025-07-14 11:40:53 +03:00 committed by GitHub
commit e1ebf8374e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 65 additions and 22 deletions

View file

@ -186,6 +186,19 @@ void Preferences::setAlternatingRowColors(const bool b)
setValue(u"Preferences/General/AlternatingRowColors"_s, b);
}
bool Preferences::useTorrentStatesColors() const
{
return value(u"GUI/TransferList/UseTorrentStatesColors"_s, true);
}
void Preferences::setUseTorrentStatesColors(const bool value)
{
if (value == useTorrentStatesColors())
return;
setValue(u"GUI/TransferList/UseTorrentStatesColors"_s, value);
}
bool Preferences::getProgressBarFollowsTextColor() const
{
return value(u"GUI/TransferList/ProgressBarFollowsTextColor"_s, false);

View file

@ -113,6 +113,8 @@ public:
void showSpeedInTitleBar(bool show);
bool useAlternatingRowColors() const;
void setAlternatingRowColors(bool b);
bool useTorrentStatesColors() const;
void setUseTorrentStatesColors(bool value);
bool getProgressBarFollowsTextColor() const;
void setProgressBarFollowsTextColor(bool value);
bool getHideZeroValues() const;

View file

@ -261,7 +261,9 @@ void OptionsDialog::loadBehaviorTabOptions()
m_ui->confirmDeletion->setChecked(pref->confirmTorrentDeletion());
m_ui->checkAltRowColors->setChecked(pref->useAlternatingRowColors());
m_ui->checkUseTorrentStatesColors->setChecked(pref->useTorrentStatesColors());
m_ui->checkProgressBarFollowsTextColor->setChecked(pref->getProgressBarFollowsTextColor());
m_ui->checkProgressBarFollowsTextColor->setEnabled(m_ui->checkProgressBarFollowsTextColor->isChecked());
m_ui->checkHideZero->setChecked(pref->getHideZeroValues());
m_ui->comboHideZero->setCurrentIndex(pref->getHideZeroComboValues());
m_ui->comboHideZero->setEnabled(m_ui->checkHideZero->isChecked());
@ -390,6 +392,8 @@ void OptionsDialog::loadBehaviorTabOptions()
connect(m_ui->confirmDeletion, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkAltRowColors, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUseTorrentStatesColors, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUseTorrentStatesColors, &QAbstractButton::toggled, m_ui->checkProgressBarFollowsTextColor, &QWidget::setEnabled);
connect(m_ui->checkProgressBarFollowsTextColor, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkHideZero, &QAbstractButton::toggled, m_ui->comboHideZero, &QWidget::setEnabled);
connect(m_ui->checkHideZero, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
@ -485,6 +489,7 @@ void OptionsDialog::saveBehaviorTabOptions() const
pref->setConfirmTorrentDeletion(m_ui->confirmDeletion->isChecked());
pref->setAlternatingRowColors(m_ui->checkAltRowColors->isChecked());
pref->setUseTorrentStatesColors(m_ui->checkUseTorrentStatesColors->isChecked());
pref->setProgressBarFollowsTextColor(m_ui->checkProgressBarFollowsTextColor->isChecked());
pref->setHideZeroValues(m_ui->checkHideZero->isChecked());
pref->setHideZeroComboValues(m_ui->comboHideZero->currentIndex());

View file

@ -297,6 +297,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkUseTorrentStatesColors">
<property name="text">
<string>Use different text colors by torrent states</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkProgressBarFollowsTextColor">
<property name="text">

View file

@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2025 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@ -34,16 +35,10 @@
#include "transferlistmodel.h"
TransferListDelegate::TransferListDelegate(QObject *parent)
: QStyledItemDelegate {parent}
: QStyledItemDelegate(parent)
{
}
QWidget *TransferListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
{
// No editor here
return nullptr;
}
QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
// Reimplementing sizeHint() because the 'name' column contains text+icon.

View file

@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2025 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@ -40,7 +41,6 @@ class TransferListDelegate final : public QStyledItemDelegate
public:
explicit TransferListDelegate(QObject *parent);
QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;

View file

@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015-2024 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015-2025 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@ -533,15 +533,19 @@ QVariant TransferListModel::internalValue(const BitTorrent::Torrent *torrent, co
QVariant TransferListModel::data(const QModelIndex &index, const int role) const
{
if (!index.isValid()) return {};
if (!index.isValid())
return {};
const BitTorrent::Torrent *torrent = m_torrentList.value(index.row());
if (!torrent) return {};
if (!torrent)
return {};
switch (role)
{
case Qt::ForegroundRole:
return m_stateThemeColors.value(torrent->state());
if (m_useTorrentStatesColors)
return m_stateThemeColors.value(torrent->state());
break;
case Qt::DisplayRole:
return displayValue(torrent, index.column());
case UnderlyingDataRole:
@ -604,10 +608,12 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const
bool TransferListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid() || (role != Qt::DisplayRole)) return false;
if (!index.isValid() || (role != Qt::DisplayRole))
return false;
BitTorrent::Torrent *const torrent = m_torrentList.value(index.row());
if (!torrent) return false;
if (!torrent)
return false;
// Category and Name columns can be edited
switch (index.column())
@ -646,10 +652,10 @@ void TransferListModel::addTorrents(const QList<BitTorrent::Torrent *> &torrents
Qt::ItemFlags TransferListModel::flags(const QModelIndex &index) const
{
if (!index.isValid()) return Qt::NoItemFlags;
if (!index.isValid())
return Qt::NoItemFlags;
// Explicitly mark as editable
return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
return QAbstractListModel::flags(index);
}
BitTorrent::Torrent *TransferListModel::torrentHandle(const QModelIndex &index) const
@ -717,11 +723,22 @@ void TransferListModel::configure()
hideZeroValuesMode = HideZeroValuesMode::Always;
}
bool isDataChanged = false;
if (m_hideZeroValuesMode != hideZeroValuesMode)
{
m_hideZeroValuesMode = hideZeroValuesMode;
emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1)));
isDataChanged = true;
}
if (const bool useTorrentStatesColors = pref->useTorrentStatesColors(); m_useTorrentStatesColors != useTorrentStatesColors)
{
m_useTorrentStatesColors = useTorrentStatesColors;
isDataChanged = true;
}
if (isDataChanged)
emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1)));
}
void TransferListModel::loadUIThemeResources()

View file

@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015-2024 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015-2025 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@ -135,6 +135,7 @@ private:
};
HideZeroValuesMode m_hideZeroValuesMode = HideZeroValuesMode::Never;
bool m_useTorrentStatesColors = false;
// cached icons
QIcon m_checkingIcon;

View file

@ -130,14 +130,14 @@ namespace
TransferListWidget::TransferListWidget(IGUIApplication *app, QWidget *parent)
: GUIApplicationComponent(app, parent)
, m_listModel {new TransferListModel {this}}
, m_sortFilterModel {new TransferListSortModel {this}}
, m_listModel {new TransferListModel(this)}
, m_sortFilterModel {new TransferListSortModel(this)}
{
// Load settings
const bool columnLoaded = loadSettings();
// Create and apply delegate
setItemDelegate(new TransferListDelegate {this});
setItemDelegate(new TransferListDelegate(this));
m_sortFilterModel->setDynamicSortFilter(true);
m_sortFilterModel->setSourceModel(m_listModel);